From 42269a032ef776e3823aacf331b916c281ce9245 Mon Sep 17 00:00:00 2001 From: "Andrew E. Rhyne" Date: Wed, 7 Dec 2016 14:06:14 -0800 Subject: [PATCH 01/57] Release 1.2.1 --- CHANGELOG.md | 4 +++- dist/index.js | 8 +++++--- dist/index.js.map | 2 +- package.json | 2 +- src/index.js | 9 +++++++-- test/spec.js | 1 + 6 files changed, 18 insertions(+), 8 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index bfcdc58..ea639ff 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,6 @@ +1.2.1 / 2016-12-07 +================== + * Fixed a bug with overriding message serialization 1.2.0 / 2016-12-07 ================== @@ -13,5 +16,4 @@ 1.0.1 / 2016-11-10 ================== - * Initial release (@thebigredgeek) diff --git a/dist/index.js b/dist/index.js index 66fc43e..7a099b5 100644 --- a/dist/index.js +++ b/dist/index.js @@ -55,7 +55,7 @@ var ApolloError = function (_ExtendableError) { var m = arguments[2] && arguments[2].message || message; var opts = Object.assign({}, options, arguments[2] && arguments[2].options || {}); - var _this = _possibleConstructorReturn(this, (ApolloError.__proto__ || Object.getPrototypeOf(ApolloError)).call(this, serializeName([name, t, Object.assign({}, d, { + var _this = _possibleConstructorReturn(this, (ApolloError.__proto__ || Object.getPrototypeOf(ApolloError)).call(this, serializeName([name, t, m !== message ? m : 'null', Object.assign({}, d, { toString: function toString() { return JSON.stringify(d); } @@ -106,10 +106,11 @@ var formatError = exports.formatError = function formatError(originalError) { var returnNull = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false; var _deserializeName = deserializeName(originalError.message), - _deserializeName2 = _slicedToArray(_deserializeName, 3), + _deserializeName2 = _slicedToArray(_deserializeName, 4), name = _deserializeName2[0], thrown_at = _deserializeName2[1], - d = _deserializeName2[2]; + m = _deserializeName2[2], + d = _deserializeName2[3]; var locations = originalError.locations, path = originalError.path; @@ -119,6 +120,7 @@ var formatError = exports.formatError = function formatError(originalError) { var CustomError = errorMap.get(name); if (!CustomError) return returnNull ? null : originalError; var error = new CustomError({ + message: m === 'null' ? undefined : m, thrown_at: thrown_at, data: data, locations: locations, diff --git a/dist/index.js.map b/dist/index.js.map index 6903d3f..20173b4 100644 --- a/dist/index.js.map +++ b/dist/index.js.map @@ -1 +1 @@ -{"version":3,"sources":["../src/index.js"],"names":["errorMap","Map","DELIMITER","serializeName","arr","reduce","str","val","length","toString","deserializeName","name","split","ApolloError","message","time_thrown","Date","toISOString","data","options","t","arguments","thrown_at","d","Object","assign","m","opts","JSON","stringify","_name","_humanized_message","_time_thrown","_data","_locations","showLocations","locations","_path","showPath","path","error","createError","e","bind","set","formatError","originalError","returnNull","undefined","parse","CustomError","get","serialize"],"mappings":";;;;;;;;;;;AAAA;;;;;;;;;;;;AAEA,IAAMA,WAAW,IAAIC,GAAJ,EAAjB;;AAEA,IAAMC,YAAY,MAAlB;;AAEA,IAAMC,gBAAgB,SAAhBA,aAAgB;AAAA,MAACC,GAAD,uEAAO,EAAP;AAAA,SAAcA,IAAIC,MAAJ,CAAW,UAACC,GAAD,EAAMC,GAAN;AAAA,iBAAiBD,IAAIE,MAAJ,GAAa,CAAb,GAAiBF,MAAMJ,SAAvB,GAAmCI,GAApD,KAA0DC,IAAIE,QAAJ,GAAeF,IAAIE,QAAJ,EAAf,GAAgCF,GAA1F;AAAA,GAAX,EAA4G,EAA5G,CAAd;AAAA,CAAtB;AACA,IAAMG,kBAAkB,SAAlBA,eAAkB;AAAA,MAACC,IAAD,uEAAQ,EAAR;AAAA,SAAeA,KAAKC,KAAL,CAAWV,SAAX,CAAf;AAAA,CAAxB;;IAEMW,W;;;AACJ,uBAAaF,IAAb,QAKG;AAAA,QAJDG,OAIC,QAJDA,OAIC;AAAA,gCAHDC,WAGC;AAAA,QAHDA,WAGC,oCAHc,IAAIC,IAAJ,EAAD,CAAaC,WAAb,EAGb;AAAA,yBAFDC,IAEC;AAAA,QAFDA,IAEC,6BAFM,EAEN;AAAA,4BADDC,OACC;AAAA,QADD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B,GAAhB,CAAd;AAMA,SAAOC,MAAMY,SAAN,EAAP;AACD,CAdM","file":"index.js","sourcesContent":["import ExtendableError from 'es6-error';\n\nconst errorMap = new Map();\n\nconst DELIMITER = '/::/';\n\nconst serializeName = (arr = []) => arr.reduce((str, val) => `${str.length > 0 ? str + DELIMITER : str}${val.toString ? val.toString() : val}`, '');\nconst deserializeName = (name = '') => name.split(DELIMITER);\n\nclass ApolloError extends ExtendableError {\n constructor (name, {\n message,\n time_thrown = (new Date()).toISOString(),\n data = {},\n options = {},\n }) {\n const t = (arguments[2] && arguments[2].thrown_at) || time_thrown;\n const d = Object.assign({}, data, ((arguments[2] && arguments[2].data) || {}));\n const m = (arguments[2] && arguments[2].message) || message;\n const opts = Object.assign({}, options, ((arguments[2] && arguments[2].options) || {}));\n\n super(serializeName([\n name,\n t,\n Object.assign({}, d, {\n toString: () => JSON.stringify(d)\n }),\n ]));\n\n this._name = name;\n this._humanized_message = m || '';\n this._time_thrown = t;\n this._data = d;\n this._locations = (opts.showLocations && arguments[2] && arguments[2].locations)\n this._path = (opts.showPath && arguments[2] && arguments[2].path);\n }\n serialize () {\n const name = this._name;\n const message = this._humanized_message;\n const time_thrown = this._time_thrown;\n const data = this._data;\n const locations = this._locations;\n const path = this._path;\n let error = {\n message,\n name,\n time_thrown,\n data,\n };\n if (locations) error.locations = locations;\n if (path) error.path = path;\n return error;\n }\n}\n\nexport const createError = (name, data = { message: 'An error has occurred', options }) => {\n const e = ApolloError.bind(null, name, data);\n errorMap.set(name, e);\n return e;\n};\n\nexport const formatError = (originalError, returnNull = false) => {\n const [ name, thrown_at, d ] = deserializeName(originalError.message);\n const { locations, path } = originalError;\n const data = d !== undefined ? JSON.parse(d) : {};\n if (!name) return returnNull ? null : originalError;\n const CustomError = errorMap.get(name);\n if (!CustomError) return returnNull ? null : originalError;\n const error = new CustomError({\n thrown_at,\n data,\n locations,\n path,\n });\n return error.serialize();\n};\n"]} \ No newline at end of file +{"version":3,"sources":["../src/index.js"],"names":["errorMap","Map","DELIMITER","serializeName","arr","reduce","str","val","length","toString","deserializeName","name","split","ApolloError","message","time_thrown","Date","toISOString","data","options","t","arguments","thrown_at","d","Object","assign","m","opts","JSON","stringify","_name","_humanized_message","_time_thrown","_data","_locations","showLocations","locations","_path","showPath","path","error","createError","e","bind","set","formatError","originalError","returnNull","undefined","parse","CustomError","get","serialize"],"mappings":";;;;;;;;;;;AAAA;;;;;;;;;;;;AAEA,IAAMA,WAAW,IAAIC,GAAJ,EAAjB;;AAEA,IAAMC,YAAY,MAAlB;;AAEA,IAAMC,gBAAgB,SAAhBA,aAAgB;AAAA,MAACC,GAAD,uEAAO,EAAP;AAAA,SAAcA,IACjCC,MADiC,CAC1B,UAACC,GAAD,EAAMC,GAAN;AAAA,iBACHD,IAAIE,MAAJ,GAAa,CAAb,GAAiBF,MAAMJ,SAAvB,GAAmCI,GADhC,KACsCC,IAAIE,QAAJ,GAAeF,IAAIE,QAAJ,EAAf,GAAgCF,GADtE;AAAA,GAD0B,EAG/B,EAH+B,CAAd;AAAA,CAAtB;AAIA,IAAMG,kBAAkB,SAAlBA,eAAkB;AAAA,MAACC,IAAD,uEAAQ,EAAR;AAAA,SAAeA,KAAKC,KAAL,CAAWV,SAAX,CAAf;AAAA,CAAxB;;IAEMW,W;;;AACJ,uBAAaF,IAAb,QAKG;AAAA,QAJDG,OAIC,QAJDA,OAIC;AAAA,gCAHDC,WAGC;AAAA,QAHDA,WAGC,oCAHc,IAAIC,IAAJ,EAAD,CAAaC,WAAb,EAGb;AAAA,yBAFDC,IAEC;AAAA,QAFDA,IAEC,6BAFM,EAEN;AAAA,4BADDC,OACC;AAAA,QADDA,OACC,gCADS,EACT;;AAAA;;AACD,QAAMC,IAAKC,UAAU,CAAV,KAAgBA,UAAU,CAAV,EAAaC,SAA9B,IAA4CP,WAAtD;AACA,QAAMQ,IAAIC,OAAOC,MAAP,CAAc,EAAd,EAAkBP,IAAlB,EAA0BG,UAAU,CAAV,KAAgBA,UAAU,C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ExtendableError from 'es6-error';\n\nconst errorMap = new Map();\n\nconst DELIMITER = '/::/';\n\nconst serializeName = (arr = []) => arr\n .reduce((str, val) => (\n `${str.length > 0 ? str + DELIMITER : str}${val.toString ? val.toString() : val}`\n ), '');\nconst deserializeName = (name = '') => name.split(DELIMITER);\n\nclass ApolloError extends ExtendableError {\n constructor (name, {\n message,\n time_thrown = (new Date()).toISOString(),\n data = {},\n options = {},\n }) {\n const t = (arguments[2] && arguments[2].thrown_at) || time_thrown;\n const d = Object.assign({}, data, ((arguments[2] && arguments[2].data) || {}));\n const m = (arguments[2] && arguments[2].message) || message;\n const opts = Object.assign({}, options, ((arguments[2] && arguments[2].options) || {}));\n\n super(serializeName([\n name,\n t,\n (m !== message ? m : 'null'),\n Object.assign({}, d, {\n toString: () => JSON.stringify(d)\n }),\n ]));\n\n this._name = name;\n this._humanized_message = m || '';\n this._time_thrown = t;\n this._data = d;\n this._locations = (opts.showLocations && arguments[2] && arguments[2].locations)\n this._path = (opts.showPath && arguments[2] && arguments[2].path);\n }\n serialize () {\n const name = this._name;\n const message = this._humanized_message;\n const time_thrown = this._time_thrown;\n const data = this._data;\n const locations = this._locations;\n const path = this._path;\n let error = {\n message,\n name,\n time_thrown,\n data,\n };\n if (locations) error.locations = locations;\n if (path) error.path = path;\n return error;\n }\n}\n\nexport const createError = (name, data = { message: 'An error has occurred', options }) => {\n const e = ApolloError.bind(null, name, data);\n errorMap.set(name, e);\n return e;\n};\n\nexport const formatError = (originalError, returnNull = false) => {\n const [ name, thrown_at, m, d ] = deserializeName(originalError.message);\n const { locations, path } = originalError;\n const data = d !== undefined ? JSON.parse(d) : {};\n if (!name) return returnNull ? null : originalError;\n const CustomError = errorMap.get(name);\n if (!CustomError) return returnNull ? null : originalError;\n const error = new CustomError({\n message: m === 'null' ? undefined : m,\n thrown_at,\n data,\n locations,\n path,\n });\n return error.serialize();\n};\n"]} \ No newline at end of file diff --git a/package.json b/package.json index a6da4c1..b426957 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "apollo-errors", - "version": "1.2.0", + "version": "1.2.1", "description": "Machine-readable custom errors for Apollostack's GraphQL server", "main": "dist/index.js", "scripts": { diff --git a/src/index.js b/src/index.js index 92c1810..0ff50fb 100644 --- a/src/index.js +++ b/src/index.js @@ -4,7 +4,10 @@ const errorMap = new Map(); const DELIMITER = '/::/'; -const serializeName = (arr = []) => arr.reduce((str, val) => `${str.length > 0 ? str + DELIMITER : str}${val.toString ? val.toString() : val}`, ''); +const serializeName = (arr = []) => arr + .reduce((str, val) => ( + `${str.length > 0 ? str + DELIMITER : str}${val.toString ? val.toString() : val}` + ), ''); const deserializeName = (name = '') => name.split(DELIMITER); class ApolloError extends ExtendableError { @@ -22,6 +25,7 @@ class ApolloError extends ExtendableError { super(serializeName([ name, t, + (m !== message ? m : 'null'), Object.assign({}, d, { toString: () => JSON.stringify(d) }), @@ -60,13 +64,14 @@ export const createError = (name, data = { message: 'An error has occurred', opt }; export const formatError = (originalError, returnNull = false) => { - const [ name, thrown_at, d ] = deserializeName(originalError.message); + const [ name, thrown_at, m, d ] = deserializeName(originalError.message); const { locations, path } = originalError; const data = d !== undefined ? JSON.parse(d) : {}; if (!name) return returnNull ? null : originalError; const CustomError = errorMap.get(name); if (!CustomError) return returnNull ? null : originalError; const error = new CustomError({ + message: m === 'null' ? undefined : m, thrown_at, data, locations, diff --git a/test/spec.js b/test/spec.js index 7b632e4..daeeee0 100644 --- a/test/spec.js +++ b/test/spec.js @@ -55,6 +55,7 @@ describe('formatError', () => { }); const e = new FooError({ + message: 'A foo 2.0 error has occurred', data: { oh: 'shit' } From febcaeb4027e0e15257830aadb0c4d4a7f4a7834 Mon Sep 17 00:00:00 2001 From: "Andrew E. Rhyne" Date: Wed, 14 Dec 2016 11:44:04 -0800 Subject: [PATCH 02/57] Add Beerpay's badge --- README.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/README.md b/README.md index 7ef6ac1..b75a4e0 100644 --- a/README.md +++ b/README.md @@ -103,3 +103,8 @@ If the error is a known ApolloError, returns the serialized form of said error. **Otherwise**, *if strict is not truthy*, returns the original error passed into formatError. **Otherwise**, *if strict is truthy*, returns null. + +## Support on Beerpay +Hey dude! Help me out for a couple of :beers:! + +[![Beerpay](https://beerpay.io/thebigredgeek/apollo-errors/badge.svg?style=beer-square)](https://beerpay.io/thebigredgeek/apollo-errors) [![Beerpay](https://beerpay.io/thebigredgeek/apollo-errors/make-wish.svg?style=flat-square)](https://beerpay.io/thebigredgeek/apollo-errors?focus=wish) \ No newline at end of file From e849a0662e986eafd78f7eefa03ea878cd0f9db7 Mon Sep 17 00:00:00 2001 From: "Andrew E. Rhyne" Date: Wed, 14 Dec 2016 11:47:04 -0800 Subject: [PATCH 03/57] Update README.md --- README.md | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/README.md b/README.md index b75a4e0..767ea91 100644 --- a/README.md +++ b/README.md @@ -3,8 +3,7 @@ Machine-readable custom errors for Apollostack's GraphQL server [![NPM](https://nodei.co/npm/apollo-errors.png?downloads=true&downloadRank=true&stars=true)](https://nodei.co/npm/apollo-errors/) -[![CircleCI](https://circleci.com/gh/thebigredgeek/apollo-errors.svg?style=shield)](https://circleci.com/gh/thebigredgeek/apollo-errors/tree/master) - +[![CircleCI](https://circleci.com/gh/thebigredgeek/apollo-errors.svg?style=shield)](https://circleci.com/gh/thebigredgeek/apollo-errors/tree/master) [![Beerpay](https://beerpay.io/thebigredgeek/apollo-errors/badge.svg?style=beer-square)](https://beerpay.io/thebigredgeek/apollo-errors) [![Beerpay](https://beerpay.io/thebigredgeek/apollo-errors/make-wish.svg?style=flat-square)](https://beerpay.io/thebigredgeek/apollo-errors?focus=wish) ## Installation and usage @@ -103,8 +102,3 @@ If the error is a known ApolloError, returns the serialized form of said error. **Otherwise**, *if strict is not truthy*, returns the original error passed into formatError. **Otherwise**, *if strict is truthy*, returns null. - -## Support on Beerpay -Hey dude! Help me out for a couple of :beers:! - -[![Beerpay](https://beerpay.io/thebigredgeek/apollo-errors/badge.svg?style=beer-square)](https://beerpay.io/thebigredgeek/apollo-errors) [![Beerpay](https://beerpay.io/thebigredgeek/apollo-errors/make-wish.svg?style=flat-square)](https://beerpay.io/thebigredgeek/apollo-errors?focus=wish) \ No newline at end of file From eaeef78eb684af437e5e10fed652d83102671cff Mon Sep 17 00:00:00 2001 From: "Andrew E. Rhyne" Date: Wed, 1 Feb 2017 16:11:01 -0800 Subject: [PATCH 04/57] release 1.3.0 --- CHANGELOG.md | 7 +++++++ dist/index.js | 6 +++++- dist/index.js.map | 2 +- package.json | 2 +- src/index.js | 2 ++ 5 files changed, 16 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ea639ff..f909826 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,10 @@ + +1.3.0 / 2017-02-01 +================== + * Update README.md + * Add Beerpay's badge + * Added isInstance method + 1.2.1 / 2016-12-07 ================== * Fixed a bug with overriding message serialization diff --git a/dist/index.js b/dist/index.js index 7a099b5..db87256 100644 --- a/dist/index.js +++ b/dist/index.js @@ -3,7 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true }); -exports.formatError = exports.createError = undefined; +exports.isInstance = exports.formatError = exports.createError = undefined; var _slicedToArray = function () { function sliceIterator(arr, i) { var _arr = []; var _n = true; var _d = false; var _e = undefined; try { for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"]) _i["return"](); } finally { if (_d) throw _e; } } return _arr; } return function (arr, i) { if (Array.isArray(arr)) { return arr; } else if (Symbol.iterator in Object(arr)) { return sliceIterator(arr, i); } else { throw new TypeError("Invalid attempt to destructure non-iterable instance"); } }; }(); @@ -128,4 +128,8 @@ var formatError = exports.formatError = function formatError(originalError) { }); return error.serialize(); }; + +var isInstance = exports.isInstance = function isInstance(e) { + return e instanceof ApolloError; +}; //# sourceMappingURL=index.js.map \ No newline at end of file diff --git a/dist/index.js.map b/dist/index.js.map index 20173b4..da250f8 100644 --- a/dist/index.js.map +++ b/dist/index.js.map @@ -1 +1 @@ -{"version":3,"sources":["../src/index.js"],"names":["errorMap","Map","DELIMITER","serializeName","arr","reduce","str","val","length","toString","deserializeName","name","split","ApolloError","message","time_thrown","Date","toISOString","data","options","t","arguments","thrown_at","d","Object","assign","m","opts","JSON","stringify","_name","_humanized_message","_time_thrown","_data","_locations","showLocations","locations","_path","showPath","path","error","createError","e","bind","set","formatError","originalError","returnNull","undefined","parse","CustomError","get","serialize"],"mappings":";;;;;;;;;;;AAAA;;;;;;;;;;;;AAEA,IAAMA,WAAW,IAAIC,GAAJ,EAAjB;;AAEA,IAAMC,YAAY,MAAlB;;AAEA,IAAMC,gBAAgB,SAAhBA,aAAgB;AAAA,MAACC,GAAD,uEAAO,EAAP;AAAA,SAAcA,IACjCC,MADiC,CAC1B,UAACC,GAAD,EAAMC,GAAN;AAAA,iBACHD,IAAIE,MAAJ,GAAa,CAAb,GAAiBF,MAAMJ,SAAvB,GAAmCI,GADhC,KACsCC,IAAIE,QAAJ,GAAeF,IAAIE,QAAJ,EAAf,GAAgCF,GADtE;AAAA,GAD0B,EAG/B,EAH+B,CAAd;AAAA,CAAtB;AAIA,IAAMG,kBAAkB,SAAlBA,eAAkB;AAAA,MAACC,IAAD,uEAAQ,EAAR;AAAA,SAAeA,KAAKC,KAAL,CAAWV,SAAX,CAAf;AAAA,CAAxB;;IAEMW,W;;;AACJ,uBAAaF,IAAb,QAKG;AAAA,QAJDG,OAIC,QAJDA,OAIC;AAAA,gCAHDC,WAGC;AAAA,QAHDA,WAGC,oCAHc,IAAIC,IAAJ,EAAD,CAAaC,WAAb,EAGb;AAAA,yBAFDC,IAEC;AAAA,QAFDA,IAEC,6BAFM,EAEN;AAAA,4BADDC,OACC;AAAA,QADDA,OACC,gCADS,EACT;;AAAA;;AACD,QAAMC,IAAKC,UAAU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BtB,CADR;AAE5BJ,wBAF4B;AAG5BJ,cAH4B;AAI5BkB,wBAJ4B;AAK5BG;AAL4B,GAAhB,CAAd;AAOA,SAAOC,MAAMY,SAAN,EAAP;AACD,CAfM","file":"index.js","sourcesContent":["import ExtendableError from 'es6-error';\n\nconst errorMap = new Map();\n\nconst DELIMITER = '/::/';\n\nconst serializeName = (arr = []) => arr\n .reduce((str, val) => (\n `${str.length > 0 ? str + DELIMITER : str}${val.toString ? val.toString() : val}`\n ), '');\nconst deserializeName = (name = '') => name.split(DELIMITER);\n\nclass ApolloError extends ExtendableError {\n constructor (name, {\n message,\n time_thrown = (new Date()).toISOString(),\n data = {},\n options = {},\n }) {\n const t = (arguments[2] && arguments[2].thrown_at) || time_thrown;\n const d = Object.assign({}, data, ((arguments[2] && arguments[2].data) || {}));\n const m = (arguments[2] && arguments[2].message) || message;\n const opts = Object.assign({}, options, ((arguments[2] && arguments[2].options) || {}));\n\n super(serializeName([\n name,\n t,\n (m !== message ? m : 'null'),\n Object.assign({}, d, {\n toString: () => JSON.stringify(d)\n }),\n ]));\n\n this._name = name;\n this._humanized_message = m || '';\n this._time_thrown = t;\n this._data = d;\n this._locations = (opts.showLocations && arguments[2] && arguments[2].locations)\n this._path = (opts.showPath && arguments[2] && arguments[2].path);\n }\n serialize () {\n const name = this._name;\n const message = this._humanized_message;\n const time_thrown = this._time_thrown;\n const data = this._data;\n const locations = this._locations;\n const path = this._path;\n let error = {\n message,\n name,\n time_thrown,\n data,\n };\n if (locations) error.locations = locations;\n if (path) error.path = path;\n return error;\n }\n}\n\nexport const createError = (name, data = { message: 'An error has occurred', options }) => {\n const e = ApolloError.bind(null, name, data);\n errorMap.set(name, e);\n return e;\n};\n\nexport const formatError = (originalError, returnNull = false) => {\n const [ name, thrown_at, m, d ] = deserializeName(originalError.message);\n const { locations, path } = originalError;\n const data = d !== undefined ? JSON.parse(d) : {};\n if (!name) return returnNull ? null : originalError;\n const CustomError = errorMap.get(name);\n if (!CustomError) return returnNull ? null : originalError;\n const error = new CustomError({\n message: m === 'null' ? undefined : m,\n thrown_at,\n data,\n locations,\n path,\n });\n return error.serialize();\n};\n"]} \ No newline at end of file +{"version":3,"sources":["../src/index.js"],"names":["errorMap","Map","DELIMITER","serializeName","arr","reduce","str","val","length","toString","deserializeName","name","split","ApolloError","message","time_thrown","Date","toISOString","data","options","t","arguments","thrown_at","d","Object","assign","m","opts","JSON","stringify","_name","_humanized_message","_time_thrown","_data","_locations","showLocations","locations","_path","showPath","path","error","createError","e","bind","set","formatError","originalError","returnNull","undefined","parse","CustomError","get","serialize","isInstance"],"mappings":";;;;;;;;;;;AAAA;;;;;;;;;;;;AAEA,IAAMA,WAAW,IAAIC,GAAJ,EAAjB;;AAEA,IAAMC,YAAY,MAAlB;;AAEA,IAAMC,gBAAgB,SAAhBA,aAAgB;AAAA,MAACC,GAAD,uEAAO,EAAP;AAAA,SAAcA,IACjCC,MADiC,CAC1B,UAACC,GAAD,EAAMC,GAAN;AAAA,iBACHD,IAAIE,MAAJ,GAAa,CAAb,GAAiBF,MAAMJ,SAAvB,GAAmCI,GADhC,KACsCC,IAAIE,QAAJ,GAAeF,IAAIE,QAAJ,EAAf,GAAgCF,GADtE;AAAA,GAD0B,EAG/B,EAH+B,CAAd;AAAA,CAAtB;AAIA,IAAMG,kBAAkB,SAAlBA,eAAkB;AAAA,MAACC,IAAD,uEAAQ,EAAR;AAAA,SAAeA,KAAKC,KAAL,CAAWV,SAAX,CAAf;AAAA,CAAxB;;IAEMW,W;;;AACJ,uBAAaF,IAAb,QAKG;AAAA,QAJDG,OAIC,QAJDA,OAIC;AAAA,gCAHDC,WAGC;AAAA,QAHDA,WAGC,oCAHc,IAAIC,IAAJ,EAAD,CAAaC,WAAb,EAGb;AAAA,yBAFDC,IAEC;AAAA,QAFDA,IAEC,6BAFM,EAEN;AAAA,4BADDC,OACC;AAAA,QADDA,OACC,gCADS,EACT;;AAAA;;AACD,QAAMC,IAAKC,UAAU,CAAV,KAAgBA,UAA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wBAF4B;AAG5BJ,cAH4B;AAI5BkB,wBAJ4B;AAK5BG;AAL4B,GAAhB,CAAd;AAOA,SAAOC,MAAMY,SAAN,EAAP;AACD,CAfM;;AAiBA,IAAMC,kCAAa,SAAbA,UAAa;AAAA,SAAKX,aAAa7B,WAAlB;AAAA,CAAnB","file":"index.js","sourcesContent":["import ExtendableError from 'es6-error';\n\nconst errorMap = new Map();\n\nconst DELIMITER = '/::/';\n\nconst serializeName = (arr = []) => arr\n .reduce((str, val) => (\n `${str.length > 0 ? str + DELIMITER : str}${val.toString ? val.toString() : val}`\n ), '');\nconst deserializeName = (name = '') => name.split(DELIMITER);\n\nclass ApolloError extends ExtendableError {\n constructor (name, {\n message,\n time_thrown = (new Date()).toISOString(),\n data = {},\n options = {},\n }) {\n const t = (arguments[2] && arguments[2].thrown_at) || time_thrown;\n const d = Object.assign({}, data, ((arguments[2] && arguments[2].data) || {}));\n const m = (arguments[2] && arguments[2].message) || message;\n const opts = Object.assign({}, options, ((arguments[2] && arguments[2].options) || {}));\n\n super(serializeName([\n name,\n t,\n (m !== message ? m : 'null'),\n Object.assign({}, d, {\n toString: () => JSON.stringify(d)\n }),\n ]));\n\n this._name = name;\n this._humanized_message = m || '';\n this._time_thrown = t;\n this._data = d;\n this._locations = (opts.showLocations && arguments[2] && arguments[2].locations)\n this._path = (opts.showPath && arguments[2] && arguments[2].path);\n }\n serialize () {\n const name = this._name;\n const message = this._humanized_message;\n const time_thrown = this._time_thrown;\n const data = this._data;\n const locations = this._locations;\n const path = this._path;\n let error = {\n message,\n name,\n time_thrown,\n data,\n };\n if (locations) error.locations = locations;\n if (path) error.path = path;\n return error;\n }\n}\n\nexport const createError = (name, data = { message: 'An error has occurred', options }) => {\n const e = ApolloError.bind(null, name, data);\n errorMap.set(name, e);\n return e;\n};\n\nexport const formatError = (originalError, returnNull = false) => {\n const [ name, thrown_at, m, d ] = deserializeName(originalError.message);\n const { locations, path } = originalError;\n const data = d !== undefined ? JSON.parse(d) : {};\n if (!name) return returnNull ? null : originalError;\n const CustomError = errorMap.get(name);\n if (!CustomError) return returnNull ? null : originalError;\n const error = new CustomError({\n message: m === 'null' ? undefined : m,\n thrown_at,\n data,\n locations,\n path,\n });\n return error.serialize();\n};\n\nexport const isInstance = e => e instanceof ApolloError;\n"]} \ No newline at end of file diff --git a/package.json b/package.json index b426957..3571ab5 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "apollo-errors", - "version": "1.2.1", + "version": "1.3.0", "description": "Machine-readable custom errors for Apollostack's GraphQL server", "main": "dist/index.js", "scripts": { diff --git a/src/index.js b/src/index.js index 0ff50fb..0733aaa 100644 --- a/src/index.js +++ b/src/index.js @@ -79,3 +79,5 @@ export const formatError = (originalError, returnNull = false) => { }); return error.serialize(); }; + +export const isInstance = e => e instanceof ApolloError; From 1d193f6235acaed5e1a8e374b478a0ea91053bac Mon Sep 17 00:00:00 2001 From: "Andrew E. Rhyne" Date: Tue, 14 Mar 2017 11:39:16 -0700 Subject: [PATCH 05/57] Update README.md --- README.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/README.md b/README.md index 767ea91..4253b83 100644 --- a/README.md +++ b/README.md @@ -102,3 +102,6 @@ If the error is a known ApolloError, returns the serialized form of said error. **Otherwise**, *if strict is not truthy*, returns the original error passed into formatError. **Otherwise**, *if strict is truthy*, returns null. + +### isInstance (error): Boolean +Returns true if the error is an instance of an ApolloError. Otherwise, returns false From e20f9abe35f38320176e040553555f21ea9ea3c3 Mon Sep 17 00:00:00 2001 From: "Andrew E. Rhyne" Date: Tue, 14 Mar 2017 12:22:39 -0700 Subject: [PATCH 06/57] rely on error.originalError and fail back to error for formatError --- CHANGELOG.md | 14 +++--- dist/index.js | 118 ++++++++++++++++++++-------------------------- dist/index.js.map | 2 +- package.json | 2 +- src/index.js | 86 ++++++++++++++------------------- test/spec.js | 6 +-- 6 files changed, 99 insertions(+), 129 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f909826..5c91171 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,25 +1,25 @@ 1.3.0 / 2017-02-01 ================== - * Update README.md - * Add Beerpay's badge - * Added isInstance method + * Docs: Update README.md (@thebigredgeek) + * Docs: Add Beerpay's badge (@thebigredgeek) + * Docs: Added isInstance method 1.2.1 / 2016-12-07 ================== - * Fixed a bug with overriding message serialization + * Fix: bug with overriding message serialization (@thebigredgeek) 1.2.0 / 2016-12-07 ================== - * Added option to override message when throwing error (@thebigredgeek) + * Feature: Added option to override message when throwing error (@thebigredgeek) 1.1.0 / 2016-12-01 ================== - * Added option to show original locations and paths in error (#1, @scf4) + * Feature: Added option to show original locations and paths in error (#1, @scf4) 1.0.2 / 2016-11-11 ================== - * Fix for data serialization (@thebigredgeek) + * Fix: data serialization (@thebigredgeek) 1.0.1 / 2016-11-10 ================== diff --git a/dist/index.js b/dist/index.js index db87256..370257f 100644 --- a/dist/index.js +++ b/dist/index.js @@ -3,9 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true }); -exports.isInstance = exports.formatError = exports.createError = undefined; - -var _slicedToArray = function () { function sliceIterator(arr, i) { var _arr = []; var _n = true; var _d = false; var _e = undefined; try { for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"]) _i["return"](); } finally { if (_d) throw _e; } } return _arr; } return function (arr, i) { if (Array.isArray(arr)) { return arr; } else if (Symbol.iterator in Object(arr)) { return sliceIterator(arr, i); } else { throw new TypeError("Invalid attempt to destructure non-iterable instance"); } }; }(); +exports.formatError = exports.createError = exports.isInstance = undefined; var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }(); @@ -21,21 +19,6 @@ function _possibleConstructorReturn(self, call) { if (!self) { throw new Referen function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; } -var errorMap = new Map(); - -var DELIMITER = '/::/'; - -var serializeName = function serializeName() { - var arr = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : []; - return arr.reduce(function (str, val) { - return '' + (str.length > 0 ? str + DELIMITER : str) + (val.toString ? val.toString() : val); - }, ''); -}; -var deserializeName = function deserializeName() { - var name = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : ''; - return name.split(DELIMITER); -}; - var ApolloError = function (_ExtendableError) { _inherits(ApolloError, _ExtendableError); @@ -50,43 +33,45 @@ var ApolloError = function (_ExtendableError) { _classCallCheck(this, ApolloError); - var t = arguments[2] && arguments[2].thrown_at || time_thrown; + var t = arguments[2] && arguments[2].time_thrown || time_thrown; var d = Object.assign({}, data, arguments[2] && arguments[2].data || {}); var m = arguments[2] && arguments[2].message || message; var opts = Object.assign({}, options, arguments[2] && arguments[2].options || {}); - var _this = _possibleConstructorReturn(this, (ApolloError.__proto__ || Object.getPrototypeOf(ApolloError)).call(this, serializeName([name, t, m !== message ? m : 'null', Object.assign({}, d, { - toString: function toString() { - return JSON.stringify(d); - } - })]))); - - _this._name = name; - _this._humanized_message = m || ''; - _this._time_thrown = t; - _this._data = d; - _this._locations = opts.showLocations && arguments[2] && arguments[2].locations; - _this._path = opts.showPath && arguments[2] && arguments[2].path; + var _this = _possibleConstructorReturn(this, (ApolloError.__proto__ || Object.getPrototypeOf(ApolloError)).call(this, m)); + + _this.name = name; + _this.message = m; + _this.time_thrown = t; + _this.data = d; + _this._showLocations = !!opts.showLocations; return _this; } _createClass(ApolloError, [{ key: 'serialize', value: function serialize() { - var name = this._name; - var message = this._humanized_message; - var time_thrown = this._time_thrown; - var data = this._data; - var locations = this._locations; - var path = this._path; + var name = this.name, + message = this.message, + time_thrown = this.time_thrown, + data = this.data, + _showLocations = this._showLocations, + path = this.path, + locations = this.locations; + + var error = { message: message, name: name, time_thrown: time_thrown, data: data }; - if (locations) error.locations = locations; - if (path) error.path = path; + + if (_showLocations) { + error.locations = locations; + error.path = path; + } + return error; } }]); @@ -94,42 +79,43 @@ var ApolloError = function (_ExtendableError) { return ApolloError; }(_es6Error2.default); +var isInstance = exports.isInstance = function isInstance(e) { + return e instanceof ApolloError; +}; + var createError = exports.createError = function createError(name) { var data = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : { message: 'An error has occurred', options: options }; var e = ApolloError.bind(null, name, data); - errorMap.set(name, e); return e; }; -var formatError = exports.formatError = function formatError(originalError) { +var formatError = exports.formatError = function formatError(error) { var returnNull = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false; - var _deserializeName = deserializeName(originalError.message), - _deserializeName2 = _slicedToArray(_deserializeName, 4), - name = _deserializeName2[0], - thrown_at = _deserializeName2[1], - m = _deserializeName2[2], - d = _deserializeName2[3]; - - var locations = originalError.locations, - path = originalError.path; - - var data = d !== undefined ? JSON.parse(d) : {}; - if (!name) return returnNull ? null : originalError; - var CustomError = errorMap.get(name); - if (!CustomError) return returnNull ? null : originalError; - var error = new CustomError({ - message: m === 'null' ? undefined : m, - thrown_at: thrown_at, - data: data, - locations: locations, - path: path - }); - return error.serialize(); -}; + var originalError = error ? error.originalError || error : null; -var isInstance = exports.isInstance = function isInstance(e) { - return e instanceof ApolloError; + if (!originalError) return returnNull ? null : error; + + var name = originalError.name; + + + if (!name || !isInstance(originalError)) return returnNull ? null : error; + + var time_thrown = originalError.time_thrown, + message = originalError.message, + data = originalError.data, + _showLocations = originalError._showLocations; + + + if (_showLocations) { + var locations = error.locations, + path = error.path; + + originalError.locations = locations; + originalError.path = path; + } + + return originalError.serialize(); }; //# sourceMappingURL=index.js.map \ No newline at end of file diff --git a/dist/index.js.map b/dist/index.js.map index da250f8..41d3c97 100644 --- a/dist/index.js.map +++ b/dist/index.js.map @@ -1 +1 @@ -{"version":3,"sources":["../src/index.js"],"names":["errorMap","Map","DELIMITER","serializeName","arr","reduce","str","val","length","toString","deserializeName","name","split","ApolloError","message","time_thrown","Date","toISOString","data","options","t","arguments","thrown_at","d","Object","assign","m","opts","JSON","stringify","_name","_humanized_message","_time_thrown","_data","_locations","showLocations","locations","_path","showPath","path","error","createError","e","bind","set","formatError","originalError","returnNull","undefined","parse","CustomError","get","serialize","isInstance"],"mappings":";;;;;;;;;;;AAAA;;;;;;;;;;;;AAEA,IAAMA,WAAW,IAAIC,GAAJ,EAAjB;;AAEA,IAAMC,YAAY,MAAlB;;AAEA,IAAMC,gBAAgB,SAAhBA,aAAgB;AAAA,MAACC,GAAD,uEAAO,EAAP;AAAA,SAAcA,IACjCC,MADiC,CAC1B,UAACC,GAAD,EAAMC,GAAN;AAAA,iBACHD,IAAIE,MAAJ,GAAa,CAAb,GAAiBF,MAAMJ,SAAvB,GAAmCI,GADhC,KACsCC,IAAIE,QAAJ,GAAeF,IAAIE,QAAJ,EAAf,GAAgCF,GADtE;AAAA,GAD0B,EAG/B,EAH+B,CAAd;AAAA,CAAtB;AAIA,IAAMG,kBAAkB,SAAlBA,eAAkB;AAAA,MAACC,IAAD,uEAAQ,EAAR;AAAA,SAAeA,KAAKC,KAAL,CAAWV,SAAX,CAAf;AAAA,CAAxB;;IAEMW,W;;;AACJ,uBAAaF,IAAb,QAKG;AAAA,QAJDG,OAIC,QAJDA,OAIC;AAAA,gCAHDC,WAGC;AAAA,QAHDA,WAGC,oCAHc,IAAIC,IAAJ,EAAD,CAAaC,WAAb,EAGb;AAAA,yBAFDC,IAEC;AAAA,QAFDA,IAEC,6BAFM,EAEN;AAAA,4BADD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IAAIU,WAAJ,CAAgB;AAC5BpC,aAASY,MAAM,MAAN,GAAesB,SAAf,GAA2BtB,CADR;AAE5BJ,wBAF4B;AAG5BJ,cAH4B;AAI5BkB,wBAJ4B;AAK5BG;AAL4B,GAAhB,CAAd;AAOA,SAAOC,MAAMY,SAAN,EAAP;AACD,CAfM;;AAiBA,IAAMC,kCAAa,SAAbA,UAAa;AAAA,SAAKX,aAAa7B,WAAlB;AAAA,CAAnB","file":"index.js","sourcesContent":["import ExtendableError from 'es6-error';\n\nconst errorMap = new Map();\n\nconst DELIMITER = '/::/';\n\nconst serializeName = (arr = []) => arr\n .reduce((str, val) => (\n `${str.length > 0 ? str + DELIMITER : str}${val.toString ? val.toString() : val}`\n ), '');\nconst deserializeName = (name = '') => name.split(DELIMITER);\n\nclass ApolloError extends ExtendableError {\n constructor (name, {\n message,\n time_thrown = (new Date()).toISOString(),\n data = {},\n options = {},\n }) {\n const t = (arguments[2] && arguments[2].thrown_at) || time_thrown;\n const d = Object.assign({}, data, ((arguments[2] && arguments[2].data) || {}));\n const m = (arguments[2] && arguments[2].message) || message;\n const opts = Object.assign({}, options, ((arguments[2] && arguments[2].options) || {}));\n\n super(serializeName([\n name,\n t,\n (m !== message ? m : 'null'),\n Object.assign({}, d, {\n toString: () => JSON.stringify(d)\n }),\n ]));\n\n this._name = name;\n this._humanized_message = m || '';\n this._time_thrown = t;\n this._data = d;\n this._locations = (opts.showLocations && arguments[2] && arguments[2].locations)\n this._path = (opts.showPath && arguments[2] && arguments[2].path);\n }\n serialize () {\n const name = this._name;\n const message = this._humanized_message;\n const time_thrown = this._time_thrown;\n const data = this._data;\n const locations = this._locations;\n const path = this._path;\n let error = {\n message,\n name,\n time_thrown,\n data,\n };\n if (locations) error.locations = locations;\n if (path) error.path = path;\n return error;\n }\n}\n\nexport const createError = (name, data = { message: 'An error has occurred', options }) => {\n const e = ApolloError.bind(null, name, data);\n errorMap.set(name, e);\n return e;\n};\n\nexport const formatError = (originalError, returnNull = false) => {\n const [ name, thrown_at, m, d ] = deserializeName(originalError.message);\n const { locations, path } = originalError;\n const data = d !== undefined ? JSON.parse(d) : {};\n if (!name) return returnNull ? null : originalError;\n const CustomError = errorMap.get(name);\n if (!CustomError) return returnNull ? null : originalError;\n const error = new CustomError({\n message: m === 'null' ? undefined : m,\n thrown_at,\n data,\n locations,\n path,\n });\n return error.serialize();\n};\n\nexport const isInstance = e => e instanceof ApolloError;\n"]} \ No newline at end of file +{"version":3,"sources":["../src/index.js"],"names":["ApolloError","name","message","time_thrown","Date","toISOString","data","options","t","arguments","d","Object","assign","m","opts","_showLocations","showLocations","path","locations","error","isInstance","e","createError","bind","formatError","returnNull","originalError","serialize"],"mappings":";;;;;;;;;AAAA;;;;;;;;;;;;IAEMA,W;;;AACJ,uBAAaC,IAAb,QAKG;AAAA,QAJDC,OAIC,QAJDA,OAIC;AAAA,gCAHDC,WAGC;AAAA,QAHDA,WAGC,oCAHc,IAAIC,IAAJ,EAAD,CAAaC,WAAb,EAGb;AAAA,yBAFDC,IAEC;AAAA,QAFDA,IAEC,6BAFM,EAEN;AAAA,4BADDC,OACC;AAAA,QADDA,OACC,gCADS,EACT;;AAAA;;AACD,QAAMC,IAAKC,UAAU,CAAV,KAAgBA,UAAU,CAAV,EAAaN,WAA9B,IAA8CA,WAAxD;AACA,QAAMO,IAAIC,OAAOC,MAAP,CAAc,EAAd,EAAkBN,IAAlB,EAA0BG,UAAU,CAAV,KAAgBA,UAAU,CAAV,EAAaH,IAA9B,IAAuC,EAAhE,CAAV;AACA,QAAMO,IAAKJ,UAAU,CAAV,KAAgBA,UAAU,CAAV,EAAaP,OAA9B,IAA0CA,OAApD;AACA,QAAMY,OAAOH,OAAOC,MAAP,CAAc,EAAd,EAAkBL,OAAlB,EAA6BE,UAAU,CAAV,KAAgBA,UAAU,CAAV,EAAaF,OAA9B,IAA0C,EAAtE,CAAb;;AAJC,0HAMKM,CANL;;AAQD,UAAKZ,IAAL,GAAYA,IAAZ;AACA,UAAKC,O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N,KAA3B;;AAHoC,MAKhDlB,IALgD,GAKvCyB,aALuC,CAKhDzB,IALgD;;;AAOxD,MAAI,CAACA,IAAD,IAAS,CAACmB,WAAWM,aAAX,CAAd,EAAyC,OAAOD,aAAa,IAAb,GAAoBN,KAA3B;;AAPe,MAShDhB,WATgD,GASDuB,aATC,CAShDvB,WATgD;AAAA,MASnCD,OATmC,GASDwB,aATC,CASnCxB,OATmC;AAAA,MAS1BI,IAT0B,GASDoB,aATC,CAS1BpB,IAT0B;AAAA,MASpBS,cAToB,GASDW,aATC,CASpBX,cAToB;;;AAWxD,MAAIA,cAAJ,EAAoB;AAAA,QACVG,SADU,GACUC,KADV,CACVD,SADU;AAAA,QACCD,IADD,GACUE,KADV,CACCF,IADD;;AAElBS,kBAAcR,SAAd,GAA0BA,SAA1B;AACAQ,kBAAcT,IAAd,GAAqBA,IAArB;AACD;;AAED,SAAOS,cAAcC,SAAd,EAAP;AACD,CAlBM","file":"index.js","sourcesContent":["import ExtendableError from 'es6-error';\n\nclass ApolloError extends ExtendableError {\n constructor (name, {\n message,\n time_thrown = (new Date()).toISOString(),\n data = {},\n options = {},\n }) {\n const t = (arguments[2] && arguments[2].time_thrown) || time_thrown;\n const d = Object.assign({}, data, ((arguments[2] && arguments[2].data) || {}));\n const m = (arguments[2] && arguments[2].message) || message;\n const opts = Object.assign({}, options, ((arguments[2] && arguments[2].options) || {}));\n\n super(m);\n\n this.name = name;\n this.message = m;\n this.time_thrown = t;\n this.data = d;\n this._showLocations = !!opts.showLocations;\n }\n serialize () {\n const { name, message, time_thrown, data, _showLocations, path, locations } = this;\n\n let error = {\n message,\n name,\n time_thrown,\n data,\n };\n\n if (_showLocations) {\n error.locations = locations;\n error.path = path;\n }\n\n return error;\n }\n}\n\nexport const isInstance = e => e instanceof ApolloError;\n\nexport const createError = (name, data = { message: 'An error has occurred', options }) => {\n const e = ApolloError.bind(null, name, data);\n return e;\n};\n\nexport const formatError = (error, returnNull = false) => {\n const originalError = error ? error.originalError || error : null;\n\n if (!originalError) return returnNull ? null : error;\n\n const { name } = originalError;\n\n if (!name || !isInstance(originalError)) return returnNull ? null : error;\n\n const { time_thrown, message, data, _showLocations } = originalError;\n\n if (_showLocations) {\n const { locations, path } = error;\n originalError.locations = locations;\n originalError.path = path;\n }\n\n return originalError.serialize();\n};\n"]} \ No newline at end of file diff --git a/package.json b/package.json index 3571ab5..34e5f06 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "apollo-errors", - "version": "1.3.0", + "version": "1.4.0", "description": "Machine-readable custom errors for Apollostack's GraphQL server", "main": "dist/index.js", "scripts": { diff --git a/src/index.js b/src/index.js index 0733aaa..f97c9c7 100644 --- a/src/index.js +++ b/src/index.js @@ -1,15 +1,5 @@ import ExtendableError from 'es6-error'; -const errorMap = new Map(); - -const DELIMITER = '/::/'; - -const serializeName = (arr = []) => arr - .reduce((str, val) => ( - `${str.length > 0 ? str + DELIMITER : str}${val.toString ? val.toString() : val}` - ), ''); -const deserializeName = (name = '') => name.split(DELIMITER); - class ApolloError extends ExtendableError { constructor (name, { message, @@ -17,67 +7,61 @@ class ApolloError extends ExtendableError { data = {}, options = {}, }) { - const t = (arguments[2] && arguments[2].thrown_at) || time_thrown; + const t = (arguments[2] && arguments[2].time_thrown) || time_thrown; const d = Object.assign({}, data, ((arguments[2] && arguments[2].data) || {})); const m = (arguments[2] && arguments[2].message) || message; const opts = Object.assign({}, options, ((arguments[2] && arguments[2].options) || {})); - super(serializeName([ - name, - t, - (m !== message ? m : 'null'), - Object.assign({}, d, { - toString: () => JSON.stringify(d) - }), - ])); + super(m); - this._name = name; - this._humanized_message = m || ''; - this._time_thrown = t; - this._data = d; - this._locations = (opts.showLocations && arguments[2] && arguments[2].locations) - this._path = (opts.showPath && arguments[2] && arguments[2].path); + this.name = name; + this.message = m; + this.time_thrown = t; + this.data = d; + this._showLocations = !!opts.showLocations; } serialize () { - const name = this._name; - const message = this._humanized_message; - const time_thrown = this._time_thrown; - const data = this._data; - const locations = this._locations; - const path = this._path; + const { name, message, time_thrown, data, _showLocations, path, locations } = this; + let error = { message, name, time_thrown, data, }; - if (locations) error.locations = locations; - if (path) error.path = path; + + if (_showLocations) { + error.locations = locations; + error.path = path; + } + return error; } } +export const isInstance = e => e instanceof ApolloError; + export const createError = (name, data = { message: 'An error has occurred', options }) => { const e = ApolloError.bind(null, name, data); - errorMap.set(name, e); return e; }; -export const formatError = (originalError, returnNull = false) => { - const [ name, thrown_at, m, d ] = deserializeName(originalError.message); - const { locations, path } = originalError; - const data = d !== undefined ? JSON.parse(d) : {}; - if (!name) return returnNull ? null : originalError; - const CustomError = errorMap.get(name); - if (!CustomError) return returnNull ? null : originalError; - const error = new CustomError({ - message: m === 'null' ? undefined : m, - thrown_at, - data, - locations, - path, - }); - return error.serialize(); -}; +export const formatError = (error, returnNull = false) => { + const originalError = error ? error.originalError || error : null; -export const isInstance = e => e instanceof ApolloError; + if (!originalError) return returnNull ? null : error; + + const { name } = originalError; + + if (!name || !isInstance(originalError)) return returnNull ? null : error; + + const { time_thrown, message, data, _showLocations } = originalError; + + if (_showLocations) { + const { locations, path } = error; + originalError.locations = locations; + originalError.path = path; + } + + return originalError.serialize(); +}; diff --git a/test/spec.js b/test/spec.js index daeeee0..fc510b4 100644 --- a/test/spec.js +++ b/test/spec.js @@ -32,7 +32,7 @@ describe('createError', () => { expect(message).to.equal('A foo 2.0 error has occurred'); expect(name).to.equal('FooError'); - expect(time_thrown).to.equal(e._time_thrown); + expect(time_thrown).to.equal(e.time_thrown); expect(data).to.eql({ hello: 'world', foo: 'bar' @@ -62,7 +62,7 @@ describe('formatError', () => { }); const s = formatError({ - message: e.message + originalError: e }, false); expect(s).to.eql(e.serialize()); @@ -85,7 +85,7 @@ describe('formatError', () => { const e = new FooError(); const s = formatError({ - message: e.message + originalError: e }, true); expect(s).to.eql(e.serialize()); From bbacf37eb86c0757a28dd433bfe7ae9ffa123bae Mon Sep 17 00:00:00 2001 From: "Andrew E. Rhyne" Date: Tue, 14 Mar 2017 12:23:53 -0700 Subject: [PATCH 07/57] release 1.4.0 --- CHANGELOG.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5c91171..fe7c4f2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,4 +1,9 @@ +1.4.0 / 2017-03-14 +================== + * Feature: (BREAKING) Rely on error.originalError and fail back to error for formatError rather than serializing body into message + * Docs: Add docs for `isInstance` + 1.3.0 / 2017-02-01 ================== * Docs: Update README.md (@thebigredgeek) From 5e5f50962902ab857f7dc231b5123fd7b693f867 Mon Sep 17 00:00:00 2001 From: "Andrew E. Rhyne" Date: Mon, 14 Aug 2017 10:16:20 -0700 Subject: [PATCH 08/57] Update README.md --- README.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/README.md b/README.md index 4253b83..78a9f01 100644 --- a/README.md +++ b/README.md @@ -5,6 +5,10 @@ Machine-readable custom errors for Apollostack's GraphQL server [![CircleCI](https://circleci.com/gh/thebigredgeek/apollo-errors.svg?style=shield)](https://circleci.com/gh/thebigredgeek/apollo-errors/tree/master) [![Beerpay](https://beerpay.io/thebigredgeek/apollo-errors/badge.svg?style=beer-square)](https://beerpay.io/thebigredgeek/apollo-errors) [![Beerpay](https://beerpay.io/thebigredgeek/apollo-errors/make-wish.svg?style=flat-square)](https://beerpay.io/thebigredgeek/apollo-errors?focus=wish) +## Example from Apollo Day + +[![Authentication and Error Handling in GraphQL](https://img.youtube.com/vi/xaorvBjCE7A/0.jpg)](https://www.youtube.com/watch?v=xaorvBjCE7A) + ## Installation and usage Install the package: From 5c45afc082b2e9e202bd2655c22828c4b69c8d99 Mon Sep 17 00:00:00 2001 From: Andrew Rhyne Date: Tue, 29 Aug 2017 11:00:30 -0700 Subject: [PATCH 09/57] fixes for createError --- .gitignore | 3 ++ dist/index.js | 19 ++++++++--- dist/index.js.map | 2 +- package.json | 2 +- src/index.js | 10 ++++-- test/spec.js | 84 +++++++++++++++++++++++++++++++---------------- 6 files changed, 83 insertions(+), 37 deletions(-) diff --git a/.gitignore b/.gitignore index 9aeb862..682ca08 100644 --- a/.gitignore +++ b/.gitignore @@ -38,3 +38,6 @@ jspm_packages # Yarn yarn.lock + +# Direnv +.envrc diff --git a/dist/index.js b/dist/index.js index 370257f..e01b125 100644 --- a/dist/index.js +++ b/dist/index.js @@ -7,6 +7,10 @@ exports.formatError = exports.createError = exports.isInstance = undefined; var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }(); +var _assert = require('assert'); + +var _assert2 = _interopRequireDefault(_assert); + var _es6Error = require('es6-error'); var _es6Error2 = _interopRequireDefault(_es6Error); @@ -19,6 +23,13 @@ function _possibleConstructorReturn(self, call) { if (!self) { throw new Referen function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; } +var isString = function isString(d) { + return Object.prototype.toString.call(d) === '[object String]'; +}; +var isObject = function isObject(d) { + return Object.prototype.toString.call(d) === '[object Object]'; +}; + var ApolloError = function (_ExtendableError) { _inherits(ApolloError, _ExtendableError); @@ -83,10 +94,10 @@ var isInstance = exports.isInstance = function isInstance(e) { return e instanceof ApolloError; }; -var createError = exports.createError = function createError(name) { - var data = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : { message: 'An error has occurred', options: options }; - - var e = ApolloError.bind(null, name, data); +var createError = exports.createError = function createError(name, config) { + (0, _assert2.default)(isObject(config), 'createError requires a config object as the second parameter'); + (0, _assert2.default)(isString(config.message), 'createError requires a "message" property on the config object passed as the second parameter'); + var e = ApolloError.bind(null, name, config); return e; }; diff --git a/dist/index.js.map b/dist/index.js.map index 41d3c97..299b4a0 100644 --- a/dist/index.js.map +++ b/dist/index.js.map @@ -1 +1 @@ -{"version":3,"sources":["../src/index.js"],"names":["ApolloError","name","message","time_thrown","Date","toISOString","data","options","t","arguments","d","Object","assign","m","opts","_showLocations","showLocations","path","locations","error","isInstance","e","createError","bind","formatError","returnNull","originalError","serialize"],"mappings":";;;;;;;;;AAAA;;;;;;;;;;;;IAEMA,W;;;AACJ,uBAAaC,IAAb,QAKG;AAAA,QAJDC,OAIC,QAJDA,OAIC;AAAA,gCAHDC,WAGC;AAAA,QAHDA,WAGC,oCAHc,IAAIC,IAAJ,EAAD,CAAaC,WAAb,EAGb;AAAA,yBAFDC,IAEC;AAAA,QAFDA,IAEC,6BAFM,EAEN;AAAA,4BADDC,OACC;AAAA,QADDA,OACC,gCADS,EACT;;AAAA;;AACD,QAAMC,IAAKC,UAAU,CAAV,KAAgBA,UAAU,CAAV,EAAaN,WAA9B,IAA8CA,WAAxD;AACA,QAAMO,IAAIC,OAAOC,MAAP,CAAc,EAAd,EAAkBN,IAAlB,EAA0BG,UAAU,CAAV,KAAgBA,UAAU,CAAV,EAAaH,IAA9B,IAAuC,EAAhE,CAAV;AACA,QAAMO,IAAKJ,UAAU,CAAV,KAAgBA,UAAU,CAAV,EAAaP,OAA9B,IAA0CA,OAApD;AACA,QAAMY,OAAOH,OAAOC,MAAP,CAAc,EAAd,EAAkBL,OAAlB,EAA6BE,UAAU,CAAV,KAAgBA,UAAU,CAAV,EAAaF,OAA9B,IAA0C,EAAtE,CAAb;;AAJC,0HAMKM,CANL;;AAQD,UAAKZ,IAAL,GAAYA,IAAZ;AACA,UAAKC,OAAL,GAAeW,CAAf;AACA,UAAKV,WAAL,GAAmBK,CAAnB;AACA,UAAKF,IAAL,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OxD,MAAI,CAACA,IAAD,IAAS,CAACmB,WAAWM,aAAX,CAAd,EAAyC,OAAOD,aAAa,IAAb,GAAoBN,KAA3B;;AAPe,MAShDhB,WATgD,GASDuB,aATC,CAShDvB,WATgD;AAAA,MASnCD,OATmC,GASDwB,aATC,CASnCxB,OATmC;AAAA,MAS1BI,IAT0B,GASDoB,aATC,CAS1BpB,IAT0B;AAAA,MASpBS,cAToB,GASDW,aATC,CASpBX,cAToB;;;AAWxD,MAAIA,cAAJ,EAAoB;AAAA,QACVG,SADU,GACUC,KADV,CACVD,SADU;AAAA,QACCD,IADD,GACUE,KADV,CACCF,IADD;;AAElBS,kBAAcR,SAAd,GAA0BA,SAA1B;AACAQ,kBAAcT,IAAd,GAAqBA,IAArB;AACD;;AAED,SAAOS,cAAcC,SAAd,EAAP;AACD,CAlBM","file":"index.js","sourcesContent":["import ExtendableError from 'es6-error';\n\nclass ApolloError extends ExtendableError {\n constructor (name, {\n message,\n time_thrown = (new Date()).toISOString(),\n data = {},\n options = {},\n }) {\n const t = (arguments[2] && arguments[2].time_thrown) || time_thrown;\n const d = Object.assign({}, data, ((arguments[2] && arguments[2].data) || {}));\n const m = (arguments[2] && arguments[2].message) || message;\n const opts = Object.assign({}, options, ((arguments[2] && arguments[2].options) || {}));\n\n super(m);\n\n this.name = name;\n this.message = m;\n this.time_thrown = t;\n this.data = d;\n this._showLocations = !!opts.showLocations;\n }\n serialize () {\n const { name, message, time_thrown, data, _showLocations, path, locations } = this;\n\n let error = {\n message,\n name,\n time_thrown,\n data,\n };\n\n if (_showLocations) {\n error.locations = locations;\n error.path = path;\n }\n\n return error;\n }\n}\n\nexport const isInstance = e => e instanceof ApolloError;\n\nexport const createError = (name, data = { message: 'An error has occurred', options }) => {\n const e = ApolloError.bind(null, name, data);\n return e;\n};\n\nexport const formatError = (error, returnNull = false) => {\n const originalError = error ? error.originalError || error : null;\n\n if (!originalError) return returnNull ? null : error;\n\n const { name } = originalError;\n\n if (!name || !isInstance(originalError)) return returnNull ? null : error;\n\n const { time_thrown, message, data, _showLocations } = originalError;\n\n if (_showLocations) {\n const { locations, path } = error;\n originalError.locations = locations;\n originalError.path = path;\n }\n\n return originalError.serialize();\n};\n"]} \ No newline at end of file +{"version":3,"sources":["../src/index.js"],"names":["isString","Object","prototype","toString","call","d","isObject","ApolloError","name","message","time_thrown","Date","toISOString","data","options","t","arguments","assign","m","opts","_showLocations","showLocations","path","locations","error","isInstance","e","createError","config","bind","formatError","returnNull","originalError","serialize"],"mappings":";;;;;;;;;AAAA;;;;AACA;;;;;;;;;;;;AAEA,IAAMA,WAAW,SAAXA,QAAW;AAAA,SAAKC,OAAOC,SAAP,CAAiBC,QAAjB,CAA0BC,IAA1B,CAA+BC,CAA/B,MAAsC,iBAA3C;AAAA,CAAjB;AACA,IAAMC,WAAW,SAAXA,QAAW;AAAA,SAAKL,OAAOC,SAAP,CAAiBC,QAAjB,CAA0BC,IAA1B,CAA+BC,CAA/B,MAAsC,iBAA3C;AAAA,CAAjB;;IAEME,W;;;AACJ,uBAAaC,IAAb,QAKG;AAAA,QAJDC,OAIC,QAJDA,OAIC;AAAA,gCAHDC,WAGC;AAAA,QAHDA,WAGC,oCAHc,IAAIC,IAAJ,EAAD,CAAaC,WAAb,EAGb;AAAA,yBAFDC,IAEC;AAAA,QAFDA,IAEC,6BAFM,EAEN;AAAA,4BADDC,OACC;AAAA,QADDA,OACC,gCADS,EACT;;AAAA;;AACD,QAAMC,IAAKC,UAAU,CAAV,KAAgBA,UAAU,CAAV,EAAaN,WAA9B,IAA8CA,WAAxD;AACA,QAAML,IAAIJ,OAAOgB,MAAP,CAAc,EAAd,EAAkBJ,IAAlB,EAA0BG,UAAU,CAAV,KAAgBA,UAAU,CAAV,EAAaH,IAA9B,IAAuC,EAAhE,CAAV;AACA,QAAMK,IAAKF,UAAU,CAAV,KAAgBA,UAAU,CAAV,EAAaP,OAA9B,IAA0CA,OAApD;AACA,QAAMU,OAAOlB,OAAOgB,MAAP,CAAc,EAA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MI,oCAAc,SAAdA,WAAc,CAACN,KAAD,EAA+B;AAAA,MAAvBO,UAAuB,uEAAV,KAAU;;AACxD,MAAMC,gBAAgBR,QAAQA,MAAMQ,aAAN,IAAuBR,KAA/B,GAAuC,IAA7D;;AAEA,MAAI,CAACQ,aAAL,EAAoB,OAAOD,aAAa,IAAb,GAAoBP,KAA3B;;AAHoC,MAKhDhB,IALgD,GAKvCwB,aALuC,CAKhDxB,IALgD;;;AAOxD,MAAI,CAACA,IAAD,IAAS,CAACiB,WAAWO,aAAX,CAAd,EAAyC,OAAOD,aAAa,IAAb,GAAoBP,KAA3B;;AAPe,MAShDd,WATgD,GASDsB,aATC,CAShDtB,WATgD;AAAA,MASnCD,OATmC,GASDuB,aATC,CASnCvB,OATmC;AAAA,MAS1BI,IAT0B,GASDmB,aATC,CAS1BnB,IAT0B;AAAA,MASpBO,cAToB,GASDY,aATC,CASpBZ,cAToB;;;AAWxD,MAAIA,cAAJ,EAAoB;AAAA,QACVG,SADU,GACUC,KADV,CACVD,SADU;AAAA,QACCD,IADD,GACUE,KADV,CACCF,IADD;;AAElBU,kBAAcT,SAAd,GAA0BA,SAA1B;AACAS,kBAAcV,IAAd,GAAqBA,IAArB;AACD;;AAED,SAAOU,cAAcC,SAAd,EAAP;AACD,CAlBM","file":"index.js","sourcesContent":["import assert from 'assert';\nimport ExtendableError from 'es6-error';\n\nconst isString = d => Object.prototype.toString.call(d) === '[object String]';\nconst isObject = d => Object.prototype.toString.call(d) === '[object Object]';\n\nclass ApolloError extends ExtendableError {\n constructor (name, {\n message,\n time_thrown = (new Date()).toISOString(),\n data = {},\n options = {},\n }) {\n const t = (arguments[2] && arguments[2].time_thrown) || time_thrown;\n const d = Object.assign({}, data, ((arguments[2] && arguments[2].data) || {}));\n const m = (arguments[2] && arguments[2].message) || message;\n const opts = Object.assign({}, options, ((arguments[2] && arguments[2].options) || {}));\n\n super(m);\n\n this.name = name;\n this.message = m;\n this.time_thrown = t;\n this.data = d;\n this._showLocations = !!opts.showLocations;\n }\n serialize () {\n const { name, message, time_thrown, data, _showLocations, path, locations } = this;\n\n let error = {\n message,\n name,\n time_thrown,\n data,\n };\n\n if (_showLocations) {\n error.locations = locations;\n error.path = path;\n }\n\n return error;\n }\n}\n\nexport const isInstance = e => e instanceof ApolloError;\n\nexport const createError = (name, config) => {\n assert(isObject(config), 'createError requires a config object as the second parameter');\n assert(isString(config.message), 'createError requires a \"message\" property on the config object passed as the second parameter');\n const e = ApolloError.bind(null, name, config);\n return e;\n};\n\nexport const formatError = (error, returnNull = false) => {\n const originalError = error ? error.originalError || error : null;\n\n if (!originalError) return returnNull ? null : error;\n\n const { name } = originalError;\n\n if (!name || !isInstance(originalError)) return returnNull ? null : error;\n\n const { time_thrown, message, data, _showLocations } = originalError;\n\n if (_showLocations) {\n const { locations, path } = error;\n originalError.locations = locations;\n originalError.path = path;\n }\n\n return originalError.serialize();\n};\n"]} \ No newline at end of file diff --git a/package.json b/package.json index 34e5f06..1c7b9c0 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "apollo-errors", - "version": "1.4.0", + "version": "1.5.0", "description": "Machine-readable custom errors for Apollostack's GraphQL server", "main": "dist/index.js", "scripts": { diff --git a/src/index.js b/src/index.js index f97c9c7..8058dad 100644 --- a/src/index.js +++ b/src/index.js @@ -1,5 +1,9 @@ +import assert from 'assert'; import ExtendableError from 'es6-error'; +const isString = d => Object.prototype.toString.call(d) === '[object String]'; +const isObject = d => Object.prototype.toString.call(d) === '[object Object]'; + class ApolloError extends ExtendableError { constructor (name, { message, @@ -41,8 +45,10 @@ class ApolloError extends ExtendableError { export const isInstance = e => e instanceof ApolloError; -export const createError = (name, data = { message: 'An error has occurred', options }) => { - const e = ApolloError.bind(null, name, data); +export const createError = (name, config) => { + assert(isObject(config), 'createError requires a config object as the second parameter'); + assert(isString(config.message), 'createError requires a "message" property on the config object passed as the second parameter'); + const e = ApolloError.bind(null, name, config); return e; }; diff --git a/test/spec.js b/test/spec.js index fc510b4..475fd46 100644 --- a/test/spec.js +++ b/test/spec.js @@ -3,39 +3,65 @@ import { expect } from 'chai'; import { createError, formatError } from '../dist'; describe('createError', () => { - it('returns an error that serializes properly', () => { - const FooError = createError('FooError', { - message: 'A foo error has occurred', - data: { - hello: 'world' - }, - options: { - showLocations: false, - showPath: true, - }, - }); + context('when properly used', () => { + it('returns an error that serializes properly', () => { + const FooError = createError('FooError', { + message: 'A foo error has occurred', + data: { + hello: 'world' + }, + options: { + showLocations: false, + showPath: true, + }, + }); - const iso = new Date().toISOString(); + const iso = new Date().toISOString(); - const e = new FooError({ - message: 'A foo 2.0 error has occurred', - data: { - foo: 'bar' - }, - options: { - showLocations: true, - showPath: false, - }, - }); + const e = new FooError({ + message: 'A foo 2.0 error has occurred', + data: { + foo: 'bar' + }, + options: { + showLocations: true, + showPath: false, + }, + }); - const { message, name, time_thrown, data } = e.serialize(); + const { message, name, time_thrown, data } = e.serialize(); - expect(message).to.equal('A foo 2.0 error has occurred'); - expect(name).to.equal('FooError'); - expect(time_thrown).to.equal(e.time_thrown); - expect(data).to.eql({ - hello: 'world', - foo: 'bar' + expect(message).to.equal('A foo 2.0 error has occurred'); + expect(name).to.equal('FooError'); + expect(time_thrown).to.equal(e.time_thrown); + expect(data).to.eql({ + hello: 'world', + foo: 'bar' + }); + }); + }); + context('when missing a config as the second parameter', () => { + it('throws an assertion error with a useful message', () => { + try { + createError('FooError'); + throw new Error('did not throw as expected'); + } catch (err) { + expect(err.name).to.equal('AssertionError [ERR_ASSERTION]'); + expect(err.message).to.equal('createError requires a config object as the second parameter'); + } + }); + }); + context('when missing a message from the config object passed as the second parameter', () => { + it('throws an assertion error with a useful message', () => { + try { + createError('FooError', { + + }); + throw new Error('did not throw as expected'); + } catch (err) { + expect(err.name).to.equal('AssertionError [ERR_ASSERTION]'); + expect(err.message).to.equal('createError requires a "message" property on the config object passed as the second parameter') + } }); }); }); From 96770589711ce3916e1c52a257d9e4fb304e3401 Mon Sep 17 00:00:00 2001 From: Andrew Rhyne Date: Tue, 29 Aug 2017 11:01:25 -0700 Subject: [PATCH 10/57] release 1.5.0 --- CHANGELOG.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index fe7c4f2..aa7af5d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,4 +1,9 @@ +1.5.0 / 2017-08-29 +================== + + * Fix: fixed syntax error for createError config parameter (@thebigredgeek) + 1.4.0 / 2017-03-14 ================== * Feature: (BREAKING) Rely on error.originalError and fail back to error for formatError rather than serializing body into message From b0fe790866e812d743915f166a090d883ea74929 Mon Sep 17 00:00:00 2001 From: Andrew Rhyne Date: Thu, 7 Sep 2017 10:08:39 -0700 Subject: [PATCH 11/57] updated docs to reference apollo-server and added new keywords to npm package --- README.md | 1 + package.json | 4 +++- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 78a9f01..9b06322 100644 --- a/README.md +++ b/README.md @@ -33,6 +33,7 @@ Hook up formatting: import express from 'express'; import bodyParser from 'body-parser'; import { formatError } from 'apollo-errors'; +import { graphqlExpress } from 'apollo-server-express'; import schema from './schema'; const app = express(); diff --git a/package.json b/package.json index 1c7b9c0..cc41294 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "apollo-errors", - "version": "1.5.0", + "version": "1.5.1", "description": "Machine-readable custom errors for Apollostack's GraphQL server", "main": "dist/index.js", "scripts": { @@ -13,6 +13,8 @@ "keywords": [ "apollostack", "graphql", + "apollo-server", + "apollo-client", "error", "api" ], From e883f2e8084c3777df1365fcd6db9d400778409f Mon Sep 17 00:00:00 2001 From: Andrew Rhyne Date: Thu, 7 Sep 2017 10:11:48 -0700 Subject: [PATCH 12/57] release 1.5.1 --- CHANGELOG.md | 6 ++++++ test/spec.js | 9 ++++++--- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index aa7af5d..4a3b7a3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,4 +1,10 @@ +1.5.1 / 2017-09-07 +================== + + * Package: Added new keywords (@thebigredgeek) + * Docs: Updated docs to reference [apollo-server](https://dev.apollodata.com/tools/apollo-server/setup.html) (@thebigredgeek) + 1.5.0 / 2017-08-29 ================== diff --git a/test/spec.js b/test/spec.js index 475fd46..c8735fe 100644 --- a/test/spec.js +++ b/test/spec.js @@ -1,7 +1,10 @@ import { expect } from 'chai'; +import assert from 'assert'; import { createError, formatError } from '../dist'; +const { AssertionError } = assert; + describe('createError', () => { context('when properly used', () => { it('returns an error that serializes properly', () => { @@ -46,7 +49,7 @@ describe('createError', () => { createError('FooError'); throw new Error('did not throw as expected'); } catch (err) { - expect(err.name).to.equal('AssertionError [ERR_ASSERTION]'); + expect(err instanceof AssertionError).to.be.true; expect(err.message).to.equal('createError requires a config object as the second parameter'); } }); @@ -55,11 +58,11 @@ describe('createError', () => { it('throws an assertion error with a useful message', () => { try { createError('FooError', { - + }); throw new Error('did not throw as expected'); } catch (err) { - expect(err.name).to.equal('AssertionError [ERR_ASSERTION]'); + expect(err instanceof AssertionError).to.be.true; expect(err.message).to.equal('createError requires a "message" property on the config object passed as the second parameter') } }); From 4f64e9746a7018a3514e8c5c9cb94c7f53b6f2d8 Mon Sep 17 00:00:00 2001 From: lakhansamani Date: Mon, 11 Sep 2017 14:55:20 +0530 Subject: [PATCH 13/57] Adds typescript version of apollo-error --- .gitignore | 1 + Makefile | 2 +- dist/index.js | 199 +++++++++++++------------------------ dist/index.js.map | 2 +- package.json | 10 +- src/{index.js => index.ts} | 18 +++- test/spec.js | 3 - tsconfig.json | 17 ++++ 8 files changed, 111 insertions(+), 141 deletions(-) rename src/{index.js => index.ts} (84%) create mode 100644 tsconfig.json diff --git a/.gitignore b/.gitignore index 682ca08..dd71061 100644 --- a/.gitignore +++ b/.gitignore @@ -2,6 +2,7 @@ logs *.log npm-debug.log* +package-lock.json # Runtime data pids diff --git a/Makefile b/Makefile index bf4762d..e6404d5 100644 --- a/Makefile +++ b/Makefile @@ -13,7 +13,7 @@ endif .FORCE: all: clean - babel src -d dist --source-maps + npm run build clean: .FORCE rimraf npm-debug.log dist diff --git a/dist/index.js b/dist/index.js index e01b125..1488be6 100644 --- a/dist/index.js +++ b/dist/index.js @@ -1,132 +1,75 @@ -'use strict'; - -Object.defineProperty(exports, "__esModule", { - value: true -}); -exports.formatError = exports.createError = exports.isInstance = undefined; - -var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }(); - -var _assert = require('assert'); - -var _assert2 = _interopRequireDefault(_assert); - -var _es6Error = require('es6-error'); - -var _es6Error2 = _interopRequireDefault(_es6Error); - -function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } - -function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } - -function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; } - -function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; } - -var isString = function isString(d) { - return Object.prototype.toString.call(d) === '[object String]'; -}; -var isObject = function isObject(d) { - return Object.prototype.toString.call(d) === '[object Object]'; -}; - -var ApolloError = function (_ExtendableError) { - _inherits(ApolloError, _ExtendableError); - - function ApolloError(name, _ref) { - var message = _ref.message, - _ref$time_thrown = _ref.time_thrown, - time_thrown = _ref$time_thrown === undefined ? new Date().toISOString() : _ref$time_thrown, - _ref$data = _ref.data, - data = _ref$data === undefined ? {} : _ref$data, - _ref$options = _ref.options, - options = _ref$options === undefined ? {} : _ref$options; - - _classCallCheck(this, ApolloError); - - var t = arguments[2] && arguments[2].time_thrown || time_thrown; - var d = Object.assign({}, data, arguments[2] && arguments[2].data || {}); - var m = arguments[2] && arguments[2].message || message; - var opts = Object.assign({}, options, arguments[2] && arguments[2].options || {}); - - var _this = _possibleConstructorReturn(this, (ApolloError.__proto__ || Object.getPrototypeOf(ApolloError)).call(this, m)); - - _this.name = name; - _this.message = m; - _this.time_thrown = t; - _this.data = d; - _this._showLocations = !!opts.showLocations; - return _this; - } - - _createClass(ApolloError, [{ - key: 'serialize', - value: function serialize() { - var name = this.name, - message = this.message, - time_thrown = this.time_thrown, - data = this.data, - _showLocations = this._showLocations, - path = this.path, - locations = this.locations; - - - var error = { - message: message, - name: name, - time_thrown: time_thrown, - data: data - }; - - if (_showLocations) { - error.locations = locations; - error.path = path; - } - - return error; +"use strict"; +var __extends = (this && this.__extends) || (function () { + var extendStatics = Object.setPrototypeOf || + ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || + function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; + return function (d, b) { + extendStatics(d, b); + function __() { this.constructor = d; } + d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); + }; +})(); +Object.defineProperty(exports, "__esModule", { value: true }); +var assert = require("assert"); +var extendable_error_1 = require("extendable-error"); +var isString = function (d) { return Object.prototype.toString.call(d) === '[object String]'; }; +var isObject = function (d) { return Object.prototype.toString.call(d) === '[object Object]'; }; +var ApolloError = /** @class */ (function (_super) { + __extends(ApolloError, _super); + function ApolloError(name, _a) { + var message = _a.message, _b = _a.time_thrown, time_thrown = _b === void 0 ? (new Date()).toISOString() : _b, _c = _a.data, data = _c === void 0 ? {} : _c, _d = _a.options, options = _d === void 0 ? {} : _d; + var _this = this; + var t = (arguments[2] && arguments[2].time_thrown) || time_thrown; + var d = ((arguments[2] && arguments[2].data) || {}); + var m = (arguments[2] && arguments[2].message) || message; + var opts = ((arguments[2] && arguments[2].options) || {}); + _this = _super.call(this, m) || this; + _this.name = name; + _this.message = m; + _this.time_thrown = t; + _this.data = d; + _this._showLocations = !!opts.showLocations; + return _this; } - }]); - - return ApolloError; -}(_es6Error2.default); - -var isInstance = exports.isInstance = function isInstance(e) { - return e instanceof ApolloError; + ApolloError.prototype.serialize = function () { + var _a = this, name = _a.name, message = _a.message, time_thrown = _a.time_thrown, data = _a.data, _showLocations = _a._showLocations, path = _a.path, locations = _a.locations; + var error = { + message: message, + name: name, + time_thrown: time_thrown, + data: data, + path: path, + locations: locations + }; + if (_showLocations) { + error.locations = locations; + error.path = path; + } + return error; + }; + return ApolloError; +}(extendable_error_1.default)); +exports.isInstance = function (e) { return e instanceof ApolloError; }; +exports.createError = function (name, config) { + assert(isObject(config), 'createError requires a config object as the second parameter'); + assert(isString(config.message), 'createError requires a "message" property on the config object passed as the second parameter'); + var e = ApolloError.bind(null, name, config); + return e; }; - -var createError = exports.createError = function createError(name, config) { - (0, _assert2.default)(isObject(config), 'createError requires a config object as the second parameter'); - (0, _assert2.default)(isString(config.message), 'createError requires a "message" property on the config object passed as the second parameter'); - var e = ApolloError.bind(null, name, config); - return e; -}; - -var formatError = exports.formatError = function formatError(error) { - var returnNull = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false; - - var originalError = error ? error.originalError || error : null; - - if (!originalError) return returnNull ? null : error; - - var name = originalError.name; - - - if (!name || !isInstance(originalError)) return returnNull ? null : error; - - var time_thrown = originalError.time_thrown, - message = originalError.message, - data = originalError.data, - _showLocations = originalError._showLocations; - - - if (_showLocations) { - var locations = error.locations, - path = error.path; - - originalError.locations = locations; - originalError.path = path; - } - - return originalError.serialize(); +exports.formatError = function (error, returnNull) { + if (returnNull === void 0) { returnNull = false; } + var originalError = error ? error.originalError || error : null; + if (!originalError) + return returnNull ? null : error; + var name = originalError.name; + if (!name || !exports.isInstance(originalError)) + return returnNull ? null : error; + var time_thrown = originalError.time_thrown, message = originalError.message, data = originalError.data, _showLocations = originalError._showLocations; + if (_showLocations) { + var locations = error.locations, path = error.path; + originalError.locations = locations; + originalError.path = path; + } + return originalError.serialize(); }; //# sourceMappingURL=index.js.map \ No newline at end of file diff --git a/dist/index.js.map b/dist/index.js.map index 299b4a0..3cce339 100644 --- a/dist/index.js.map +++ b/dist/index.js.map @@ -1 +1 @@ -{"version":3,"sources":["../src/index.js"],"names":["isString","Object","prototype","toString","call","d","isObject","ApolloError","name","message","time_thrown","Date","toISOString","data","options","t","arguments","assign","m","opts","_showLocations","showLocations","path","locations","error","isInstance","e","createError","config","bind","formatError","returnNull","originalError","serialize"],"mappings":";;;;;;;;;AAAA;;;;AACA;;;;;;;;;;;;AAEA,IAAMA,WAAW,SAAXA,QAAW;AAAA,SAAKC,OAAOC,SAAP,CAAiBC,QAAjB,CAA0BC,IAA1B,CAA+BC,CAA/B,MAAsC,iBAA3C;AAAA,CAAjB;AACA,IAAMC,WAAW,SAAXA,QAAW;AAAA,SAAKL,OAAOC,SAAP,CAAiBC,QAAjB,CAA0BC,IAA1B,CAA+BC,CAA/B,MAAsC,iBAA3C;AAAA,CAAjB;;IAEME,W;;;AACJ,uBAAaC,IAAb,QAKG;AAAA,QAJDC,OAIC,QAJDA,OAIC;AAAA,gCAHDC,WAGC;AAAA,QAHDA,WAGC,oCAHc,IAAIC,IAAJ,EAAD,CAAaC,WAAb,EAGb;AAAA,yBAFDC,IAEC;AAAA,QAFDA,IAEC,6BAFM,EAEN;AAAA,4BADDC,OACC;AAAA,QADDA,OACC,gCADS,EACT;;AAAA;;AACD,QAAMC,IAAKC,UAAU,CAAV,KAAgBA,UAAU,CAAV,EAAaN,WAA9B,IAA8CA,WAAxD;AACA,QAAML,IAAIJ,OAAOgB,MAAP,CAAc,EAAd,EAAkBJ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AAP,EAAyB,8DAAzB;AACA,wBAAO5B,SAAS4B,OAAOnB,OAAhB,CAAP,EAAiC,+FAAjC;AACA,MAAMiB,IAAInB,YAAYsB,IAAZ,CAAiB,IAAjB,EAAuBrB,IAAvB,EAA6BoB,MAA7B,CAAV;AACA,SAAOF,CAAP;AACD,CALM;;AAOA,IAAMI,oCAAc,SAAdA,WAAc,CAACN,KAAD,EAA+B;AAAA,MAAvBO,UAAuB,uEAAV,KAAU;;AACxD,MAAMC,gBAAgBR,QAAQA,MAAMQ,aAAN,IAAuBR,KAA/B,GAAuC,IAA7D;;AAEA,MAAI,CAACQ,aAAL,EAAoB,OAAOD,aAAa,IAAb,GAAoBP,KAA3B;;AAHoC,MAKhDhB,IALgD,GAKvCwB,aALuC,CAKhDxB,IALgD;;;AAOxD,MAAI,CAACA,IAAD,IAAS,CAACiB,WAAWO,aAAX,CAAd,EAAyC,OAAOD,aAAa,IAAb,GAAoBP,KAA3B;;AAPe,MAShDd,WATgD,GASDsB,aATC,CAShDtB,WATgD;AAAA,MASnCD,OATmC,GASDuB,aATC,CASnCvB,OATmC;AAAA,MAS1BI,IAT0B,GASDmB,aATC,CAS1BnB,IAT0B;AAAA,MASpBO,cAToB,GASDY,aATC,CASpBZ,cAToB;;;AAWxD,MAAIA,cAAJ,EAAoB;AAAA,QACVG,SADU,GACUC,KADV,CACVD,SADU;AAAA,QACCD,IADD,GACUE,KADV,CACCF,IADD;;AAElBU,kBAAcT,SAAd,GAA0BA,SAA1B;AACAS,kBAAcV,IAAd,GAAqBA,IAArB;AACD;;AAED,SAAOU,cAAcC,SAAd,EAAP;AACD,CAlBM","file":"index.js","sourcesContent":["import assert from 'assert';\nimport ExtendableError from 'es6-error';\n\nconst isString = d => Object.prototype.toString.call(d) === '[object String]';\nconst isObject = d => Object.prototype.toString.call(d) === '[object Object]';\n\nclass ApolloError extends ExtendableError {\n constructor (name, {\n message,\n time_thrown = (new Date()).toISOString(),\n data = {},\n options = {},\n }) {\n const t = (arguments[2] && arguments[2].time_thrown) || time_thrown;\n const d = Object.assign({}, data, ((arguments[2] && arguments[2].data) || {}));\n const m = (arguments[2] && arguments[2].message) || message;\n const opts = Object.assign({}, options, ((arguments[2] && arguments[2].options) || {}));\n\n super(m);\n\n this.name = name;\n this.message = m;\n this.time_thrown = t;\n this.data = d;\n this._showLocations = !!opts.showLocations;\n }\n serialize () {\n const { name, message, time_thrown, data, _showLocations, path, locations } = this;\n\n let error = {\n message,\n name,\n time_thrown,\n data,\n };\n\n if (_showLocations) {\n error.locations = locations;\n error.path = path;\n }\n\n return error;\n }\n}\n\nexport const isInstance = e => e instanceof ApolloError;\n\nexport const createError = (name, config) => {\n assert(isObject(config), 'createError requires a config object as the second parameter');\n assert(isString(config.message), 'createError requires a \"message\" property on the config object passed as the second parameter');\n const e = ApolloError.bind(null, name, config);\n return e;\n};\n\nexport const formatError = (error, returnNull = false) => {\n const originalError = error ? error.originalError || error : null;\n\n if (!originalError) return returnNull ? null : error;\n\n const { name } = originalError;\n\n if (!name || !isInstance(originalError)) return returnNull ? null : error;\n\n const { time_thrown, message, data, _showLocations } = originalError;\n\n if (_showLocations) {\n const { locations, path } = error;\n originalError.locations = locations;\n originalError.path = path;\n }\n\n return originalError.serialize();\n};\n"]} \ No newline at end of file +{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,+BAAiC;AACjC,qDAA+C;AAE/C,IAAM,QAAQ,GAAG,UAAA,CAAC,IAAI,OAAA,MAAM,CAAC,SAAS,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC,CAAC,KAAK,iBAAiB,EAAvD,CAAuD,CAAC;AAC9E,IAAM,QAAQ,GAAG,UAAA,CAAC,IAAI,OAAA,MAAM,CAAC,SAAS,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC,CAAC,KAAK,iBAAiB,EAAvD,CAAuD,CAAC;AAC9E;IAA0B,+BAAe;IAQvC,qBAAa,IAAI,EAAE,EAKl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Aa,CAAC,IAAI,GAAG,IAAI,CAAC;IAC5B,CAAC;IAED,MAAM,CAAC,aAAa,CAAC,SAAS,EAAE,CAAC;AACnC,CAAC,CAAC"} \ No newline at end of file diff --git a/package.json b/package.json index cc41294..79be9b1 100644 --- a/package.json +++ b/package.json @@ -4,7 +4,8 @@ "description": "Machine-readable custom errors for Apollostack's GraphQL server", "main": "dist/index.js", "scripts": { - "test": "make test" + "test": "make test", + "build": "tsc" }, "repository": { "type": "git", @@ -25,7 +26,8 @@ }, "homepage": "https://github.com/thebigredgeek/apollo-errors#readme", "dependencies": { - "es6-error": "^4.0.0" + "assert": "^1.4.1", + "extendable-error": "^0.1.5" }, "devDependencies": { "babel-cli": "^6.18.0", @@ -37,6 +39,8 @@ "eslint": "^3.8.1", "eslint-plugin-babel": "^3.3.0", "mocha": "^3.1.2", - "rimraf": "^2.5.4" + "rimraf": "^2.5.4", + "typescript": "^2.5.2", + "typings": "^2.1.1" } } diff --git a/src/index.js b/src/index.ts similarity index 84% rename from src/index.js rename to src/index.ts index 8058dad..ff933fe 100644 --- a/src/index.js +++ b/src/index.ts @@ -1,10 +1,16 @@ -import assert from 'assert'; -import ExtendableError from 'es6-error'; +import * as assert from 'assert'; +import ExtendableError from 'extendable-error'; const isString = d => Object.prototype.toString.call(d) === '[object String]'; const isObject = d => Object.prototype.toString.call(d) === '[object Object]'; - class ApolloError extends ExtendableError { + name: any; + message: any; + time_thrown: any; + data: any; + path: any; + locations: any; + _showLocations: any; constructor (name, { message, time_thrown = (new Date()).toISOString(), @@ -12,9 +18,9 @@ class ApolloError extends ExtendableError { options = {}, }) { const t = (arguments[2] && arguments[2].time_thrown) || time_thrown; - const d = Object.assign({}, data, ((arguments[2] && arguments[2].data) || {})); + const d = ((arguments[2] && arguments[2].data) || {}) const m = (arguments[2] && arguments[2].message) || message; - const opts = Object.assign({}, options, ((arguments[2] && arguments[2].options) || {})); + const opts = ((arguments[2] && arguments[2].options) || {}) super(m); @@ -32,6 +38,8 @@ class ApolloError extends ExtendableError { name, time_thrown, data, + path, + locations }; if (_showLocations) { diff --git a/test/spec.js b/test/spec.js index c8735fe..27b7525 100644 --- a/test/spec.js +++ b/test/spec.js @@ -18,7 +18,6 @@ describe('createError', () => { showPath: true, }, }); - const iso = new Date().toISOString(); const e = new FooError({ @@ -31,14 +30,12 @@ describe('createError', () => { showPath: false, }, }); - const { message, name, time_thrown, data } = e.serialize(); expect(message).to.equal('A foo 2.0 error has occurred'); expect(name).to.equal('FooError'); expect(time_thrown).to.equal(e.time_thrown); expect(data).to.eql({ - hello: 'world', foo: 'bar' }); }); diff --git a/tsconfig.json b/tsconfig.json new file mode 100644 index 0000000..c1e6bf1 --- /dev/null +++ b/tsconfig.json @@ -0,0 +1,17 @@ +{ + "compilerOptions": { + "target": "es5", + "module": "commonjs", + "moduleResolution": "node", + "sourceMap": true, + "emitDecoratorMetadata": true, + "experimentalDecorators": true, + "removeComments": false, + "noImplicitAny": false, + "allowJs": true, + "outDir": "./dist" + }, + "include": [ + "./src/**/*" + ] +} From 7e3af95b7a6f337300f2fa573b4c8623ad480c46 Mon Sep 17 00:00:00 2001 From: lakhansamani Date: Wed, 20 Sep 2017 12:40:10 +0530 Subject: [PATCH 14/57] Adds interface for configuration --- dist/index.js | 12 ++++++------ dist/index.js.map | 2 +- src/index.ts | 29 ++++++++++++++++------------- 3 files changed, 23 insertions(+), 20 deletions(-) diff --git a/dist/index.js b/dist/index.js index 1488be6..4c61d33 100644 --- a/dist/index.js +++ b/dist/index.js @@ -16,13 +16,12 @@ var isString = function (d) { return Object.prototype.toString.call(d) === '[obj var isObject = function (d) { return Object.prototype.toString.call(d) === '[object Object]'; }; var ApolloError = /** @class */ (function (_super) { __extends(ApolloError, _super); - function ApolloError(name, _a) { - var message = _a.message, _b = _a.time_thrown, time_thrown = _b === void 0 ? (new Date()).toISOString() : _b, _c = _a.data, data = _c === void 0 ? {} : _c, _d = _a.options, options = _d === void 0 ? {} : _d; + function ApolloError(name, config) { var _this = this; - var t = (arguments[2] && arguments[2].time_thrown) || time_thrown; - var d = ((arguments[2] && arguments[2].data) || {}); - var m = (arguments[2] && arguments[2].message) || message; - var opts = ((arguments[2] && arguments[2].options) || {}); + var t = (config && config.time_thrown) || (new Date()).toISOString(); + var d = (config && config.data || {}); + var m = (config && config.message) || ''; + var opts = ((config && config.options) || {}); _this = _super.call(this, m) || this; _this.name = name; _this.message = m; @@ -51,6 +50,7 @@ var ApolloError = /** @class */ (function (_super) { }(extendable_error_1.default)); exports.isInstance = function (e) { return e instanceof ApolloError; }; exports.createError = function (name, config) { + console.log('config', config); assert(isObject(config), 'createError requires a config object as the second parameter'); assert(isString(config.message), 'createError requires a "message" property on the config object passed as the second parameter'); var e = ApolloError.bind(null, name, config); diff --git a/dist/index.js.map b/dist/index.js.map index 3cce339..3f18dcb 100644 --- a/dist/index.js.map +++ b/dist/index.js.map @@ -1 +1 @@ -{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,+BAAiC;AACjC,qDAA+C;AAE/C,IAAM,QAAQ,GAAG,UAAA,CAAC,IAAI,OAAA,MAAM,CAAC,SAAS,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC,CAAC,KAAK,iBAAiB,EAAvD,CAAuD,CAAC;AAC9E,IAAM,QAAQ,GAAG,UAAA,CAAC,IAAI,OAAA,MAAM,CAAC,SAAS,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC,CAAC,KAAK,iBAAiB,EAAvD,CAAuD,CAAC;AAC9E;IAA0B,+BAAe;IAQvC,qBAAa,IAAI,EAAE,EAKlB;YAJC,oBAAO,EACP,mBAAwC,EAAxC,6DAAwC,EACxC,YAAS,EAAT,8BAAS,EACT,eAAY,EAAZ,iCAAY;QAJd,iBAkBC;QAZC,IAAM,CAAC,GAAG,CAAC,SAAS,CAAC,CAAC,CAAC,IAAI,SAAS,CAAC,CAAC,CAAC,CAAC,WAAW,CAAC,IAAI,WAAW,CAAC;Q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,IAAA,uCAAW,EAAE,+BAAO,EAAE,yBAAI,EAAE,6CAAc,CAAmB;IAErE,EAAE,CAAC,CAAC,cAAc,CAAC,CAAC,CAAC;QACX,IAAA,2BAAS,EAAE,iBAAI,CAAW;QAClC,aAAa,CAAC,SAAS,GAAG,SAAS,CAAC;QACpC,aAAa,CAAC,IAAI,GAAG,IAAI,CAAC;IAC5B,CAAC;IAED,MAAM,CAAC,aAAa,CAAC,SAAS,EAAE,CAAC;AACnC,CAAC,CAAC"} \ No newline at end of file diff --git a/src/index.ts b/src/index.ts index ff933fe..1702589 100644 --- a/src/index.ts +++ b/src/index.ts @@ -3,24 +3,26 @@ import ExtendableError from 'extendable-error'; const isString = d => Object.prototype.toString.call(d) === '[object String]'; const isObject = d => Object.prototype.toString.call(d) === '[object Object]'; +interface ErrorConfig { + message: string; + time_thrown: any; + data: any, + options: any, +} + class ApolloError extends ExtendableError { - name: any; - message: any; + name: string; + message: string; time_thrown: any; data: any; path: any; locations: any; _showLocations: any; - constructor (name, { - message, - time_thrown = (new Date()).toISOString(), - data = {}, - options = {}, - }) { - const t = (arguments[2] && arguments[2].time_thrown) || time_thrown; - const d = ((arguments[2] && arguments[2].data) || {}) - const m = (arguments[2] && arguments[2].message) || message; - const opts = ((arguments[2] && arguments[2].options) || {}) + constructor (name, config: ErrorConfig) { + const t = (config && config.time_thrown) || (new Date()).toISOString(); + const d = (config && config.data || {}) + const m = (config && config.message) || ''; + const opts = ((config && config.options) || {}) super(m); @@ -53,7 +55,8 @@ class ApolloError extends ExtendableError { export const isInstance = e => e instanceof ApolloError; -export const createError = (name, config) => { +export const createError = (name, config: ErrorConfig) => { + console.log('config', config); assert(isObject(config), 'createError requires a config object as the second parameter'); assert(isString(config.message), 'createError requires a "message" property on the config object passed as the second parameter'); const e = ApolloError.bind(null, name, config); From fbac46baaf2d7084c7e8b7008b29b17180524e22 Mon Sep 17 00:00:00 2001 From: lakhansamani Date: Thu, 21 Sep 2017 10:17:15 +0530 Subject: [PATCH 15/57] Adds interface for config --- dist/index.js | 21 ++++++++++++++------- dist/index.js.map | 2 +- package.json | 3 ++- src/index.ts | 17 ++++++----------- test/spec.js | 10 +++++----- 5 files changed, 28 insertions(+), 25 deletions(-) diff --git a/dist/index.js b/dist/index.js index 4c61d33..3122edf 100644 --- a/dist/index.js +++ b/dist/index.js @@ -9,6 +9,14 @@ var __extends = (this && this.__extends) || (function () { d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); }; })(); +var __assign = (this && this.__assign) || Object.assign || function(t) { + for (var s, i = 1, n = arguments.length; i < n; i++) { + s = arguments[i]; + for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) + t[p] = s[p]; + } + return t; +}; Object.defineProperty(exports, "__esModule", { value: true }); var assert = require("assert"); var extendable_error_1 = require("extendable-error"); @@ -17,12 +25,12 @@ var isObject = function (d) { return Object.prototype.toString.call(d) === '[obj var ApolloError = /** @class */ (function (_super) { __extends(ApolloError, _super); function ApolloError(name, config) { - var _this = this; - var t = (config && config.time_thrown) || (new Date()).toISOString(); - var d = (config && config.data || {}); - var m = (config && config.message) || ''; - var opts = ((config && config.options) || {}); - _this = _super.call(this, m) || this; + var _this = _super.call(this, (config && config.message) || '') || this; + var t = (arguments[2] && arguments[2].time_thrown) || (new Date()).toISOString(); + var m = (arguments[2] && arguments[2].message) || ''; + var configData = (arguments[2] && arguments[2].data) || {}; + var d = __assign({}, _this.data, configData); + var opts = ((arguments[2] && arguments[2].options) || {}); _this.name = name; _this.message = m; _this.time_thrown = t; @@ -50,7 +58,6 @@ var ApolloError = /** @class */ (function (_super) { }(extendable_error_1.default)); exports.isInstance = function (e) { return e instanceof ApolloError; }; exports.createError = function (name, config) { - console.log('config', config); assert(isObject(config), 'createError requires a config object as the second parameter'); assert(isString(config.message), 'createError requires a "message" property on the config object passed as the second parameter'); var e = ApolloError.bind(null, name, config); diff --git a/dist/index.js.map b/dist/index.js.map index 3f18dcb..b0749a6 100644 --- a/dist/index.js.map +++ b/d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AW,GAAG,UAAC,IAAI,EAAE,MAAmB;IACnD,MAAM,CAAC,QAAQ,CAAC,MAAM,CAAC,EAAE,8DAA8D,CAAC,CAAC;IACzF,MAAM,CAAC,QAAQ,CAAC,MAAM,CAAC,OAAO,CAAC,EAAE,+FAA+F,CAAC,CAAC;IAClI,IAAM,CAAC,GAAG,WAAW,CAAC,IAAI,CAAC,IAAI,EAAE,IAAI,EAAE,MAAM,CAAC,CAAC;IAC/C,MAAM,CAAC,CAAC,CAAC;AACX,CAAC,CAAC;AAEW,QAAA,WAAW,GAAG,UAAC,KAAK,EAAE,UAAkB;IAAlB,2BAAA,EAAA,kBAAkB;IACnD,IAAM,aAAa,GAAG,KAAK,GAAG,KAAK,CAAC,aAAa,IAAI,KAAK,GAAG,IAAI,CAAC;IAElE,EAAE,CAAC,CAAC,CAAC,aAAa,CAAC;QAAC,MAAM,CAAC,UAAU,GAAG,IAAI,GAAG,KAAK,CAAC;IAE7C,IAAA,yBAAI,CAAmB;IAE/B,EAAE,CAAC,CAAC,CAAC,IAAI,IAAI,CAAC,kBAAU,CAAC,aAAa,CAAC,CAAC;QAAC,MAAM,CAAC,UAAU,GAAG,IAAI,GAAG,KAAK,CAAC;IAElE,IAAA,uCAAW,EAAE,+BAAO,EAAE,yBAAI,EAAE,6CAAc,CAAmB;IAErE,EAAE,CAAC,CAAC,cAAc,CAAC,CAAC,CAAC;QACX,IAAA,2BAAS,EAAE,iBAAI,CAAW;QAClC,aAAa,CAAC,SAAS,GAAG,SAAS,CAAC;QACpC,aAAa,CAAC,IAAI,GAAG,IAAI,CAAC;IAC5B,CAAC;IAED,MAAM,CAAC,aAAa,CAAC,SAAS,EAAE,CAAC;AACnC,CAAC,CAAC"} \ No newline at end of file diff --git a/package.json b/package.json index 79be9b1..3bdf4c0 100644 --- a/package.json +++ b/package.json @@ -27,7 +27,8 @@ "homepage": "https://github.com/thebigredgeek/apollo-errors#readme", "dependencies": { "assert": "^1.4.1", - "extendable-error": "^0.1.5" + "extendable-error": "^0.1.5", + "install": "^0.10.1" }, "devDependencies": { "babel-cli": "^6.18.0", diff --git a/src/index.ts b/src/index.ts index 1702589..aeaa377 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,6 +1,5 @@ import * as assert from 'assert'; import ExtendableError from 'extendable-error'; - const isString = d => Object.prototype.toString.call(d) === '[object String]'; const isObject = d => Object.prototype.toString.call(d) === '[object Object]'; interface ErrorConfig { @@ -9,7 +8,6 @@ interface ErrorConfig { data: any, options: any, } - class ApolloError extends ExtendableError { name: string; message: string; @@ -19,12 +17,12 @@ class ApolloError extends ExtendableError { locations: any; _showLocations: any; constructor (name, config: ErrorConfig) { - const t = (config && config.time_thrown) || (new Date()).toISOString(); - const d = (config && config.data || {}) - const m = (config && config.message) || ''; - const opts = ((config && config.options) || {}) - - super(m); + super((config && config.message) || ''); + const t = (arguments[2] && arguments[2].time_thrown) || (new Date()).toISOString(); + const m = (arguments[2] && arguments[2].message) || ''; + const configData = (arguments[2] && arguments[2].data) || {}; + const d = {...this.data, ...configData} + const opts = ((arguments[2] && arguments[2].options) || {}) this.name = name; this.message = m; @@ -43,12 +41,10 @@ class ApolloError extends ExtendableError { path, locations }; - if (_showLocations) { error.locations = locations; error.path = path; } - return error; } } @@ -56,7 +52,6 @@ class ApolloError extends ExtendableError { export const isInstance = e => e instanceof ApolloError; export const createError = (name, config: ErrorConfig) => { - console.log('config', config); assert(isObject(config), 'createError requires a config object as the second parameter'); assert(isString(config.message), 'createError requires a "message" property on the config object passed as the second parameter'); const e = ApolloError.bind(null, name, config); diff --git a/test/spec.js b/test/spec.js index 27b7525..48dfee5 100644 --- a/test/spec.js +++ b/test/spec.js @@ -15,27 +15,28 @@ describe('createError', () => { }, options: { showLocations: false, - showPath: true, + showPath: false, }, }); const iso = new Date().toISOString(); - const e = new FooError({ message: 'A foo 2.0 error has occurred', data: { + hello: 'world', foo: 'bar' }, options: { showLocations: true, - showPath: false, + showPath: true, }, }); - const { message, name, time_thrown, data } = e.serialize(); + const { message, name, time_thrown, data } = e.serialize(); expect(message).to.equal('A foo 2.0 error has occurred'); expect(name).to.equal('FooError'); expect(time_thrown).to.equal(e.time_thrown); expect(data).to.eql({ + hello: 'world', foo: 'bar' }); }); @@ -86,7 +87,6 @@ describe('formatError', () => { oh: 'shit' } }); - const s = formatError({ originalError: e }, false); From 5665a6afe51d579a4d55dc9c482c8188d566ca81 Mon Sep 17 00:00:00 2001 From: lakhansamani Date: Fri, 22 Sep 2017 10:26:18 +0530 Subject: [PATCH 16/57] * Removes build script from package.json * Adds build script in make file * Removes un-used modules from package.json * Changes type of time_thrown and _showLocation * Gives default type as string to name parameter in constructor and createError * Removes unsued configurations from tsconfig --- Makefile | 2 +- dist/index.js | 3 ++- dist/index.js.map | 2 +- package.json | 9 +++------ src/index.ts | 17 +++++++++++------ test/spec.js | 4 ++-- tsconfig.json | 2 -- 7 files changed, 20 insertions(+), 19 deletions(-) diff --git a/Makefile b/Makefile index e6404d5..8b3638a 100644 --- a/Makefile +++ b/Makefile @@ -13,7 +13,7 @@ endif .FORCE: all: clean - npm run build + tsc clean: .FORCE rimraf npm-debug.log dist diff --git a/dist/index.js b/dist/index.js index 3122edf..12bcca6 100644 --- a/dist/index.js +++ b/dist/index.js @@ -25,7 +25,8 @@ var isObject = function (d) { return Object.prototype.toString.call(d) === '[obj var ApolloError = /** @class */ (function (_super) { __extends(ApolloError, _super); function ApolloError(name, config) { - var _this = _super.call(this, (config && config.message) || '') || this; + var _this = _super.call(this, (arguments[2] && arguments[2].message) || '') || this; + _this._showLocations = false; var t = (arguments[2] && arguments[2].time_thrown) || (new Date()).toISOString(); var m = (arguments[2] && arguments[2].message) || ''; var configData = (arguments[2] && arguments[2].data) || {}; diff --git a/dist/index.js.map b/dist/index.js.map index b0749a6..529bd5f 100644 --- a/dist/index.js.map +++ b/dist/index.js.map @@ -1 +1 @@ -{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;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--git a/package.json b/package.json index 3bdf4c0..eb3a19f 100644 --- a/package.json +++ b/package.json @@ -4,8 +4,7 @@ "description": "Machine-readable custom errors for Apollostack's GraphQL server", "main": "dist/index.js", "scripts": { - "test": "make test", - "build": "tsc" + "test": "make test" }, "repository": { "type": "git", @@ -27,8 +26,7 @@ "homepage": "https://github.com/thebigredgeek/apollo-errors#readme", "dependencies": { "assert": "^1.4.1", - "extendable-error": "^0.1.5", - "install": "^0.10.1" + "extendable-error": "^0.1.5" }, "devDependencies": { "babel-cli": "^6.18.0", @@ -41,7 +39,6 @@ "eslint-plugin-babel": "^3.3.0", "mocha": "^3.1.2", "rimraf": "^2.5.4", - "typescript": "^2.5.2", - "typings": "^2.1.1" + "typescript": "^2.5.2" } } diff --git a/src/index.ts b/src/index.ts index aeaa377..a2aec2f 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,23 +1,28 @@ import * as assert from 'assert'; import ExtendableError from 'extendable-error'; + const isString = d => Object.prototype.toString.call(d) === '[object String]'; const isObject = d => Object.prototype.toString.call(d) === '[object Object]'; + interface ErrorConfig { message: string; - time_thrown: any; + time_thrown: string; data: any, options: any, } + class ApolloError extends ExtendableError { name: string; message: string; - time_thrown: any; + time_thrown: string; data: any; path: any; locations: any; - _showLocations: any; - constructor (name, config: ErrorConfig) { - super((config && config.message) || ''); + _showLocations: boolean=false; + + constructor (name:string, config: ErrorConfig) { + super((arguments[2] && arguments[2].message) || ''); + const t = (arguments[2] && arguments[2].time_thrown) || (new Date()).toISOString(); const m = (arguments[2] && arguments[2].message) || ''; const configData = (arguments[2] && arguments[2].data) || {}; @@ -51,7 +56,7 @@ class ApolloError extends ExtendableError { export const isInstance = e => e instanceof ApolloError; -export const createError = (name, config: ErrorConfig) => { +export const createError = (name:string, config: ErrorConfig) => { assert(isObject(config), 'createError requires a config object as the second parameter'); assert(isString(config.message), 'createError requires a "message" property on the config object passed as the second parameter'); const e = ApolloError.bind(null, name, config); diff --git a/test/spec.js b/test/spec.js index 48dfee5..9036ac4 100644 --- a/test/spec.js +++ b/test/spec.js @@ -15,7 +15,7 @@ describe('createError', () => { }, options: { showLocations: false, - showPath: false, + showPath: true, }, }); const iso = new Date().toISOString(); @@ -27,7 +27,7 @@ describe('createError', () => { }, options: { showLocations: true, - showPath: true, + showPath: false, }, }); diff --git a/tsconfig.json b/tsconfig.json index c1e6bf1..f0b096c 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -4,8 +4,6 @@ "module": "commonjs", "moduleResolution": "node", "sourceMap": true, - "emitDecoratorMetadata": true, - "experimentalDecorators": true, "removeComments": false, "noImplicitAny": false, "allowJs": true, From 3450ef252f456185ab443ce8042ae096cc7a3b46 Mon Sep 17 00:00:00 2001 From: Daniel Khoroshko Date: Tue, 24 Oct 2017 21:15:47 +0300 Subject: [PATCH 17/57] added ts types --- dist/index.d.ts | 29 ++++++++++ dist/index.js | 4 +- dist/index.js.map | 2 +- src/index.ts | 135 +++++++++++++++++++++++++--------------------- tsconfig.json | 6 ++- 5 files changed, 109 insertions(+), 67 deletions(-) create mode 100644 dist/index.d.ts diff --git a/dist/index.d.ts b/dist/index.d.ts new file mode 100644 index 0000000..dd1ddbd --- /dev/null +++ b/dist/index.d.ts @@ -0,0 +1,29 @@ +import ExtendableError from 'extendable-error'; +export interface ErrorConfig { + message: string; + time_thrown: string; + data: any; + options: any; +} +export interface ErrorInfo { + message: string; + name: string; + time_thrown: string; + data: string; + path: string; + locations: string; +} +export declare class ApolloError extends ExtendableError { + name: string; + message: string; + time_thrown: string; + data: any; + path: any; + locations: any; + _showLocations: boolean; + constructor(name: string, config: ErrorConfig); + serialize(): ErrorInfo; +} +export declare const isInstance: (e: any) => boolean; +export declare const createError: (name: string, config: ErrorConfig) => ApolloError; +export declare const formatError: (error: any, returnNull?: boolean) => ErrorInfo; diff --git a/dist/index.js b/dist/index.js index 12bcca6..ddcd3e6 100644 --- a/dist/index.js +++ b/dist/index.js @@ -57,12 +57,12 @@ var ApolloError = /** @class */ (function (_super) { }; return ApolloError; }(extendable_error_1.default)); +exports.ApolloError = ApolloError; exports.isInstance = function (e) { return e instanceof ApolloError; }; exports.createError = function (name, config) { assert(isObject(config), 'createError requires a config object as the second parameter'); assert(isString(config.message), 'createError requires a "message" property on the config object passed as the second parameter'); - var e = ApolloError.bind(null, name, config); - return e; + return new ApolloError(name, config); }; exports.formatError = function (error, returnNull) { if (returnNull === void 0) { returnNull = false; } diff --git a/dist/index.js.map b/dist/index.js.map index 529bd5f..ef2ed71 100644 --- a/dist/index.js.map +++ b/dist/index.js.map @@ -1 +1 @@ -{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA,+BAAiC;AACjC,qDAA+C;AAE/C,IAAM,QAAQ,GAAG,UAAA,CAAC,IAAI,OAAA,MAAM,CAAC,SAAS,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC,CAAC,KAAK,iBAAiB,EAAvD,CAAuD,CAAC;AAC9E,IAAM,QAAQ,GAAG,UAAA,CAAC,IAAI,OAAA,MAAM,CAAC,SAAS,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC,CAAC,KAAK,iBAAiB,EAAvD,CAAuD,CAAC;AAS9E;IAA0B,+BAAe;IASvC,qBAAa,IAAW,EAAE,MAAmB;QAA7C,YACE,kBAAM,CAAC,SAAS,CAAC,CAAC,CAAC,IAAI,SAAS,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,IAAI,EAAE,CAAC,SAapD;QAhBD,oBAAc,GAAU,KAAK,CAAC;QAK5B,IAAM,CAAC,GAAG,CAAC,SAAS,CAAC,CAAC,CAAC,IAAI,SAAS,CAAC,CAAC,CAAC,CAAC,WAAW,CAAC,IAAI,CAAC,IAAI,IAAI,EAAE,CAAC,CAAC,WAAW,EAAE,CAAC;QACnF,IAAM,CAAC,GAAG,CAAC,SAAS,CAAC,CAAC,CAAC,IAAI,SAAS,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,IAA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B;IAE/B,EAAE,CAAC,CAAC,CAAC,IAAI,IAAI,CAAC,kBAAU,CAAC,aAAa,CAAC,CAAC;QAAC,MAAM,CAAC,UAAU,GAAG,IAAI,GAAG,KAAK,CAAC;IAElE,IAAA,uCAAW,EAAE,+BAAO,EAAE,yBAAI,EAAE,6CAAc,CAAmB;IAErE,EAAE,CAAC,CAAC,cAAc,CAAC,CAAC,CAAC;QACZ,IAAA,2BAAS,EAAE,iBAAI,CAAW;QAClC,aAAa,CAAC,SAAS,GAAG,SAAS,CAAC;QACpC,aAAa,CAAC,IAAI,GAAG,IAAI,CAAC;IAC3B,CAAC;IAED,MAAM,CAAC,aAAa,CAAC,SAAS,EAAE,CAAC;AAClC,CAAC,CAAC"} \ No newline at end of file diff --git a/src/index.ts b/src/index.ts index a2aec2f..b340f6f 100644 --- a/src/index.ts +++ b/src/index.ts @@ -4,81 +4,92 @@ import ExtendableError from 'extendable-error'; const isString = d => Object.prototype.toString.call(d) === '[object String]'; const isObject = d => Object.prototype.toString.call(d) === '[object Object]'; -interface ErrorConfig { - message: string; - time_thrown: string; - data: any, - options: any, +export interface ErrorConfig { + message: string; + time_thrown: string; + data: any, + options: any, } -class ApolloError extends ExtendableError { - name: string; - message: string; - time_thrown: string; - data: any; - path: any; - locations: any; - _showLocations: boolean=false; - - constructor (name:string, config: ErrorConfig) { - super((arguments[2] && arguments[2].message) || ''); - - const t = (arguments[2] && arguments[2].time_thrown) || (new Date()).toISOString(); - const m = (arguments[2] && arguments[2].message) || ''; - const configData = (arguments[2] && arguments[2].data) || {}; - const d = {...this.data, ...configData} - const opts = ((arguments[2] && arguments[2].options) || {}) - - this.name = name; - this.message = m; - this.time_thrown = t; - this.data = d; - this._showLocations = !!opts.showLocations; - } - serialize () { - const { name, message, time_thrown, data, _showLocations, path, locations } = this; - - let error = { - message, - name, - time_thrown, - data, - path, - locations - }; - if (_showLocations) { - error.locations = locations; - error.path = path; - } - return error; - } +export interface ErrorInfo { + message: string; + name: string; + time_thrown: string; + data: string; + path: string; + locations: string; +} + +export class ApolloError extends ExtendableError { + name: string; + message: string; + time_thrown: string; + data: any; + path: any; + locations: any; + _showLocations: boolean=false; + + constructor (name:string, config: ErrorConfig) { + super((arguments[2] && arguments[2].message) || ''); + + const t = (arguments[2] && arguments[2].time_thrown) || (new Date()).toISOString(); + const m = (arguments[2] && arguments[2].message) || ''; + const configData = (arguments[2] && arguments[2].data) || {}; + const d = {...this.data, ...configData} + const opts = ((arguments[2] && arguments[2].options) || {}) + + this.name = name; + this.message = m; + this.time_thrown = t; + this.data = d; + this._showLocations = !!opts.showLocations; + } + + serialize (): ErrorInfo { + const { name, message, time_thrown, data, _showLocations, path, locations } = this; + + let error: ErrorInfo = { + message, + name, + time_thrown, + data, + path, + locations + }; + + if (_showLocations) { + error.locations = locations; + error.path = path; + } + + return error; + } } export const isInstance = e => e instanceof ApolloError; export const createError = (name:string, config: ErrorConfig) => { - assert(isObject(config), 'createError requires a config object as the second parameter'); - assert(isString(config.message), 'createError requires a "message" property on the config object passed as the second parameter'); - const e = ApolloError.bind(null, name, config); - return e; + assert(isObject(config), 'createError requires a config object as the second parameter'); + assert(isString(config.message), 'createError requires a "message" property on the config object passed as the second parameter'); + return new ApolloError(name, config); }; -export const formatError = (error, returnNull = false) => { - const originalError = error ? error.originalError || error : null; +export const formatError = (error, returnNull = false): ErrorInfo => { + const originalError = error ? error.originalError || error : null; - if (!originalError) return returnNull ? null : error; + if (!originalError) return returnNull ? null : error; - const { name } = originalError; + const { name } = originalError; - if (!name || !isInstance(originalError)) return returnNull ? null : error; + if (!name || !isInstance(originalError)) return returnNull ? null : error; - const { time_thrown, message, data, _showLocations } = originalError; + const { time_thrown, message, data, _showLocations } = originalError; - if (_showLocations) { - const { locations, path } = error; - originalError.locations = locations; - originalError.path = path; - } + if (_showLocations) { + const { locations, path } = error; + originalError.locations = locations; + originalError.path = path; + } - return originalError.serialize(); + return originalError.serialize(); }; diff --git a/tsconfig.json b/tsconfig.json index f0b096c..bd7c8da 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -6,8 +6,10 @@ "sourceMap": true, "removeComments": false, "noImplicitAny": false, - "allowJs": true, - "outDir": "./dist" + // "allowJs": true, + "outDir": "./dist", + // "emitDecoratorMetadata": true, + "declaration": true }, "include": [ "./src/**/*" From 13c29c97330ac90f066e0a2f03826a825ba05d96 Mon Sep 17 00:00:00 2001 From: Daniel Khoroshko Date: Tue, 24 Oct 2017 21:19:45 +0300 Subject: [PATCH 18/57] package.json typings update --- package.json | 85 ++++++++++++++++++++++++++-------------------------- 1 file changed, 43 insertions(+), 42 deletions(-) diff --git a/package.json b/package.json index eb3a19f..93c7821 100644 --- a/package.json +++ b/package.json @@ -1,44 +1,45 @@ { - "name": "apollo-errors", - "version": "1.5.1", - "description": "Machine-readable custom errors for Apollostack's GraphQL server", - "main": "dist/index.js", - "scripts": { - "test": "make test" - }, - "repository": { - "type": "git", - "url": "git+https://github.com/thebigredgeek/apollo-errors.git" - }, - "keywords": [ - "apollostack", - "graphql", - "apollo-server", - "apollo-client", - "error", - "api" - ], - "author": "Andrew E. Rhyne ", - "license": "MIT", - "bugs": { - "url": "https://github.com/thebigredgeek/apollo-errors/issues" - }, - "homepage": "https://github.com/thebigredgeek/apollo-errors#readme", - "dependencies": { - "assert": "^1.4.1", - "extendable-error": "^0.1.5" - }, - "devDependencies": { - "babel-cli": "^6.18.0", - "babel-core": "^6.17.0", - "babel-eslint": "^7.0.0", - "babel-preset-es2015": "^6.16.0", - "babel-register": "^6.18.0", - "chai": "^3.5.0", - "eslint": "^3.8.1", - "eslint-plugin-babel": "^3.3.0", - "mocha": "^3.1.2", - "rimraf": "^2.5.4", - "typescript": "^2.5.2" - } + "name": "apollo-errors", + "version": "1.5.1", + "description": "Machine-readable custom errors for Apollostack's GraphQL server", + "main": "dist/index.js", + "scripts": { + "test": "make test" + }, + "repository": { + "type": "git", + "url": "git+https://github.com/thebigredgeek/apollo-errors.git" + }, + "keywords": [ + "apollostack", + "graphql", + "apollo-server", + "apollo-client", + "error", + "api" + ], + "author": "Andrew E. Rhyne ", + "license": "MIT", + "bugs": { + "url": "https://github.com/thebigredgeek/apollo-errors/issues" + }, + "homepage": "https://github.com/thebigredgeek/apollo-errors#readme", + "dependencies": { + "assert": "^1.4.1", + "extendable-error": "^0.1.5" + }, + "devDependencies": { + "babel-cli": "^6.18.0", + "babel-core": "^6.17.0", + "babel-eslint": "^7.0.0", + "babel-preset-es2015": "^6.16.0", + "babel-register": "^6.18.0", + "chai": "^3.5.0", + "eslint": "^3.8.1", + "eslint-plugin-babel": "^3.3.0", + "mocha": "^3.1.2", + "rimraf": "^2.5.4", + "typescript": "^2.5.2" + }, + "typings": "dist/index.d.ts" } From 6bb3e2923f9d22d8ba8845c6015f6276de8b46ed Mon Sep 17 00:00:00 2001 From: Daniel Khoroshko Date: Tue, 24 Oct 2017 21:26:49 +0300 Subject: [PATCH 19/57] updated ErrorConfig interface --- dist/index.d.ts | 6 +++--- package.json | 2 +- src/index.ts | 6 +++--- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/dist/index.d.ts b/dist/index.d.ts index dd1ddbd..a072147 100644 --- a/dist/index.d.ts +++ b/dist/index.d.ts @@ -1,9 +1,9 @@ import ExtendableError from 'extendable-error'; export interface ErrorConfig { message: string; - time_thrown: string; - data: any; - options: any; + time_thrown?: string; + data?: any; + options?: any; } export interface ErrorInfo { message: string; diff --git a/package.json b/package.json index 93c7821..6ba936f 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "apollo-errors", - "version": "1.5.1", + "version": "1.6.1", "description": "Machine-readable custom errors for Apollostack's GraphQL server", "main": "dist/index.js", "scripts": { diff --git a/src/index.ts b/src/index.ts index b340f6f..a1e6002 100644 --- a/src/index.ts +++ b/src/index.ts @@ -6,9 +6,9 @@ const isObject = d => Object.prototype.toString.call(d) === '[object Object]'; export interface ErrorConfig { message: string; - time_thrown: string; - data: any, - options: any, + time_thrown?: string; + data?: any, + options?: any, } export interface ErrorInfo { From 18b8dd990d302b2f8cef0ca9bf38e3dee3acc033 Mon Sep 17 00:00:00 2001 From: Daniel Khoroshko Date: Tue, 24 Oct 2017 21:29:36 +0300 Subject: [PATCH 20/57] updated ErrorConfig interface --- src/index.ts | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/index.ts b/src/index.ts index a1e6002..e373c77 100644 --- a/src/index.ts +++ b/src/index.ts @@ -7,8 +7,11 @@ const isObject = d => Object.prototype.toString.call(d) === '[object Object]'; export interface ErrorConfig { message: string; time_thrown?: string; - data?: any, - options?: any, + data?: any; + options?: { + showPath?: boolean; + showLocations?: boolean; + }, } export interface ErrorInfo { From 701972f9f879e32936e64d25a87289a6beba14c9 Mon Sep 17 00:00:00 2001 From: Daniel Khoroshko Date: Tue, 24 Oct 2017 21:29:48 +0300 Subject: [PATCH 21/57] version bump --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 6ba936f..a147fdf 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "apollo-errors", - "version": "1.6.1", + "version": "1.6.2", "description": "Machine-readable custom errors for Apollostack's GraphQL server", "main": "dist/index.js", "scripts": { From cb7bcf984220dcead4bdbbf36ad98b66969943d8 Mon Sep 17 00:00:00 2001 From: Daniel Khoroshko Date: Tue, 24 Oct 2017 21:30:29 +0300 Subject: [PATCH 22/57] build --- dist/index.d.ts | 5 ++++- dist/index.js.map | 2 +- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/dist/index.d.ts b/dist/index.d.ts index a072147..84e4410 100644 --- a/dist/index.d.ts +++ b/dist/index.d.ts @@ -3,7 +3,10 @@ export interface ErrorConfig { message: string; time_thrown?: string; data?: any; - options?: any; + options?: { + showPath?: boolean; + showLocations?: boolean; + }; } export interface ErrorInfo { message: string; diff --git a/dist/index.js.map b/dist/index.js.map index ef2ed71..a87c30f 100644 --- a/dist/index.js.map +++ b/dist/index.js.map @@ -1 +1 @@ -{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IAED,MAAM,CAAC,aAAa,CAAC,SAAS,EAAE,CAAC;AAClC,CAAC,CAAC"} \ No newline at end of file From 431c15f850b252d79ee0b72ffd704d4a9a4342ca Mon Sep 17 00:00:00 2001 From: Daniel Khoroshko Date: Tue, 24 Oct 2017 21:36:47 +0300 Subject: [PATCH 23/57] cleaned up tsconfig --- package.json | 2 +- tsconfig.json | 2 -- 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/package.json b/package.json index a147fdf..01a1fbe 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "apollo-errors", - "version": "1.6.2", + "version": "1.6.3", "description": "Machine-readable custom errors for Apollostack's GraphQL server", "main": "dist/index.js", "scripts": { diff --git a/tsconfig.json b/tsconfig.json index bd7c8da..a84597b 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -6,9 +6,7 @@ "sourceMap": true, "removeComments": false, "noImplicitAny": false, - // "allowJs": true, "outDir": "./dist", - // "emitDecoratorMetadata": true, "declaration": true }, "include": [ From 1ea7a07f6032bed1e2550d85eb71081db9897df7 Mon Sep 17 00:00:00 2001 From: Daniel Khoroshko Date: Tue, 24 Oct 2017 21:42:13 +0300 Subject: [PATCH 24/57] repaired indentation --- .gitignore | 4 ++ src/index.ts | 142 +++++++++++++++++++++++++-------------------------- 2 files changed, 75 insertions(+), 71 deletions(-) diff --git a/.gitignore b/.gitignore index dd71061..9c6fc03 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,7 @@ +# intellij idea +.idea + + # Logs logs *.log diff --git a/src/index.ts b/src/index.ts index e373c77..40e3d5d 100644 --- a/src/index.ts +++ b/src/index.ts @@ -5,94 +5,94 @@ const isString = d => Object.prototype.toString.call(d) === '[object String]'; const isObject = d => Object.prototype.toString.call(d) === '[object Object]'; export interface ErrorConfig { - message: string; - time_thrown?: string; - data?: any; - options?: { - showPath?: boolean; - showLocations?: boolean; - }, + message: string; + time_thrown?: string; + data?: any; + options?: { + showPath?: boolean; + showLocations?: boolean; + }; } export interface ErrorInfo { - message: string; - name: string; - time_thrown: string; - data: string; - path: string; - locations: string; + message: string; + name: string; + time_thrown: string; + data: string; + path: string; + locations: string; } export class ApolloError extends ExtendableError { - name: string; - message: string; - time_thrown: string; - data: any; - path: any; - locations: any; - _showLocations: boolean=false; - - constructor (name:string, config: ErrorConfig) { - super((arguments[2] && arguments[2].message) || ''); - - const t = (arguments[2] && arguments[2].time_thrown) || (new Date()).toISOString(); - const m = (arguments[2] && arguments[2].message) || ''; - const configData = (arguments[2] && arguments[2].data) || {}; - const d = {...this.data, ...configData} - const opts = ((arguments[2] && arguments[2].options) || {}) - - this.name = name; - this.message = m; - this.time_thrown = t; - this.data = d; - this._showLocations = !!opts.showLocations; - } - - serialize (): ErrorInfo { - const { name, message, time_thrown, data, _showLocations, path, locations } = this; - - let error: ErrorInfo = { - message, - name, - time_thrown, - data, - path, - locations - }; - - if (_showLocations) { - error.locations = locations; - error.path = path; - } - - return error; - } + name: string; + message: string; + time_thrown: string; + data: any; + path: any; + locations: any; + _showLocations: boolean = false; + + constructor(name: string, config: ErrorConfig) { + super((arguments[2] && arguments[2].message) || ''); + + const t = (arguments[2] && arguments[2].time_thrown) || (new Date()).toISOString(); + const m = (arguments[2] && arguments[2].message) || ''; + const configData = (arguments[2] && arguments[2].data) || {}; + const d = { ...this.data, ...configData } + const opts = ((arguments[2] && arguments[2].options) || {}) + + this.name = name; + this.message = m; + this.time_thrown = t; + this.data = d; + this._showLocations = !!opts.showLocations; + } + + serialize(): ErrorInfo { + const { name, message, time_thrown, data, _showLocations, path, locations } = this; + + let error: ErrorInfo = { + message, + name, + time_thrown, + data, + path, + locations + }; + + if (_showLocations) { + error.locations = locations; + error.path = path; + } + + return error; + } } export const isInstance = e => e instanceof ApolloError; -export const createError = (name:string, config: ErrorConfig) => { - assert(isObject(config), 'createError requires a config object as the second parameter'); - assert(isString(config.message), 'createError requires a "message" property on the config object passed as the second parameter'); - return new ApolloError(name, config); +export const createError = (name: string, config: ErrorConfig) => { + assert(isObject(config), 'createError requires a config object as the second parameter'); + assert(isString(config.message), 'createError requires a "message" property on the config object passed as the second parameter'); + return new ApolloError(name, config); }; export const formatError = (error, returnNull = false): ErrorInfo => { - const originalError = error ? error.originalError || error : null; + const originalError = error ? error.originalError || error : null; - if (!originalError) return returnNull ? null : error; + if (!originalError) return returnNull ? null : error; - const { name } = originalError; + const { name } = originalError; - if (!name || !isInstance(originalError)) return returnNull ? null : error; + if (!name || !isInstance(originalError)) return returnNull ? null : error; - const { time_thrown, message, data, _showLocations } = originalError; + const { time_thrown, message, data, _showLocations } = originalError; - if (_showLocations) { - const { locations, path } = error; - originalError.locations = locations; - originalError.path = path; - } + if (_showLocations) { + const { locations, path } = error; + originalError.locations = locations; + originalError.path = path; + } - return originalError.serialize(); + return originalError.serialize(); }; From a354487764f7684ea52c23b88809a93e32efc289 Mon Sep 17 00:00:00 2001 From: Daniel Khoroshko Date: Thu, 26 Oct 2017 16:27:21 +0300 Subject: [PATCH 25/57] ErrorInfo optional fields --- src/index.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/index.ts b/src/index.ts index 40e3d5d..250b109 100644 --- a/src/index.ts +++ b/src/index.ts @@ -18,9 +18,9 @@ export interface ErrorInfo { message: string; name: string; time_thrown: string; - data: string; - path: string; - locations: string; + data?: string; + path?: string; + locations?: string; } export class ApolloError extends ExtendableError { From d84ea3fb5da7909c8d7f0a87350f506f2e91cd38 Mon Sep 17 00:00:00 2001 From: Daniel Khoroshko Date: Thu, 26 Oct 2017 16:29:44 +0300 Subject: [PATCH 26/57] ErrorInfo field types --- src/index.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/index.ts b/src/index.ts index 250b109..6a24e20 100644 --- a/src/index.ts +++ b/src/index.ts @@ -18,9 +18,9 @@ export interface ErrorInfo { message: string; name: string; time_thrown: string; - data?: string; + data?: {}; path?: string; - locations?: string; + locations?: any; } export class ApolloError extends ExtendableError { From 0c4a6e13d954d48c0a8013413ca045e8656e7229 Mon Sep 17 00:00:00 2001 From: "Andrew E. Rhyne" Date: Thu, 22 Feb 2018 17:32:13 -0800 Subject: [PATCH 27/57] fixes --- dist/index.d.ts | 9 +++++---- dist/index.js | 14 ++++++++++---- dist/index.js.map | 2 +- src/index.ts | 16 ++++++++++++---- 4 files changed, 28 insertions(+), 13 deletions(-) diff --git a/dist/index.d.ts b/dist/index.d.ts index 84e4410..79117f7 100644 --- a/dist/index.d.ts +++ b/dist/index.d.ts @@ -12,9 +12,9 @@ export interface ErrorInfo { message: string; name: string; time_thrown: string; - data: string; - path: string; - locations: string; + data?: {}; + path?: string; + locations?: any; } export declare class ApolloError extends ExtendableError { name: string; @@ -24,9 +24,10 @@ export declare class ApolloError extends ExtendableError { path: any; locations: any; _showLocations: boolean; + _showPath: boolean; constructor(name: string, config: ErrorConfig); serialize(): ErrorInfo; } export declare const isInstance: (e: any) => boolean; -export declare const createError: (name: string, config: ErrorConfig) => ApolloError; +export declare const createError: (name: string, config: ErrorConfig) => any; export declare const formatError: (error: any, returnNull?: boolean) => ErrorInfo; diff --git a/dist/index.js b/dist/index.js index ddcd3e6..1598708 100644 --- a/dist/index.js +++ b/dist/index.js @@ -27,6 +27,7 @@ var ApolloError = /** @class */ (function (_super) { function ApolloError(name, config) { var _this = _super.call(this, (arguments[2] && arguments[2].message) || '') || this; _this._showLocations = false; + _this._showPath = false; var t = (arguments[2] && arguments[2].time_thrown) || (new Date()).toISOString(); var m = (arguments[2] && arguments[2].message) || ''; var configData = (arguments[2] && arguments[2].data) || {}; @@ -37,10 +38,11 @@ var ApolloError = /** @class */ (function (_super) { _this.time_thrown = t; _this.data = d; _this._showLocations = !!opts.showLocations; + _this._showPath = !!opts.showPath; return _this; } ApolloError.prototype.serialize = function () { - var _a = this, name = _a.name, message = _a.message, time_thrown = _a.time_thrown, data = _a.data, _showLocations = _a._showLocations, path = _a.path, locations = _a.locations; + var _a = this, name = _a.name, message = _a.message, time_thrown = _a.time_thrown, data = _a.data, _showLocations = _a._showLocations, _showPath = _a._showPath, path = _a.path, locations = _a.locations; var error = { message: message, name: name, @@ -51,6 +53,8 @@ var ApolloError = /** @class */ (function (_super) { }; if (_showLocations) { error.locations = locations; + } + if (_showPath) { error.path = path; } return error; @@ -62,7 +66,7 @@ exports.isInstance = function (e) { return e instanceof ApolloError; }; exports.createError = function (name, config) { assert(isObject(config), 'createError requires a config object as the second parameter'); assert(isString(config.message), 'createError requires a "message" property on the config object passed as the second parameter'); - return new ApolloError(name, config); + return ApolloError.bind(null, name, config); }; exports.formatError = function (error, returnNull) { if (returnNull === void 0) { returnNull = false; } @@ -72,10 +76,12 @@ exports.formatError = function (error, returnNull) { var name = originalError.name; if (!name || !exports.isInstance(originalError)) return returnNull ? null : error; - var time_thrown = originalError.time_thrown, message = originalError.message, data = originalError.data, _showLocations = originalError._showLocations; + var time_thrown = originalError.time_thrown, message = originalError.message, data = originalError.data, _showLocations = originalError._showLocations, _showPath = originalError._showPath; + var locations = error.locations, path = error.path; if (_showLocations) { - var locations = error.locations, path = error.path; originalError.locations = locations; + } + if (_showPath) { originalError.path = path; } return originalError.serialize(); diff --git a/dist/index.js.map b/dist/index.js.map index a87c30f..d1908b6 100644 --- a/dist/index.js.map +++ b/dist/index.js.map @@ -1 +1 @@ -{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA,+BAAiC;AACjC,qDAA+C;AAE/C,IAAM,QAAQ,GAAG,UAAA,CAAC,IAAI,OAAA,MAAM,CAAC,SAAS,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC,CAAC,KAAK,iBAAiB,EAAvD,CAAuD,CAAC;AAC9E,IAAM,QAAQ,GAAG,UAAA,CAAC,IAAI,OAAA,MAAM,CAAC,SAAS,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC,CAAC,KAAK,iBAAiB,EAAvD,CAAuD,CAAC;AAqB9E;IAAiC,+BAAe;IAS/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/index.ts index 6a24e20..ba7b3c8 100644 --- a/src/index.ts +++ b/src/index.ts @@ -31,6 +31,7 @@ export class ApolloError extends ExtendableError { path: any; locations: any; _showLocations: boolean = false; + _showPath: boolean = false; constructor(name: string, config: ErrorConfig) { super((arguments[2] && arguments[2].message) || ''); @@ -46,10 +47,11 @@ export class ApolloError extends ExtendableError { this.time_thrown = t; this.data = d; this._showLocations = !!opts.showLocations; + this._showPath = !!opts.showPath; } serialize(): ErrorInfo { - const { name, message, time_thrown, data, _showLocations, path, locations } = this; + const { name, message, time_thrown, data, _showLocations, _showPath, path, locations } = this; let error: ErrorInfo = { message, @@ -62,6 +64,9 @@ export class ApolloError extends ExtendableError { if (_showLocations) { error.locations = locations; + } + + if (_showPath) { error.path = path; } @@ -74,7 +79,7 @@ export const isInstance = e => e instanceof ApolloError; export const createError = (name: string, config: ErrorConfig) => { assert(isObject(config), 'createError requires a config object as the second parameter'); assert(isString(config.message), 'createError requires a "message" property on the config object passed as the second parameter'); - return new ApolloError(name, config); + return ApolloError.bind(null, name, config); }; export const formatError = (error, returnNull = false): ErrorInfo => { @@ -86,11 +91,14 @@ export const formatError = (error, returnNull = false): ErrorInfo => { if (!name || !isInstance(originalError)) return returnNull ? null : error; - const { time_thrown, message, data, _showLocations } = originalError; + const { time_thrown, message, data, _showLocations, _showPath } = originalError; + const { locations, path } = error; if (_showLocations) { - const { locations, path } = error; originalError.locations = locations; + } + + if (_showPath) { originalError.path = path; } From df8ab0db1d479c82aa049b57a0ddf569b063a68d Mon Sep 17 00:00:00 2001 From: "Andrew E. Rhyne" Date: Thu, 22 Feb 2018 17:35:05 -0800 Subject: [PATCH 28/57] release 1.7.0 --- CHANGELOG.md | 7 +++++++ package.json | 2 +- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4a3b7a3..5920a17 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,4 +1,11 @@ +1.7.0 / 2018-02-22 +================== + + * Misc: Refactored in TypeScript (#19, #22, @iamdanthdev, @lakhansamani) + * Fix: Fix createError interface post-typescript refactor (@thebigredgeek) + * Fix: Fix showPath option to correctly toggle error path exposure regardless of showLocation state (@thebigredgeek) + 1.5.1 / 2017-09-07 ================== diff --git a/package.json b/package.json index 01a1fbe..b78e0b1 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "apollo-errors", - "version": "1.6.3", + "version": "1.7.0", "description": "Machine-readable custom errors for Apollostack's GraphQL server", "main": "dist/index.js", "scripts": { From 3cc1c3867514685000d66f63fd59696bb3aff800 Mon Sep 17 00:00:00 2001 From: "Andrew E. Rhyne" Date: Thu, 22 Feb 2018 17:48:16 -0800 Subject: [PATCH 29/57] less ambiguity around data type --- dist/index.d.ts | 6 +++--- dist/index.js.map | 2 +- src/index.ts | 11 ++++++----- 3 files changed, 10 insertions(+), 9 deletions(-) diff --git a/dist/index.d.ts b/dist/index.d.ts index 79117f7..6634488 100644 --- a/dist/index.d.ts +++ b/dist/index.d.ts @@ -2,7 +2,7 @@ import ExtendableError from 'extendable-error'; export interface ErrorConfig { message: string; time_thrown?: string; - data?: any; + data?: object; options?: { showPath?: boolean; showLocations?: boolean; @@ -12,7 +12,7 @@ export interface ErrorInfo { message: string; name: string; time_thrown: string; - data?: {}; + data?: object; path?: string; locations?: any; } @@ -20,7 +20,7 @@ export declare class ApolloError extends ExtendableError { name: string; message: string; time_thrown: string; - data: any; + data: object; path: any; locations: any; _showLocations: boolean; diff --git a/dist/index.js.map b/dist/index.js.map index d1908b6..923a414 100644 --- a/dist/index.js.map +++ b/dist/index.js.map @@ -1 +1 @@ -{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA,+BAAiC;AACjC,qDAA+C;AAE/C,IAAM,QAAQ,GAAG,UAAA,CAAC,IAAI,OAAA,MAAM,CAAC,SAAS,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC,CAAC,K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AI,IAAI,CAAC,kBAAU,CAAC,aAAa,CAAC,CAAC;QAAC,MAAM,CAAC,UAAU,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,KAAK,CAAC;IAElE,IAAA,uCAAW,EAAE,+BAAO,EAAE,yBAAI,EAAE,6CAAc,EAAE,mCAAS,CAAmB;IACxE,IAAA,2BAAS,EAAE,iBAAI,CAAW;IAElC,EAAE,CAAC,CAAC,cAAc,CAAC,CAAC,CAAC;QACnB,aAAa,CAAC,SAAS,GAAG,SAAS,CAAC;IACtC,CAAC;IAED,EAAE,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC;QACd,aAAa,CAAC,IAAI,GAAG,IAAI,CAAC;IAC5B,CAAC;IAED,MAAM,CAAC,aAAa,CAAC,SAAS,EAAE,CAAC;AACnC,CAAC,CAAC"} \ No newline at end of file diff --git a/src/index.ts b/src/index.ts index ba7b3c8..cb9d9d5 100644 --- a/src/index.ts +++ b/src/index.ts @@ -7,7 +7,7 @@ const isObject = d => Object.prototype.toString.call(d) === '[object Object]'; export interface ErrorConfig { message: string; time_thrown?: string; - data?: any; + data?: object; options?: { showPath?: boolean; showLocations?: boolean; @@ -18,7 +18,7 @@ export interface ErrorInfo { message: string; name: string; time_thrown: string; - data?: {}; + data?: object; path?: string; locations?: any; } @@ -27,7 +27,7 @@ export class ApolloError extends ExtendableError { name: string; message: string; time_thrown: string; - data: any; + data: object; path: any; locations: any; _showLocations: boolean = false; @@ -39,8 +39,9 @@ export class ApolloError extends ExtendableError { const t = (arguments[2] && arguments[2].time_thrown) || (new Date()).toISOString(); const m = (arguments[2] && arguments[2].message) || ''; const configData = (arguments[2] && arguments[2].data) || {}; - const d = { ...this.data, ...configData } - const opts = ((arguments[2] && arguments[2].options) || {}) + const d = { ...this.data, ...configData }; + const opts = ((arguments[2] && arguments[2].options) || {}); + this.name = name; this.message = m; From b7e881484020adbd63fd0a82949466b16a448a45 Mon Sep 17 00:00:00 2001 From: "Andrew E. Rhyne" Date: Thu, 22 Feb 2018 17:48:54 -0800 Subject: [PATCH 30/57] release 1.7.1 --- CHANGELOG.md | 5 +++++ package.json | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5920a17..ec7c2e5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,4 +1,9 @@ +1.7.1 / 2018-02-22 +================== + + * Fix: less ambiguity around data type (@thebigredgeek) + 1.7.0 / 2018-02-22 ================== diff --git a/package.json b/package.json index b78e0b1..d2bb1f8 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "apollo-errors", - "version": "1.7.0", + "version": "1.7.1", "description": "Machine-readable custom errors for Apollostack's GraphQL server", "main": "dist/index.js", "scripts": { From 11e98cc75e066a7aec94218d8c3cee112d4168a5 Mon Sep 17 00:00:00 2001 From: Luis Grases Date: Sat, 17 Mar 2018 14:29:34 -0600 Subject: [PATCH 31/57] Set error config properly. The constructor ApolloError is failing to get the config argument. It is trying to get it from the 3rd position of the arguments object: (arguments[2]). It should be accessing it from the 2nd position: (arguments[1]). --- src/index.ts | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/index.ts b/src/index.ts index cb9d9d5..6818d21 100644 --- a/src/index.ts +++ b/src/index.ts @@ -34,13 +34,13 @@ export class ApolloError extends ExtendableError { _showPath: boolean = false; constructor(name: string, config: ErrorConfig) { - super((arguments[2] && arguments[2].message) || ''); + super((arguments[1] && arguments[1].message) || ''); - const t = (arguments[2] && arguments[2].time_thrown) || (new Date()).toISOString(); - const m = (arguments[2] && arguments[2].message) || ''; - const configData = (arguments[2] && arguments[2].data) || {}; + const t = (arguments[1] && arguments[1].time_thrown) || (new Date()).toISOString(); + const m = (arguments[1] && arguments[1].message) || ''; + const configData = (arguments[1] && arguments[1].data) || {}; const d = { ...this.data, ...configData }; - const opts = ((arguments[2] && arguments[2].options) || {}); + const opts = ((arguments[1] && arguments[1].options) || {}); this.name = name; From c3d938ad9c36412218aead642c546eac108e444f Mon Sep 17 00:00:00 2001 From: Stan Chang Khin Boon Date: Tue, 27 Mar 2018 18:26:19 +0800 Subject: [PATCH 32/57] Make serialized error spec compliant Summary: An update recently in `facebook/graphql/spec/Section 7 -- Response.md` specify that GraphQL services may provide an additional entry to errors with key `extensions`. Although non-specified entries are not violations, they are still discouraged. This update try to follow through with the spec recommendation. --- src/index.ts | 18 +++++++++++------- test/spec.js | 2 +- 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/src/index.ts b/src/index.ts index cb9d9d5..31437ea 100644 --- a/src/index.ts +++ b/src/index.ts @@ -16,11 +16,13 @@ export interface ErrorConfig { export interface ErrorInfo { message: string; - name: string; - time_thrown: string; - data?: object; path?: string; locations?: any; + extensions?: { + name: string; + time_thrown: string; + data?: object; + }; } export class ApolloError extends ExtendableError { @@ -56,11 +58,13 @@ export class ApolloError extends ExtendableError { let error: ErrorInfo = { message, - name, - time_thrown, - data, path, - locations + locations, + extensions: { + name, + time_thrown, + data + } }; if (_showLocations) { diff --git a/test/spec.js b/test/spec.js index 9036ac4..f5932b0 100644 --- a/test/spec.js +++ b/test/spec.js @@ -31,7 +31,7 @@ describe('createError', () => { }, }); - const { message, name, time_thrown, data } = e.serialize(); + const { message, extensions: { name, time_thrown, data } } = e.serialize(); expect(message).to.equal('A foo 2.0 error has occurred'); expect(name).to.equal('FooError'); expect(time_thrown).to.equal(e.time_thrown); From bf393c083b585f8d0cba4a5eb436d8e09691a60f Mon Sep 17 00:00:00 2001 From: "Andrew E. Rhyne" Date: Tue, 27 Mar 2018 19:28:05 -0700 Subject: [PATCH 33/57] Revert "Set error config properly." --- src/index.ts | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/index.ts b/src/index.ts index 6818d21..cb9d9d5 100644 --- a/src/index.ts +++ b/src/index.ts @@ -34,13 +34,13 @@ export class ApolloError extends ExtendableError { _showPath: boolean = false; constructor(name: string, config: ErrorConfig) { - super((arguments[1] && arguments[1].message) || ''); + super((arguments[2] && arguments[2].message) || ''); - const t = (arguments[1] && arguments[1].time_thrown) || (new Date()).toISOString(); - const m = (arguments[1] && arguments[1].message) || ''; - const configData = (arguments[1] && arguments[1].data) || {}; + const t = (arguments[2] && arguments[2].time_thrown) || (new Date()).toISOString(); + const m = (arguments[2] && arguments[2].message) || ''; + const configData = (arguments[2] && arguments[2].data) || {}; const d = { ...this.data, ...configData }; - const opts = ((arguments[1] && arguments[1].options) || {}); + const opts = ((arguments[2] && arguments[2].options) || {}); this.name = name; From d57470daf6bcbd50a4380cfaead001e06297a179 Mon Sep 17 00:00:00 2001 From: "Andrew E. Rhyne" Date: Tue, 27 Mar 2018 19:32:55 -0700 Subject: [PATCH 34/57] updated code with a couple of comments and made ctorData more explicit --- dist/index.d.ts | 2 +- dist/index.js | 12 ++++++------ dist/index.js.map | 2 +- src/index.ts | 20 +++++++++++++------- 4 files changed, 21 insertions(+), 15 deletions(-) diff --git a/dist/index.d.ts b/dist/index.d.ts index 6634488..09cd18e 100644 --- a/dist/index.d.ts +++ b/dist/index.d.ts @@ -25,7 +25,7 @@ export declare class ApolloError extends ExtendableError { locations: any; _showLocations: boolean; _showPath: boolean; - constructor(name: string, config: ErrorConfig); + constructor(name: string, config: ErrorConfig, ctorData: any); serialize(): ErrorInfo; } export declare const isInstance: (e: any) => boolean; diff --git a/dist/index.js b/dist/index.js index 1598708..f0798fc 100644 --- a/dist/index.js +++ b/dist/index.js @@ -24,15 +24,15 @@ var isString = function (d) { return Object.prototype.toString.call(d) === '[obj var isObject = function (d) { return Object.prototype.toString.call(d) === '[object Object]'; }; var ApolloError = /** @class */ (function (_super) { __extends(ApolloError, _super); - function ApolloError(name, config) { - var _this = _super.call(this, (arguments[2] && arguments[2].message) || '') || this; + function ApolloError(name, config, ctorData) { + var _this = _super.call(this, (ctorData && ctorData.message) || '') || this; _this._showLocations = false; _this._showPath = false; - var t = (arguments[2] && arguments[2].time_thrown) || (new Date()).toISOString(); - var m = (arguments[2] && arguments[2].message) || ''; - var configData = (arguments[2] && arguments[2].data) || {}; + var t = (ctorData && ctorData.time_thrown) || (new Date()).toISOString(); + var m = (ctorData && ctorData.message) || ''; + var configData = (ctorData && ctorData.data) || {}; var d = __assign({}, _this.data, configData); - var opts = ((arguments[2] && arguments[2].options) || {}); + var opts = ((ctorData && ctorData.options) || {}); _this.name = name; _this.message = m; _this.time_thrown = t; diff --git a/dist/index.js.map b/dist/index.js.map index 923a414..a51ade4 100644 --- a/dist/index.js.map +++ b/dist/index.js.map @@ -1 +1 @@ -{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA,+BAAiC;AACjC,qDAA+C;AAE/C,IAAM,QAAQ,GAAG,UAAA,CAAC,IAAI,OAAA,MAAM,CAAC,SAAS,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC,CAAC,KAAK,iBAAiB,EAAvD,CAAuD,CAAC;AAC9E,IAAM,QAAQ,GAAG,UAAA,CAAC,IAAI,OAAA,MAAM,CAAC,SAAS,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC,CAAC,KAAK,iBAAiB,EAAvD,CAAuD,CAAC;AAqB9E;IAAiC,+BAAe;IAU9C,qBAAY,IAAY,EAAE,MAAmB;QAA7C,YACE,kBAAM,CAAC,SAAS,CAAC,CAAC,CAAC,IAAI,SAAS,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,IAAI,EAAE,CAAC,SAepD;QAnBD,oBAAc,GAAY,KAAK,CAAC;QAChC,eAAS,GAAY,KAAK,CAAC;QAKzB,IAAM,CAAC,GAAG,CAAC,SAAS,CAAC,CAAC,CAAC,IAAI,SAAS,CAAC,CAAC,CAAC,CAAC,WAAW,CAAC,IAAI,CAAC,IAAI,IAAI,EAAE,CAAC,CAAC,WAAW,EAAE,CAAC;QACnF,IAAM,CAAC,GAAG,CAAC,SAAS,CAAC,CAAC,CAAC,IAAI,SAAS,CAAC,CAAC,CAAC,C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E,MAAM,CAAC,CAAC;AAC9C,CAAC,CAAC;AAEW,QAAA,WAAW,GAAG,UAAC,KAAK,EAAE,UAAkB;IAAlB,2BAAA,EAAA,kBAAkB;IACnD,IAAM,aAAa,GAAG,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,aAAa,IAAI,KAAK,CAAC,CAAC,CAAC,IAAI,CAAC;IAElE,EAAE,CAAC,CAAC,CAAC,aAAa,CAAC;QAAC,MAAM,CAAC,UAAU,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,KAAK,CAAC;IAE7C,IAAA,yBAAI,CAAmB;IAE/B,EAAE,CAAC,CAAC,CAAC,IAAI,IAAI,CAAC,kBAAU,CAAC,aAAa,CAAC,CAAC;QAAC,MAAM,CAAC,UAAU,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,KAAK,CAAC;IAElE,IAAA,uCAAW,EAAE,+BAAO,EAAE,yBAAI,EAAE,6CAAc,EAAE,mCAAS,CAAmB;IACxE,IAAA,2BAAS,EAAE,iBAAI,CAAW;IAElC,EAAE,CAAC,CAAC,cAAc,CAAC,CAAC,CAAC;QACnB,aAAa,CAAC,SAAS,GAAG,SAAS,CAAC;IACtC,CAAC;IAED,EAAE,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC;QACd,aAAa,CAAC,IAAI,GAAG,IAAI,CAAC;IAC5B,CAAC;IAED,MAAM,CAAC,aAAa,CAAC,SAAS,EAAE,CAAC;AACnC,CAAC,CAAC"} \ No newline at end of file diff --git a/src/index.ts b/src/index.ts index cb9d9d5..c63c3c5 100644 --- a/src/index.ts +++ b/src/index.ts @@ -33,14 +33,17 @@ export class ApolloError extends ExtendableError { _showLocations: boolean = false; _showPath: boolean = false; - constructor(name: string, config: ErrorConfig) { - super((arguments[2] && arguments[2].message) || ''); - - const t = (arguments[2] && arguments[2].time_thrown) || (new Date()).toISOString(); - const m = (arguments[2] && arguments[2].message) || ''; - const configData = (arguments[2] && arguments[2].data) || {}; + // NOTE: The object passed to the Constructor is actually `ctorData`. + // We are binding the constructor to the name and config object + // for the first two parameters inside of `createError` + constructor(name: string, config: ErrorConfig, ctorData: any) { + super((ctorData && ctorData.message) || ''); + + const t = (ctorData && ctorData.time_thrown) || (new Date()).toISOString(); + const m = (ctorData && ctorData.message) || ''; + const configData = (ctorData && ctorData.data) || {}; const d = { ...this.data, ...configData }; - const opts = ((arguments[2] && arguments[2].options) || {}); + const opts = ((ctorData && ctorData.options) || {}); this.name = name; @@ -80,6 +83,9 @@ export const isInstance = e => e instanceof ApolloError; export const createError = (name: string, config: ErrorConfig) => { assert(isObject(config), 'createError requires a config object as the second parameter'); assert(isString(config.message), 'createError requires a "message" property on the config object passed as the second parameter'); + // NOTE: The first two parameters give to the constructor will always be name and config + // Parameters passed to the constructor when `new` is invoked will be passed as + // subsequent parameters. return ApolloError.bind(null, name, config); }; From b7fdcd9aff234a4b59e7f01f938d75fe63d4733f Mon Sep 17 00:00:00 2001 From: Stan Chang Khin Boon Date: Wed, 28 Mar 2018 11:03:55 +0800 Subject: [PATCH 35/57] Rename ctorData to ctorConfig Summary: Previously, ctorData is accessing all the attributes listed in ErrorConfig so it should be define as ErrorConfig instance and renamed as ctorConfig. The common use case will bind the first 2 arguments of ApolloError.constructor() to name and a common configuration object, leaving the ctorConfig to provide the final customization. We make sure that ctorConfig take precedence over config and merge them whenever necessary. --- src/index.ts | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/src/index.ts b/src/index.ts index c63c3c5..180ffc7 100644 --- a/src/index.ts +++ b/src/index.ts @@ -36,14 +36,17 @@ export class ApolloError extends ExtendableError { // NOTE: The object passed to the Constructor is actually `ctorData`. // We are binding the constructor to the name and config object // for the first two parameters inside of `createError` - constructor(name: string, config: ErrorConfig, ctorData: any) { - super((ctorData && ctorData.message) || ''); - - const t = (ctorData && ctorData.time_thrown) || (new Date()).toISOString(); - const m = (ctorData && ctorData.message) || ''; - const configData = (ctorData && ctorData.data) || {}; - const d = { ...this.data, ...configData }; - const opts = ((ctorData && ctorData.options) || {}); + constructor(name: string, config: ErrorConfig, ctorConfig: ErrorConfig) { + super((ctorConfig && ctorConfig.message) || (config && config.message) || ''); + + const t = (ctorConfig && ctorConfig.time_thrown) || (config && config.time_thrown) || (new Date()).toISOString(); + const m = (ctorConfig && ctorConfig.message) || (config && config.message) || ''; + const ctorData = (ctorConfig && ctorConfig.data) || {}; + const configData = (config && config.data) || {}; + const d = { ...this.data, ...configData, ...ctorData }; + const ctorOptions = (ctorConfig && ctorConfig.options) || {}; + const configOptions = (config && config.options) || {}; + const opts = { ...configOptions, ...ctorOptions }; this.name = name; From 2df269ae178a1ab2b01eabbbf32e47b8346c1ead Mon Sep 17 00:00:00 2001 From: "Andrew E. Rhyne" Date: Tue, 10 Apr 2018 21:08:58 -0700 Subject: [PATCH 36/57] Revert "Make serialized error spec compliant" --- src/index.ts | 18 +++++++----------- test/spec.js | 2 +- 2 files changed, 8 insertions(+), 12 deletions(-) diff --git a/src/index.ts b/src/index.ts index 21c46de..180ffc7 100644 --- a/src/index.ts +++ b/src/index.ts @@ -16,13 +16,11 @@ export interface ErrorConfig { export interface ErrorInfo { message: string; + name: string; + time_thrown: string; + data?: object; path?: string; locations?: any; - extensions?: { - name: string; - time_thrown: string; - data?: object; - }; } export class ApolloError extends ExtendableError { @@ -64,13 +62,11 @@ export class ApolloError extends ExtendableError { let error: ErrorInfo = { message, + name, + time_thrown, + data, path, - locations, - extensions: { - name, - time_thrown, - data - } + locations }; if (_showLocations) { diff --git a/test/spec.js b/test/spec.js index f5932b0..9036ac4 100644 --- a/test/spec.js +++ b/test/spec.js @@ -31,7 +31,7 @@ describe('createError', () => { }, }); - const { message, extensions: { name, time_thrown, data } } = e.serialize(); + const { message, name, time_thrown, data } = e.serialize(); expect(message).to.equal('A foo 2.0 error has occurred'); expect(name).to.equal('FooError'); expect(time_thrown).to.equal(e.time_thrown); From 9d4ca8b4f57af9246342567617f82729b667afb0 Mon Sep 17 00:00:00 2001 From: "Andrew E. Rhyne" Date: Tue, 10 Apr 2018 21:14:07 -0700 Subject: [PATCH 37/57] fixes for wrong data being returned in errors --- dist/index.d.ts | 2 +- dist/index.js | 23 ++++++++++++++++------- dist/index.js.map | 2 +- test/spec.js | 19 +++++++++++++++++++ 4 files changed, 37 insertions(+), 9 deletions(-) diff --git a/dist/index.d.ts b/dist/index.d.ts index 09cd18e..1fb6aac 100644 --- a/dist/index.d.ts +++ b/dist/index.d.ts @@ -25,7 +25,7 @@ export declare class ApolloError extends ExtendableError { locations: any; _showLocations: boolean; _showPath: boolean; - constructor(name: string, config: ErrorConfig, ctorData: any); + constructor(name: string, config: ErrorConfig, ctorConfig: ErrorConfig); serialize(): ErrorInfo; } export declare const isInstance: (e: any) => boolean; diff --git a/dist/index.js b/dist/index.js index f0798fc..663e89d 100644 --- a/dist/index.js +++ b/dist/index.js @@ -24,15 +24,21 @@ var isString = function (d) { return Object.prototype.toString.call(d) === '[obj var isObject = function (d) { return Object.prototype.toString.call(d) === '[object Object]'; }; var ApolloError = /** @class */ (function (_super) { __extends(ApolloError, _super); - function ApolloError(name, config, ctorData) { - var _this = _super.call(this, (ctorData && ctorData.message) || '') || this; + // NOTE: The object passed to the Constructor is actually `ctorData`. + // We are binding the constructor to the name and config object + // for the first two parameters inside of `createError` + function ApolloError(name, config, ctorConfig) { + var _this = _super.call(this, (ctorConfig && ctorConfig.message) || (config && config.message) || '') || this; _this._showLocations = false; _this._showPath = false; - var t = (ctorData && ctorData.time_thrown) || (new Date()).toISOString(); - var m = (ctorData && ctorData.message) || ''; - var configData = (ctorData && ctorData.data) || {}; - var d = __assign({}, _this.data, configData); - var opts = ((ctorData && ctorData.options) || {}); + var t = (ctorConfig && ctorConfig.time_thrown) || (config && config.time_thrown) || (new Date()).toISOString(); + var m = (ctorConfig && ctorConfig.message) || (config && config.message) || ''; + var ctorData = (ctorConfig && ctorConfig.data) || {}; + var configData = (config && config.data) || {}; + var d = __assign({}, _this.data, configData, ctorData); + var ctorOptions = (ctorConfig && ctorConfig.options) || {}; + var configOptions = (config && config.options) || {}; + var opts = __assign({}, configOptions, ctorOptions); _this.name = name; _this.message = m; _this.time_thrown = t; @@ -66,6 +72,9 @@ exports.isInstance = function (e) { return e instanceof ApolloError; }; exports.createError = function (name, config) { assert(isObject(config), 'createError requires a config object as the second parameter'); assert(isString(config.message), 'createError requires a "message" property on the config object passed as the second parameter'); + // NOTE: The first two parameters give to the constructor will always be name and config + // Parameters passed to the constructor when `new` is invoked will be passed as + // subsequent parameters. return ApolloError.bind(null, name, config); }; exports.formatError = function (error, returnNull) { diff --git a/dist/index.js.map b/dist/index.js.map index a51ade4..98e6395 100644 --- a/dist/index.js.map +++ b/dist/index.js.map @@ -1 +1 @@ -{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA,+BAAiC;AACjC,qDAA+C;AAE/C,IAAM,QAAQ,GAAG,UAAA,CAAC,IAAI,OAAA,MAAM,CAAC,SAAS,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC,CAAC,KAAK,iBAAiB,EAAvD,CAAuD,CAAC;AAC9E,IAAM,QAAQ,GAAG,UAAA,CAAC,IAAI,OAAA,MAAM,CAAC,SAAS,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC,CAAC,KAAK,iBAAiB,EAAvD,CAAuD,CAAC;AAqB9E;IAAiC,+BAAe;IAU9C,qBAAY,IAAY,EAAE,MAAmB,EAAE,QAAa;QAA5D,YACE,kBAAM,CAAC,QAAQ,IAAI,QAAQ,CAAC,OAAO,CAAC,IAAI,EAAE,CAAC,SAe5C;QAnBD,oBAAc,GAAY,KAAK,CAAC;QAChC,eAAS,GAAY,KAAK,CAAC;QAKzB,IAAM,CAAC,GAAG,CAAC,QAAQ,IAAI,QAAQ,CAAC,WAAW,CAAC,IAAI,CAAC,IAAI,IAAI,EAAE,CAAC,CAAC,WAAW,EAAE,CAAC;QAC3E,IAAM,CAAC,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IAAI,GAAG,IAAI,CAAC;IAC5B,CAAC;IAED,MAAM,CAAC,aAAa,CAAC,SAAS,EAAE,CAAC;AACnC,CAAC,CAAC"} \ No newline at end of file diff --git a/test/spec.js b/test/spec.js index 9036ac4..74c07ae 100644 --- a/test/spec.js +++ b/test/spec.js @@ -40,6 +40,25 @@ describe('createError', () => { foo: 'bar' }); }); + it('uses original message and merges original data', () => { + const FooError = createError('FooError', { + message: 'A foo error has occurred', + data: { + hello: 'world' + }, + options: { + showLocations: false, + showPath: true + } + }); + const e = new FooError({data: {foo: 'bar'}}); + + const { message, name, time_thrown, data } = e.serialize(); + expect(message).to.equal('A foo error has occurred'); + expect(name).to.equal('FooError'); + expect(time_thrown).to.equal(e.time_thrown); + expect(data).to.eql({ hello: 'world', foo: 'bar' }); + }); }); context('when missing a config as the second parameter', () => { it('throws an assertion error with a useful message', () => { From 106ec8f19dcbcb5cfb3473a47f720b1692433c6c Mon Sep 17 00:00:00 2001 From: "Andrew E. Rhyne" Date: Tue, 10 Apr 2018 21:15:42 -0700 Subject: [PATCH 38/57] release 1.8.0 --- CHANGELOG.md | 6 ++++++ package.json | 2 +- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ec7c2e5..2ae30ad 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,4 +1,10 @@ +1.8.0 / 2018-04-10 +================== + + * Fix: Wrong and missing data being returned in errors (@thebigredgeek) + * Fix: Reverted breaking change regarding spec compliance (@thebigredgeek) + 1.7.1 / 2018-02-22 ================== diff --git a/package.json b/package.json index d2bb1f8..d010e02 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "apollo-errors", - "version": "1.7.1", + "version": "1.8.0", "description": "Machine-readable custom errors for Apollostack's GraphQL server", "main": "dist/index.js", "scripts": { From 94b3502842f9fba0b8469c04f3ce9a11fb66bb8f Mon Sep 17 00:00:00 2001 From: Laurin Quast Date: Wed, 11 Apr 2018 15:48:16 +0200 Subject: [PATCH 39/57] Implement internalData property --- src/index.ts | 1 + test/spec.js | 14 ++++++++++++++ 2 files changed, 15 insertions(+) diff --git a/src/index.ts b/src/index.ts index 180ffc7..71bf3a6 100644 --- a/src/index.ts +++ b/src/index.ts @@ -8,6 +8,7 @@ export interface ErrorConfig { message: string; time_thrown?: string; data?: object; + internalData?: object; options?: { showPath?: boolean; showLocations?: boolean; diff --git a/test/spec.js b/test/spec.js index 74c07ae..ac2feb6 100644 --- a/test/spec.js +++ b/test/spec.js @@ -137,4 +137,18 @@ describe('formatError', () => { }); }); }); + context('error has internalData', () => { + it('does not include the internalData property', () => { + const FooError = createError('FooError', { + message: 'A foo error has occurred', + internalData: { + secret: 'SQL ERROR' + } + }); + + const e = new FooError(); + const s = formatError(e); + expect(s.internalData).to.eq(undefined) + }) + }) }); From a710b537f3d7233e85ada580d56dbdd7e4efb0be Mon Sep 17 00:00:00 2001 From: Laurin Quast Date: Wed, 11 Apr 2018 16:04:50 +0200 Subject: [PATCH 40/57] Ensure internalData property is actually present on the error instance --- src/index.ts | 5 +++++ test/spec.js | 3 +++ 2 files changed, 8 insertions(+) diff --git a/src/index.ts b/src/index.ts index 71bf3a6..683c776 100644 --- a/src/index.ts +++ b/src/index.ts @@ -29,6 +29,7 @@ export class ApolloError extends ExtendableError { message: string; time_thrown: string; data: object; + internalData: object; path: any; locations: any; _showLocations: boolean = false; @@ -43,8 +44,11 @@ export class ApolloError extends ExtendableError { const t = (ctorConfig && ctorConfig.time_thrown) || (config && config.time_thrown) || (new Date()).toISOString(); const m = (ctorConfig && ctorConfig.message) || (config && config.message) || ''; const ctorData = (ctorConfig && ctorConfig.data) || {}; + const ctorInternalData = (ctorConfig && ctorConfig.internalData) || {} const configData = (config && config.data) || {}; + const configInternalData = (config && config.internalData) || {} const d = { ...this.data, ...configData, ...ctorData }; + const id = { ...this.internalData, ...configInternalData, ...ctorInternalData} const ctorOptions = (ctorConfig && ctorConfig.options) || {}; const configOptions = (config && config.options) || {}; const opts = { ...configOptions, ...ctorOptions }; @@ -54,6 +58,7 @@ export class ApolloError extends ExtendableError { this.message = m; this.time_thrown = t; this.data = d; + this.internalData = id; this._showLocations = !!opts.showLocations; this._showPath = !!opts.showPath; } diff --git a/test/spec.js b/test/spec.js index ac2feb6..4b2df72 100644 --- a/test/spec.js +++ b/test/spec.js @@ -147,6 +147,9 @@ describe('formatError', () => { }); const e = new FooError(); + expect(e.internalData).to.to.eql({ + secret: 'SQL ERROR' + }) const s = formatError(e); expect(s.internalData).to.eq(undefined) }) From 7145ffa3c58e811c2ae4392858cd672d48a28222 Mon Sep 17 00:00:00 2001 From: Laurin Quast Date: Fri, 13 Apr 2018 09:33:42 +0200 Subject: [PATCH 41/57] Add documentation for internalData property --- README.md | 32 ++++++++++++++++++++++++++++---- 1 file changed, 28 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 9b06322..67744e9 100644 --- a/README.md +++ b/README.md @@ -58,6 +58,9 @@ const resolverThatThrowsError = (root, params, context) => { throw new FooError({ data: { something: 'important' + }, + internalData: { + error: `The SQL server died.` } }); } @@ -83,18 +86,39 @@ Witness glorious simplicity: } ``` +The `internalData` property is meant for data you want to store on the error object (e.g. for logging), but not send out to your end users. +You can utilize this data for logging purposes. + +```js +import { isInstance as isApolloErrorInstance, formatError as formatApolloError } from 'apollo-errors'; + +function formatError(error) { + const { originialError } = error; + if (isApolloErrorInstance(originalError)) { + // log internalData to stdout but not include it in the formattedError + console.log(JSON.stringify({ + type: `error`, + data: originalError.data, + internalData: originalError.internalData + })); + } + return formatApolloError(error) +} + +``` + ## API -### ApolloError ({ [time_thrown: String, data: Object, message: String ]}) +### ApolloError ({ [time_thrown: String, data: Object, internalData: object message: String ]}) Creates a new ApolloError object. Note that `ApolloError` in this context refers to an error class created and returned by `createError` documented below. Error can be -initialized with a custom `time_thrown` ISODate (default is current ISODate), `data` object (which will be merged with data specified through `createError`, if it exists), and `message` (which will override the message specified through `createError`). +initialized with a custom `time_thrown` ISODate (default is current ISODate), `data` object (which will be merged with data specified through `createError`, if it exists), `internalData` object (which will be merged with internalData specified trough `createError`) and `message` (which will override the message specified through `createError`). -### createError(name, {message: String, [data: Object, options: Object]}): ApolloError +### createError(name, {message: String, [data: Object, internalData: object, options: Object]}): ApolloError -Creates and returns an error class with the given `name` and `message`, optionally initialized with the given `data` and `options`. `data` passed to `createError` will later be merged with any data passed to the constructor. +Creates and returns an error class with the given `name` and `message`, optionally initialized with the given `data`, `internalData` and `options`. `data` and `internalData` passed to `createError` will later be merged with any data passed to the constructor. #### Options (default): From c72a6192bd772b3bbb0c0dbe6797bf4bf919f5b2 Mon Sep 17 00:00:00 2001 From: Andrew Rhyne Date: Tue, 17 Apr 2018 10:02:47 -0700 Subject: [PATCH 42/57] release 1.9.0 --- CHANGELOG.md | 5 +++++ dist/index.d.ts | 2 ++ dist/index.js | 4 ++++ dist/index.js.map | 2 +- package.json | 2 +- 5 files changed, 13 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2ae30ad..636b0cc 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,4 +1,9 @@ +1.9.0 / 2018-04-17 +================== + + * Feature: Added `internalData` property for non-serialized context data (@n1ru4l, #41) + 1.8.0 / 2018-04-10 ================== diff --git a/dist/index.d.ts b/dist/index.d.ts index 1fb6aac..eb2549e 100644 --- a/dist/index.d.ts +++ b/dist/index.d.ts @@ -3,6 +3,7 @@ export interface ErrorConfig { message: string; time_thrown?: string; data?: object; + internalData?: object; options?: { showPath?: boolean; showLocations?: boolean; @@ -21,6 +22,7 @@ export declare class ApolloError extends ExtendableError { message: string; time_thrown: string; data: object; + internalData: object; path: any; locations: any; _showLocations: boolean; diff --git a/dist/index.js b/dist/index.js index 663e89d..a63302d 100644 --- a/dist/index.js +++ b/dist/index.js @@ -34,8 +34,11 @@ var ApolloError = /** @class */ (function (_super) { var t = (ctorConfig && ctorConfig.time_thrown) || (config && config.time_thrown) || (new Date()).toISOString(); var m = (ctorConfig && ctorConfig.message) || (config && config.message) || ''; var ctorData = (ctorConfig && ctorConfig.data) || {}; + var ctorInternalData = (ctorConfig && ctorConfig.internalData) || {}; var configData = (config && config.data) || {}; + var configInternalData = (config && config.internalData) || {}; var d = __assign({}, _this.data, configData, ctorData); + var id = __assign({}, _this.internalData, configInternalData, ctorInternalData); var ctorOptions = (ctorConfig && ctorConfig.options) || {}; var configOptions = (config && config.options) || {}; var opts = __assign({}, configOptions, ctorOptions); @@ -43,6 +46,7 @@ var ApolloError = /** @class */ (function (_super) { _this.message = m; _this.time_thrown = t; _this.data = d; + _this.internalData = id; _this._showLocations = !!opts.showLocations; _this._showPath = !!opts.showPath; return _this; diff --git a/dist/index.js.map b/dist/index.js.map index 98e6395..5361035 100644 --- a/dist/index.js.map +++ b/dist/index.js.map @@ -1 +1 @@ -{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA,+BAAiC;AACjC,qDAA+C;AAE/C,IAAM,QAAQ,GAAG,UAAA,CAAC,IAAI,OAAA,MAAM,CAAC,SAAS,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC,CAAC,KAAK,iBAAiB,EAAvD,CAAuD,CAAC;AAC9E,IAAM,QAAQ,GAAG,UAAA,CAAC,IAAI,OAAA,MAAM,CAAC,SAAS,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC,CAAC,KAAK,iBAAiB,EAAvD,CAAuD,CAAC;AAqB9E;IAAiC,+BAAe;IAU9C,qEAAqE;IACrE,qEAAqE;IACrE,6DAA6D;IAC7D,qBAAY,IAAY,EAAE,MAAmB,EAAE,UAAuB;QAAtE,YACE,kBAAM,CAAC,UAAU,IAAI,UAAU,CAAC,OAAO,CAAC,IAAI,CAAC,MAAM,IAAI,MAAM,CAAC,OAAO,CAAC,IAAI,EAAE,CAAC,SAkB9E;QAzBD,oBAAc,GAAY,KAAK,CAAC;QAChC,eAAS,GAAY,KAAK,CAA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E,UAAkB;IAAlB,2BAAA,EAAA,kBAAkB;IACnD,IAAM,aAAa,GAAG,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,aAAa,IAAI,KAAK,CAAC,CAAC,CAAC,IAAI,CAAC;IAElE,IAAI,CAAC,aAAa;QAAE,OAAO,UAAU,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,KAAK,CAAC;IAE7C,IAAA,yBAAI,CAAmB;IAE/B,IAAI,CAAC,IAAI,IAAI,CAAC,kBAAU,CAAC,aAAa,CAAC;QAAE,OAAO,UAAU,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,KAAK,CAAC;IAElE,IAAA,uCAAW,EAAE,+BAAO,EAAE,yBAAI,EAAE,6CAAc,EAAE,mCAAS,CAAmB;IACxE,IAAA,2BAAS,EAAE,iBAAI,CAAW;IAElC,IAAI,cAAc,EAAE;QAClB,aAAa,CAAC,SAAS,GAAG,SAAS,CAAC;KACrC;IAED,IAAI,SAAS,EAAE;QACb,aAAa,CAAC,IAAI,GAAG,IAAI,CAAC;KAC3B;IAED,OAAO,aAAa,CAAC,SAAS,EAAE,CAAC;AACnC,CAAC,CAAC"} \ No newline at end of file diff --git a/package.json b/package.json index d010e02..6303069 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "apollo-errors", - "version": "1.8.0", + "version": "1.9.0", "description": "Machine-readable custom errors for Apollostack's GraphQL server", "main": "dist/index.js", "scripts": { From 9eb49faf052bf242a396e67b4ee28d9845c6c8f4 Mon Sep 17 00:00:00 2001 From: Laurin Quast Date: Wed, 18 Apr 2018 16:03:51 +0200 Subject: [PATCH 43/57] Fix typo in README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 67744e9..ae237ad 100644 --- a/README.md +++ b/README.md @@ -109,7 +109,7 @@ function formatError(error) { ## API -### ApolloError ({ [time_thrown: String, data: Object, internalData: object message: String ]}) +### ApolloError ({ [time_thrown: String, data: Object, internalData: object, message: String ]}) Creates a new ApolloError object. Note that `ApolloError` in this context refers to an error class created and returned by `createError` documented below. Error can be From 672a3082773fb98ea5abe7394b78a1f8e0dedcad Mon Sep 17 00:00:00 2001 From: junho nam Date: Sun, 13 May 2018 15:33:35 +0900 Subject: [PATCH 44/57] readme wrong word fix --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index ae237ad..da9af99 100644 --- a/README.md +++ b/README.md @@ -93,7 +93,7 @@ You can utilize this data for logging purposes. import { isInstance as isApolloErrorInstance, formatError as formatApolloError } from 'apollo-errors'; function formatError(error) { - const { originialError } = error; + const { originalError } = error; if (isApolloErrorInstance(originalError)) { // log internalData to stdout but not include it in the formattedError console.log(JSON.stringify({ From 2c25351c6dc3e70ea770c75c6540bc2eddcf4a83 Mon Sep 17 00:00:00 2001 From: Renovate Bot Date: Wed, 10 Apr 2019 19:33:56 +0000 Subject: [PATCH 45/57] Add renovate.json --- renovate.json | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 renovate.json diff --git a/renovate.json b/renovate.json new file mode 100644 index 0000000..f45d8f1 --- /dev/null +++ b/renovate.json @@ -0,0 +1,5 @@ +{ + "extends": [ + "config:base" + ] +} From 5338d55236afb2bd51935d44be3f4ca9d9d6af3c Mon Sep 17 00:00:00 2001 From: Renovate Bot Date: Fri, 3 May 2019 20:06:27 +0000 Subject: [PATCH 46/57] Pin dependencies --- package.json | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/package.json b/package.json index 6303069..237c45e 100644 --- a/package.json +++ b/package.json @@ -29,17 +29,17 @@ "extendable-error": "^0.1.5" }, "devDependencies": { - "babel-cli": "^6.18.0", - "babel-core": "^6.17.0", - "babel-eslint": "^7.0.0", - "babel-preset-es2015": "^6.16.0", - "babel-register": "^6.18.0", - "chai": "^3.5.0", - "eslint": "^3.8.1", - "eslint-plugin-babel": "^3.3.0", - "mocha": "^3.1.2", - "rimraf": "^2.5.4", - "typescript": "^2.5.2" + "babel-cli": "6.26.0", + "babel-core": "6.26.3", + "babel-eslint": "7.2.3", + "babel-preset-es2015": "6.24.1", + "babel-register": "6.26.0", + "chai": "3.5.0", + "eslint": "3.19.0", + "eslint-plugin-babel": "3.3.0", + "mocha": "3.5.3", + "rimraf": "2.6.3", + "typescript": "2.9.2" }, "typings": "dist/index.d.ts" } From 79d5948cc355e0b53be48dd70d1176b50fcac0ad Mon Sep 17 00:00:00 2001 From: Renovate Bot Date: Sun, 12 May 2019 11:02:44 +0000 Subject: [PATCH 47/57] Update dependency assert to v2 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 6303069..f24175e 100644 --- a/package.json +++ b/package.json @@ -25,7 +25,7 @@ }, "homepage": "https://github.com/thebigredgeek/apollo-errors#readme", "dependencies": { - "assert": "^1.4.1", + "assert": "^2.0.0", "extendable-error": "^0.1.5" }, "devDependencies": { From ff5d46800c926fe79cf3fd110228843a5e62df98 Mon Sep 17 00:00:00 2001 From: "Andrew E. Rhyne" Date: Mon, 23 Sep 2019 14:50:53 -0500 Subject: [PATCH 48/57] fix --- .circleci/config.yml | 54 ++++++++++++++++++++++++++++++++++++++++++++ circle.yml | 14 ------------ package.json | 5 +++- 3 files changed, 58 insertions(+), 15 deletions(-) create mode 100644 .circleci/config.yml delete mode 100644 circle.yml diff --git a/.circleci/config.yml b/.circleci/config.yml new file mode 100644 index 0000000..772a636 --- /dev/null +++ b/.circleci/config.yml @@ -0,0 +1,54 @@ +version: 2 +workflows: + version: 2 + node-multi-build: + jobs: + - node-v6 + - node-v8 + - node-v10 + - node-v12 +jobs: + node-base: &node-base + docker: + - image: node + steps: + - checkout + - restore_cache: + keys: + - npm-lock-{{ .Branch }}-{{ .Environment.CIRCLE_JOB }}-{{ checksum "package.json" }} + - npm-lock-master-{{ .Environment.CIRCLE_JOB }}-{{ checksum "package.json" }} + - npm-cache-{{ .Branch }}-{{ .Environment.CIRCLE_JOB }} + - npm-cache-master-{{ .Environment.CIRCLE_JOB }} + - run: + name: Install dependencies + command: npm install + - run: + name: Build + command: npm run build + - run: + name: Test + command: npm run test + - save_cache: + key: npm-lock-{{ .Branch }}-{{ .Environment.CIRCLE_JOB }}-{{ checksum "package.json" }} + paths: + - node_modules + - save_cache: + key: npm-cache-{{ .Branch }}-{{ .Environment.CIRCLE_JOB }}-{{ checksum "package.json" }} + paths: + - ~/.npm/_cacache + node-v6: + <<: *node-base + docker: + - image: node:6 + node-v8: + <<: *node-base + docker: + - image: node:8 + node-v10: + <<: *node-base + docker: + - image: node:10 + node-v12: + <<: *node-base + docker: + - image: node:12 diff --git a/circle.yml b/circle.yml deleted file mode 100644 index 1357e3f..0000000 --- a/circle.yml +++ /dev/null @@ -1,14 +0,0 @@ -machine: - node: - version: 5.5.0 - -dependencies: - override: - - make environment - - make dependencies - -test: - override: - - make lint - - make - - make test diff --git a/package.json b/package.json index f0c3510..b2a9e70 100644 --- a/package.json +++ b/package.json @@ -4,7 +4,10 @@ "description": "Machine-readable custom errors for Apollostack's GraphQL server", "main": "dist/index.js", "scripts": { - "test": "make test" + "test": "mocha", + "build": "tsc", + "lint": "eslint src", + "clean": "rimraf dist" }, "repository": { "type": "git", From a9ff7e6b2bd4cda314ccd21b9cdec8e31b092ddf Mon Sep 17 00:00:00 2001 From: "Andrew E. Rhyne" Date: Mon, 23 Sep 2019 14:55:34 -0500 Subject: [PATCH 49/57] fix --- .circleci/config.yml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 772a636..09802b4 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -39,16 +39,16 @@ jobs: node-v6: <<: *node-base docker: - - image: node:6 + - image: circleci/node:6 node-v8: <<: *node-base docker: - - image: node:8 + - image: circleci/node:8 node-v10: <<: *node-base docker: - - image: node:10 + - image: circleci/node:10 node-v12: <<: *node-base docker: - - image: node:12 + - image: circleci/node:12 From 555800e24e42ad7c32268a3850489541535540cd Mon Sep 17 00:00:00 2001 From: "Andrew E. Rhyne" Date: Mon, 23 Sep 2019 14:57:42 -0500 Subject: [PATCH 50/57] fix --- .circleci/config.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 09802b4..97eb9c4 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -1,4 +1,3 @@ -version: 2 workflows: version: 2 node-multi-build: @@ -7,6 +6,7 @@ workflows: - node-v8 - node-v10 - node-v12 +version: 2 jobs: node-base: &node-base docker: From f6e95ecd7b31d564a758ef0bb7d4d4e93f5da445 Mon Sep 17 00:00:00 2001 From: "Andrew E. Rhyne" Date: Mon, 23 Sep 2019 14:59:59 -0500 Subject: [PATCH 51/57] updated readme --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index da9af99..353c2e4 100644 --- a/README.md +++ b/README.md @@ -3,7 +3,7 @@ Machine-readable custom errors for Apollostack's GraphQL server [![NPM](https://nodei.co/npm/apollo-errors.png?downloads=true&downloadRank=true&stars=true)](https://nodei.co/npm/apollo-errors/) -[![CircleCI](https://circleci.com/gh/thebigredgeek/apollo-errors.svg?style=shield)](https://circleci.com/gh/thebigredgeek/apollo-errors/tree/master) [![Beerpay](https://beerpay.io/thebigredgeek/apollo-errors/badge.svg?style=beer-square)](https://beerpay.io/thebigredgeek/apollo-errors) [![Beerpay](https://beerpay.io/thebigredgeek/apollo-errors/make-wish.svg?style=flat-square)](https://beerpay.io/thebigredgeek/apollo-errors?focus=wish) +[![CircleCI](https://circleci.com/gh/boltsource/apollo-errors.svg?style=shield)](https://circleci.com/gh/thebigredgeek/apollo-errors/tree/master) [![Beerpay](https://beerpay.io/thebigredgeek/apollo-errors/badge.svg?style=beer-square)](https://beerpay.io/thebigredgeek/apollo-errors) [![Beerpay](https://beerpay.io/thebigredgeek/apollo-errors/make-wish.svg?style=flat-square)](https://beerpay.io/thebigredgeek/apollo-errors?focus=wish) ## Example from Apollo Day From 1af8e5f600218bb770b979f780e88263d15c9c35 Mon Sep 17 00:00:00 2001 From: "Andrew E. Rhyne" Date: Mon, 23 Sep 2019 15:02:21 -0500 Subject: [PATCH 52/57] fix --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 353c2e4..5747f0b 100644 --- a/README.md +++ b/README.md @@ -3,7 +3,7 @@ Machine-readable custom errors for Apollostack's GraphQL server [![NPM](https://nodei.co/npm/apollo-errors.png?downloads=true&downloadRank=true&stars=true)](https://nodei.co/npm/apollo-errors/) -[![CircleCI](https://circleci.com/gh/boltsource/apollo-errors.svg?style=shield)](https://circleci.com/gh/thebigredgeek/apollo-errors/tree/master) [![Beerpay](https://beerpay.io/thebigredgeek/apollo-errors/badge.svg?style=beer-square)](https://beerpay.io/thebigredgeek/apollo-errors) [![Beerpay](https://beerpay.io/thebigredgeek/apollo-errors/make-wish.svg?style=flat-square)](https://beerpay.io/thebigredgeek/apollo-errors?focus=wish) +[![CircleCI](https://circleci.com/gh/boltsource/apollo-errors.svg?style=shield)](https://circleci.com/gh/boltsource/apollo-errors/tree/master) [![Beerpay](https://beerpay.io/thebigredgeek/apollo-errors/badge.svg?style=beer-square)](https://beerpay.io/thebigredgeek/apollo-errors) [![Beerpay](https://beerpay.io/thebigredgeek/apollo-errors/make-wish.svg?style=flat-square)](https://beerpay.io/thebigredgeek/apollo-errors?focus=wish) ## Example from Apollo Day From fd85a2c76099bf34e4f49053b17eb4d2d066fb11 Mon Sep 17 00:00:00 2001 From: "Andrew E. Rhyne" Date: Wed, 14 Jul 2021 12:00:24 -0500 Subject: [PATCH 53/57] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 5747f0b..da9af99 100644 --- a/README.md +++ b/README.md @@ -3,7 +3,7 @@ Machine-readable custom errors for Apollostack's GraphQL server [![NPM](https://nodei.co/npm/apollo-errors.png?downloads=true&downloadRank=true&stars=true)](https://nodei.co/npm/apollo-errors/) -[![CircleCI](https://circleci.com/gh/boltsource/apollo-errors.svg?style=shield)](https://circleci.com/gh/boltsource/apollo-errors/tree/master) [![Beerpay](https://beerpay.io/thebigredgeek/apollo-errors/badge.svg?style=beer-square)](https://beerpay.io/thebigredgeek/apollo-errors) [![Beerpay](https://beerpay.io/thebigredgeek/apollo-errors/make-wish.svg?style=flat-square)](https://beerpay.io/thebigredgeek/apollo-errors?focus=wish) +[![CircleCI](https://circleci.com/gh/thebigredgeek/apollo-errors.svg?style=shield)](https://circleci.com/gh/thebigredgeek/apollo-errors/tree/master) [![Beerpay](https://beerpay.io/thebigredgeek/apollo-errors/badge.svg?style=beer-square)](https://beerpay.io/thebigredgeek/apollo-errors) [![Beerpay](https://beerpay.io/thebigredgeek/apollo-errors/make-wish.svg?style=flat-square)](https://beerpay.io/thebigredgeek/apollo-errors?focus=wish) ## Example from Apollo Day From bf1aee78b437293f02b3b16cf9cee16f8c103cda Mon Sep 17 00:00:00 2001 From: "Andrew E. Rhyne" Date: Wed, 14 Jul 2021 12:01:16 -0500 Subject: [PATCH 54/57] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index da9af99..1a6b97d 100644 --- a/README.md +++ b/README.md @@ -3,7 +3,7 @@ Machine-readable custom errors for Apollostack's GraphQL server [![NPM](https://nodei.co/npm/apollo-errors.png?downloads=true&downloadRank=true&stars=true)](https://nodei.co/npm/apollo-errors/) -[![CircleCI](https://circleci.com/gh/thebigredgeek/apollo-errors.svg?style=shield)](https://circleci.com/gh/thebigredgeek/apollo-errors/tree/master) [![Beerpay](https://beerpay.io/thebigredgeek/apollo-errors/badge.svg?style=beer-square)](https://beerpay.io/thebigredgeek/apollo-errors) [![Beerpay](https://beerpay.io/thebigredgeek/apollo-errors/make-wish.svg?style=flat-square)](https://beerpay.io/thebigredgeek/apollo-errors?focus=wish) +[![CircleCI](https://circleci.com/gh/thebigredgeek/apollo-errors.svg?style=shield)](https://circleci.com/gh/thebigredgeek/apollo-errors/tree/master) [![Beerpay] ## Example from Apollo Day From 11bcd65171a8a2f487d741a1ca6e1b2fcf4a2642 Mon Sep 17 00:00:00 2001 From: "Andrew E. Rhyne" Date: Wed, 14 Jul 2021 12:01:28 -0500 Subject: [PATCH 55/57] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 1a6b97d..2446d07 100644 --- a/README.md +++ b/README.md @@ -3,7 +3,7 @@ Machine-readable custom errors for Apollostack's GraphQL server [![NPM](https://nodei.co/npm/apollo-errors.png?downloads=true&downloadRank=true&stars=true)](https://nodei.co/npm/apollo-errors/) -[![CircleCI](https://circleci.com/gh/thebigredgeek/apollo-errors.svg?style=shield)](https://circleci.com/gh/thebigredgeek/apollo-errors/tree/master) [![Beerpay] +[![CircleCI](https://circleci.com/gh/thebigredgeek/apollo-errors.svg?style=shield)](https://circleci.com/gh/thebigredgeek/apollo-errors/tree/master) ## Example from Apollo Day From 73aec86404e7cc3b2c61efa53ff9544ae27ddab2 Mon Sep 17 00:00:00 2001 From: "Andrew E. Rhyne" Date: Wed, 14 Jul 2021 12:06:00 -0500 Subject: [PATCH 56/57] Update config.yml --- .circleci/config.yml | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/.circleci/config.yml b/.circleci/config.yml index 97eb9c4..60dd741 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -6,6 +6,7 @@ workflows: - node-v8 - node-v10 - node-v12 + - node-v14 version: 2 jobs: node-base: &node-base @@ -52,3 +53,7 @@ jobs: <<: *node-base docker: - image: circleci/node:12 + node-v14: + <<: *node-base + docker: + - image: circleci/node:14 From 5e7e23a5b288819b1efca085b1b74911e2604963 Mon Sep 17 00:00:00 2001 From: "Andrew E. Rhyne" Date: Wed, 14 Jul 2021 12:08:39 -0500 Subject: [PATCH 57/57] Update config.yml --- .circleci/config.yml | 5 ----- 1 file changed, 5 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 60dd741..2622a5c 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -2,7 +2,6 @@ workflows: version: 2 node-multi-build: jobs: - - node-v6 - node-v8 - node-v10 - node-v12 @@ -37,10 +36,6 @@ jobs: key: npm-cache-{{ .Branch }}-{{ .Environment.CIRCLE_JOB }}-{{ checksum "package.json" }} paths: - ~/.npm/_cacache - node-v6: - <<: *node-base - docker: - - image: circleci/node:6 node-v8: <<: *node-base docker: