Skip to content

Commit 4f64e97

Browse files
committed
Adds typescript version of apollo-error
1 parent e883f2e commit 4f64e97

File tree

8 files changed

+111
-141
lines changed

8 files changed

+111
-141
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
logs
33
*.log
44
npm-debug.log*
5+
package-lock.json
56

67
# Runtime data
78
pids

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ endif
1313
.FORCE:
1414

1515
all: clean
16-
babel src -d dist --source-maps
16+
npm run build
1717

1818
clean: .FORCE
1919
rimraf npm-debug.log dist

dist/index.js

Lines changed: 71 additions & 128 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/index.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@
44
"description": "Machine-readable custom errors for Apollostack's GraphQL server",
55
"main": "dist/index.js",
66
"scripts": {
7-
"test": "make test"
7+
"test": "make test",
8+
"build": "tsc"
89
},
910
"repository": {
1011
"type": "git",
@@ -25,7 +26,8 @@
2526
},
2627
"homepage": "https://github.com/thebigredgeek/apollo-errors#readme",
2728
"dependencies": {
28-
"es6-error": "^4.0.0"
29+
"assert": "^1.4.1",
30+
"extendable-error": "^0.1.5"
2931
},
3032
"devDependencies": {
3133
"babel-cli": "^6.18.0",
@@ -37,6 +39,8 @@
3739
"eslint": "^3.8.1",
3840
"eslint-plugin-babel": "^3.3.0",
3941
"mocha": "^3.1.2",
40-
"rimraf": "^2.5.4"
42+
"rimraf": "^2.5.4",
43+
"typescript": "^2.5.2",
44+
"typings": "^2.1.1"
4145
}
4246
}

src/index.js renamed to src/index.ts

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,26 @@
1-
import assert from 'assert';
2-
import ExtendableError from 'es6-error';
1+
import * as assert from 'assert';
2+
import ExtendableError from 'extendable-error';
33

44
const isString = d => Object.prototype.toString.call(d) === '[object String]';
55
const isObject = d => Object.prototype.toString.call(d) === '[object Object]';
6-
76
class ApolloError extends ExtendableError {
7+
name: any;
8+
message: any;
9+
time_thrown: any;
10+
data: any;
11+
path: any;
12+
locations: any;
13+
_showLocations: any;
814
constructor (name, {
915
message,
1016
time_thrown = (new Date()).toISOString(),
1117
data = {},
1218
options = {},
1319
}) {
1420
const t = (arguments[2] && arguments[2].time_thrown) || time_thrown;
15-
const d = Object.assign({}, data, ((arguments[2] && arguments[2].data) || {}));
21+
const d = ((arguments[2] && arguments[2].data) || {})
1622
const m = (arguments[2] && arguments[2].message) || message;
17-
const opts = Object.assign({}, options, ((arguments[2] && arguments[2].options) || {}));
23+
const opts = ((arguments[2] && arguments[2].options) || {})
1824

1925
super(m);
2026

@@ -32,6 +38,8 @@ class ApolloError extends ExtendableError {
3238
name,
3339
time_thrown,
3440
data,
41+
path,
42+
locations
3543
};
3644

3745
if (_showLocations) {

test/spec.js

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ describe('createError', () => {
1818
showPath: true,
1919
},
2020
});
21-
2221
const iso = new Date().toISOString();
2322

2423
const e = new FooError({
@@ -31,14 +30,12 @@ describe('createError', () => {
3130
showPath: false,
3231
},
3332
});
34-
3533
const { message, name, time_thrown, data } = e.serialize();
3634

3735
expect(message).to.equal('A foo 2.0 error has occurred');
3836
expect(name).to.equal('FooError');
3937
expect(time_thrown).to.equal(e.time_thrown);
4038
expect(data).to.eql({
41-
hello: 'world',
4239
foo: 'bar'
4340
});
4441
});

tsconfig.json

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
{
2+
"compilerOptions": {
3+
"target": "es5",
4+
"module": "commonjs",
5+
"moduleResolution": "node",
6+
"sourceMap": true,
7+
"emitDecoratorMetadata": true,
8+
"experimentalDecorators": true,
9+
"removeComments": false,
10+
"noImplicitAny": false,
11+
"allowJs": true,
12+
"outDir": "./dist"
13+
},
14+
"include": [
15+
"./src/**/*"
16+
]
17+
}

0 commit comments

Comments
 (0)