diff --git a/package.json b/package.json index 6c1588b..d69c254 100644 --- a/package.json +++ b/package.json @@ -29,7 +29,7 @@ ], "dependencies": { "graphql-relay": "^0.3.6", - "lodash": "^4.0.0" + "lodash": "^4.0.1" }, "peerDependencies": { "graphql": "^0.4.14", @@ -37,7 +37,7 @@ }, "devDependencies": { "babel": "^6.3.26", - "babel-cli": "^6.4.0", + "babel-cli": "^6.4.5", "babel-eslint": "^5.0.0-beta6", "babel-istanbul": "^0.6.0", "babel-polyfill": "^6.3.14", @@ -47,12 +47,12 @@ "chai": "^3.4.1", "chai-subset": "^1.2.0", "eslint": "^1.10.3", - "eslint-config-airbnb": "^3.1.0", + "eslint-config-airbnb": "^4.0.0", "graphql": "^0.4.14", - "mocha": "^2.3.4", - "mongoose": "^4.3.6", + "mocha": "^2.4.2", + "mongoose": "^4.3.7", "pre-commit": "^1.1.2", - "sinon": "^1.17.2", + "sinon": "^1.17.3", "sinon-chai": "^2.8.0" }, "pre-commit": [ diff --git a/src/e2e.spec.js b/src/e2e.spec.js index 284b18f..9c3a392 100644 --- a/src/e2e.spec.js +++ b/src/e2e.spec.js @@ -11,7 +11,7 @@ describe('e2e', () => { let user2; let schema; let hooks; - before(function beforeAll() { + before(() => { hooks = { viewer: { pre: spy(), diff --git a/src/model/model.js b/src/model/model.js index df009f5..bc6cd03 100644 --- a/src/model/model.js +++ b/src/model/model.js @@ -98,9 +98,9 @@ function extractPath(schemaPath) { * @return {Object) extractedSchemaPaths */ function extractPaths(schemaPaths, model) { - return reduce(schemaPaths, (fields, schemaPath) => { - return merge(fields, extractPath(schemaPath, model)); - }, {}); + return reduce(schemaPaths, (fields, schemaPath) => ( + merge(fields, extractPath(schemaPath, model)) + ), {}); } /** diff --git a/src/query/query.js b/src/query/query.js index 57cc377..6d1a237 100644 --- a/src/query/query.js +++ b/src/query/query.js @@ -95,12 +95,10 @@ function updateOne(Collection, {id, _id, ...args}, info) { function deleteOne(Collection, args) { const _id = processId(args); - return Collection.remove({_id}).then(({result}) => { - return { - id: toGlobalId(Collection.modelName, _id), - ok: !!result.ok - }; - }); + return Collection.remove({_id}).then(({result}) => ({ + id: toGlobalId(Collection.modelName, _id), + ok: !!result.ok + })); } function getList(Collection, selector, options = {}, info = null) { @@ -113,14 +111,12 @@ function getList(Collection, selector, options = {}, info = null) { } const projection = getFieldList(info); - return Collection.find(selector, projection, options).then((result) => { - return result.map((value) => { - return { - ...value.toObject(), - _type: Collection.modelName - }; - }); - }); + return Collection.find(selector, projection, options).then((result) => ( + result.map((value) => ({ + ...value.toObject(), + _type: Collection.modelName + })) + )); } function getOneResolver(graffitiModel) { @@ -303,12 +299,10 @@ async function connectionFromModel(graffitiModel, args, info) { return emptyConnection(); } - const edges = result.map((value) => { - return { - cursor: idToCursor(value._id), - node: value - }; - }); + const edges = result.map((value) => ({ + cursor: idToCursor(value._id), + node: value + })); const firstElement = await getFirst(Collection); return { diff --git a/src/query/query.spec.js b/src/query/query.spec.js index f758fff..cfced50 100644 --- a/src/query/query.spec.js +++ b/src/query/query.spec.js @@ -44,9 +44,7 @@ describe('query', () => { model: { modelName: type, findById(id) { - const obj = objArray.find((obj) => { - return obj._id === id; - }); + const obj = objArray.find((obj) => obj._id === id); return Promise.resolve(obj); }, @@ -126,12 +124,10 @@ describe('query', () => { describe('connectionFromModel', () => { it('should return a connection', async function connectionFromModelTest() { const result = await connectionFromModel(graffitiModels.type, {}); - const edges = resultArray.map((obj) => { - return { - cursor: _idToCursor(obj._id), - node: obj - }; - }); + const edges = resultArray.map((obj) => ({ + cursor: _idToCursor(obj._id), + node: obj + })); const startCursor = edges[0].cursor; const endCursor = edges[edges.length - 1].cursor; expect(result).to.containSubset({ diff --git a/src/schema/schema.spec.js b/src/schema/schema.spec.js index a7efdb3..4198340 100644 --- a/src/schema/schema.spec.js +++ b/src/schema/schema.spec.js @@ -36,8 +36,8 @@ describe('schema', () => { describe('getQueryField', () => { it('should return a singular and a plural query field', function getQueryFieldTest() { - this.sandbox.stub(query, 'getOneResolver').returns(() => {}); - this.sandbox.stub(query, 'getListResolver').returns(() => {}); + this.sandbox.stub(query, 'getOneResolver').returns(() => null); + this.sandbox.stub(query, 'getListResolver').returns(() => null); const graphQLType = types.Qux; const fields = getQueryField({Qux: {model: {}}}, graphQLType); @@ -65,8 +65,8 @@ describe('schema', () => { describe('getMutationField', () => { it('should return an addXyz and an updateXyz field', function getMutationFieldTest() { - this.sandbox.stub(query, 'getAddOneMutateHandler').returns(() => {}); - this.sandbox.stub(query, 'getUpdateOneMutateHandler').returns(() => {}); + this.sandbox.stub(query, 'getAddOneMutateHandler').returns(() => null); + this.sandbox.stub(query, 'getUpdateOneMutateHandler').returns(() => null); const graphQLType = types.Qux; const fields = getMutationField({Qux: {model: {}}}, graphQLType); const args = { @@ -147,14 +147,14 @@ describe('schema', () => { this.sandbox.stub(type, 'getTypes').returns(types); }); - it('should return a GraphQL schema', function getSchemaTest() { + it('should return a GraphQL schema', () => { const schema = getSchema({}); expect(schema).instanceOf(GraphQLSchema); expect(schema._queryType.name).to.be.equal('RootQuery'); expect(schema._mutationType.name).to.be.equal('RootMutation'); }); - it('should return a GraphQL schema without mutations', function getSchemaTest() { + it('should return a GraphQL schema without mutations', () => { const schema = getSchema({}, {mutation: false}); expect(schema).instanceOf(GraphQLSchema); expect(schema._queryType.name).to.be.equal('RootQuery'); diff --git a/src/type/custom/buffer.js b/src/type/custom/buffer.js index ccafc73..cd26a42 100644 --- a/src/type/custom/buffer.js +++ b/src/type/custom/buffer.js @@ -16,7 +16,7 @@ export default new GraphQLScalarType({ parseValue: coerceBuffer, parseLiteral(ast) { if (ast.kind !== Kind.STRING) { - throw new GraphQLError('Query error: Can only parse strings to buffers but got a: ' + ast.kind, [ast]); + throw new GraphQLError(`Query error: Can only parse strings to buffers but got a: ${ast.kind}`, [ast]); } const result = new Buffer(ast.value); diff --git a/src/type/custom/buffer.spec.js b/src/type/custom/buffer.spec.js index 059191c..336f4a0 100644 --- a/src/type/custom/buffer.spec.js +++ b/src/type/custom/buffer.spec.js @@ -73,9 +73,7 @@ describe('GraphQL buffer type', () => { type: GraphQLBuffer } }, - resolve: (_, {bar}) => { - return new Buffer(bar.toString() + '-qux'); - } + resolve: (_, {bar}) => new Buffer(`${bar.toString()}-qux`) } } }) diff --git a/src/type/custom/date.js b/src/type/custom/date.js index c13c875..606d2eb 100644 --- a/src/type/custom/date.js +++ b/src/type/custom/date.js @@ -26,7 +26,7 @@ export default new GraphQLScalarType({ }, parseLiteral(ast) { if (ast.kind !== Kind.STRING) { - throw new GraphQLError('Query error: Can only parse strings to dates but got a: ' + ast.kind, [ast]); + throw new GraphQLError(`Query error: Can only parse strings to buffers but got a: ${ast.kind}`, [ast]); } const result = new Date(ast.value); diff --git a/src/type/custom/date.spec.js b/src/type/custom/date.spec.js index fe806a3..c1cc2f1 100644 --- a/src/type/custom/date.spec.js +++ b/src/type/custom/date.spec.js @@ -103,9 +103,7 @@ describe('GraphQL date type', () => { type: GraphQlDate } }, - resolve: (_, {date}) => { - return new Date(date.getTime() + 24 * 3600 * 1000); - } + resolve: (_, {date}) => new Date(date.getTime() + 24 * 3600 * 1000) } } }) diff --git a/src/type/custom/generic.js b/src/type/custom/generic.js index 53848a5..23046d6 100644 --- a/src/type/custom/generic.js +++ b/src/type/custom/generic.js @@ -12,7 +12,7 @@ export default new GraphQLScalarType({ parseValue: coerceDate, parseLiteral(ast) { if (ast.kind !== Kind.STRING) { - throw new GraphQLError('Query error: Can only parse strings to JSON but got a: ' + ast.kind, [ast]); + throw new GraphQLError(`Query error: Can only parse strings to buffers but got a: ${ast.kind}`, [ast]); } const json = ast.value.replace(/\'/g, '"'); diff --git a/src/type/custom/generic.spec.js b/src/type/custom/generic.spec.js index 56de8f2..1e9d58a 100644 --- a/src/type/custom/generic.spec.js +++ b/src/type/custom/generic.spec.js @@ -79,9 +79,7 @@ describe('GraphQL generic type', () => { type: GraphQLGeneric } }, - resolve: (_, {bar}) => { - return new Unknown(bar.field + '-qux'); - } + resolve: (_, {bar}) => new Unknown(`${bar.field}-qux`) } } }) diff --git a/src/type/type.js b/src/type/type.js index aee5682..7bf3c40 100644 --- a/src/type/type.js +++ b/src/type/type.js @@ -39,10 +39,10 @@ function addType(name, type) { } // Node interface -const {nodeInterface} = nodeDefinitions(null, (obj) => { +const {nodeInterface} = nodeDefinitions(null, (obj) => ( // Type resolver - return obj._type ? types[obj._type] : null; -}); + obj._type ? types[obj._type] : null +)); // GraphQL Viewer type const GraphQLViewer = new GraphQLObjectType({ @@ -245,9 +245,7 @@ export default function getType(graffitiModels, {name, description, fields}, pat } if (!graphQLField.resolve) { - graphQLField.resolve = addHooks((source) => { - return source[name]; - }, hooks); + graphQLField.resolve = addHooks((source) => source[name], hooks); } graphQLFields[name] = graphQLField; diff --git a/src/utils/Middleware.js b/src/utils/Middleware.js index b753102..07ed740 100644 --- a/src/utils/Middleware.js +++ b/src/utils/Middleware.js @@ -48,6 +48,6 @@ export default class Middleware { await fn.call(this, next, ...result); return lastResult; }; - }, () => {})(); + }, () => null)(); } }