From f5ebf9ab6a9ad188e27f30d9b55d1e4d43863e81 Mon Sep 17 00:00:00 2001 From: Ivan Goncharov Date: Thu, 25 Jun 2020 17:32:46 +0300 Subject: [PATCH] Remove unnecessary async code --- src/__tests__/starWarsConnectionTests.js | 193 ++++++++---------- src/__tests__/starWarsMutationTests.js | 6 +- .../starWarsObjectIdentificationTests.js | 87 ++++---- src/connection/__tests__/connection.js | 101 +++++---- src/mutation/__tests__/mutation.js | 49 +++-- src/mutation/mutation.js | 20 +- src/node/__tests__/global.js | 34 +-- src/node/__tests__/node.js | 104 ++++------ src/node/node.js | 4 +- 9 files changed, 270 insertions(+), 328 deletions(-) diff --git a/src/__tests__/starWarsConnectionTests.js b/src/__tests__/starWarsConnectionTests.js index 5874085..afc1a91 100644 --- a/src/__tests__/starWarsConnectionTests.js +++ b/src/__tests__/starWarsConnectionTests.js @@ -3,10 +3,10 @@ import { expect } from 'chai'; import { describe, it } from 'mocha'; import { StarWarsSchema } from './starWarsSchema.js'; -import { graphql } from 'graphql'; +import { graphqlSync } from 'graphql'; describe('Star Wars connections', () => { - it('fetches the first ship of the rebels', async () => { + it('fetches the first ship of the rebels', () => { const query = ` query RebelsShipsQuery { rebels { @@ -21,25 +21,24 @@ describe('Star Wars connections', () => { } } `; - const expected = { - rebels: { - name: 'Alliance to Restore the Republic', - ships: { - edges: [ - { - node: { - name: 'X-Wing', + + expect(graphqlSync(StarWarsSchema, query)).to.deep.equal({ + data: { + rebels: { + name: 'Alliance to Restore the Republic', + ships: { + edges: [ + { + node: { name: 'X-Wing' }, }, - }, - ], + ], + }, }, }, - }; - const result = await graphql(StarWarsSchema, query); - expect(result).to.deep.equal({ data: expected }); + }); }); - it('fetches the first two ships of the rebels with a cursor', async () => { + it('fetches the first two ships of the rebels with a cursor', () => { const query = ` query MoreRebelShipsQuery { rebels { @@ -55,32 +54,29 @@ describe('Star Wars connections', () => { } } `; - const expected = { - rebels: { - name: 'Alliance to Restore the Republic', - ships: { - edges: [ - { - cursor: 'YXJyYXljb25uZWN0aW9uOjA=', - node: { - name: 'X-Wing', + + expect(graphqlSync(StarWarsSchema, query)).to.deep.equal({ + data: { + rebels: { + name: 'Alliance to Restore the Republic', + ships: { + edges: [ + { + cursor: 'YXJyYXljb25uZWN0aW9uOjA=', + node: { name: 'X-Wing' }, }, - }, - { - cursor: 'YXJyYXljb25uZWN0aW9uOjE=', - node: { - name: 'Y-Wing', + { + cursor: 'YXJyYXljb25uZWN0aW9uOjE=', + node: { name: 'Y-Wing' }, }, - }, - ], + ], + }, }, }, - }; - const result = await graphql(StarWarsSchema, query); - expect(result).to.deep.equal({ data: expected }); + }); }); - it('fetches the next three ships of the rebels with a cursor', async () => { + it('fetches the next three ships of the rebels with a cursor', () => { const query = ` query EndOfRebelShipsQuery { rebels { @@ -96,38 +92,33 @@ describe('Star Wars connections', () => { } } `; - const expected = { - rebels: { - name: 'Alliance to Restore the Republic', - ships: { - edges: [ - { - cursor: 'YXJyYXljb25uZWN0aW9uOjI=', - node: { - name: 'A-Wing', + + expect(graphqlSync(StarWarsSchema, query)).to.deep.equal({ + data: { + rebels: { + name: 'Alliance to Restore the Republic', + ships: { + edges: [ + { + cursor: 'YXJyYXljb25uZWN0aW9uOjI=', + node: { name: 'A-Wing' }, }, - }, - { - cursor: 'YXJyYXljb25uZWN0aW9uOjM=', - node: { - name: 'Millenium Falcon', + { + cursor: 'YXJyYXljb25uZWN0aW9uOjM=', + node: { name: 'Millenium Falcon' }, }, - }, - { - cursor: 'YXJyYXljb25uZWN0aW9uOjQ=', - node: { - name: 'Home One', + { + cursor: 'YXJyYXljb25uZWN0aW9uOjQ=', + node: { name: 'Home One' }, }, - }, - ], + ], + }, }, }, - }; - const result = await graphql(StarWarsSchema, query); - expect(result).to.deep.equal({ data: expected }); + }); }); - it('fetches no ships of the rebels at the end of connection', async () => { + it('fetches no ships of the rebels at the end of connection', () => { const query = ` query RebelsQuery { rebels { @@ -143,19 +134,20 @@ describe('Star Wars connections', () => { } } `; - const expected = { - rebels: { - name: 'Alliance to Restore the Republic', - ships: { - edges: [], + + expect(graphqlSync(StarWarsSchema, query)).to.deep.equal({ + data: { + rebels: { + name: 'Alliance to Restore the Republic', + ships: { + edges: [], + }, }, }, - }; - const result = await graphql(StarWarsSchema, query); - expect(result).to.deep.equal({ data: expected }); + }); }); - it('identifies the end of the list', async () => { + it('identifies the end of the list', () => { const query = ` query EndOfRebelShipsQuery { rebels { @@ -183,51 +175,38 @@ describe('Star Wars connections', () => { } } `; - const expected = { - rebels: { - name: 'Alliance to Restore the Republic', - originalShips: { - edges: [ - { - node: { - name: 'X-Wing', + + expect(graphqlSync(StarWarsSchema, query)).to.deep.equal({ + data: { + rebels: { + name: 'Alliance to Restore the Republic', + originalShips: { + edges: [ + { + node: { name: 'X-Wing' }, }, - }, - { - node: { - name: 'Y-Wing', + { + node: { name: 'Y-Wing' }, }, - }, - ], - pageInfo: { - hasNextPage: true, + ], + pageInfo: { hasNextPage: true }, }, - }, - moreShips: { - edges: [ - { - node: { - name: 'A-Wing', + moreShips: { + edges: [ + { + node: { name: 'A-Wing' }, }, - }, - { - node: { - name: 'Millenium Falcon', + { + node: { name: 'Millenium Falcon' }, }, - }, - { - node: { - name: 'Home One', + { + node: { name: 'Home One' }, }, - }, - ], - pageInfo: { - hasNextPage: false, + ], + pageInfo: { hasNextPage: false }, }, }, }, - }; - const result = await graphql(StarWarsSchema, query); - expect(result).to.deep.equal({ data: expected }); + }); }); }); diff --git a/src/__tests__/starWarsMutationTests.js b/src/__tests__/starWarsMutationTests.js index 8d76c24..08ca26f 100644 --- a/src/__tests__/starWarsMutationTests.js +++ b/src/__tests__/starWarsMutationTests.js @@ -3,10 +3,10 @@ import { expect } from 'chai'; import { describe, it } from 'mocha'; import { StarWarsSchema } from './starWarsSchema.js'; -import { graphql } from 'graphql'; +import { graphqlSync } from 'graphql'; describe('Star Wars mutations', () => { - it('mutates the data set', async () => { + it('mutates the data set', () => { const mutation = ` mutation AddBWingQuery($input: IntroduceShipInput!) { introduceShip(input: $input) { @@ -40,7 +40,7 @@ describe('Star Wars mutations', () => { clientMutationId: 'abcde', }, }; - const result = await graphql(StarWarsSchema, mutation, null, null, params); + const result = graphqlSync(StarWarsSchema, mutation, null, null, params); expect(result).to.deep.equal({ data: expected }); }); }); diff --git a/src/__tests__/starWarsObjectIdentificationTests.js b/src/__tests__/starWarsObjectIdentificationTests.js index 46e1e97..975f79d 100644 --- a/src/__tests__/starWarsObjectIdentificationTests.js +++ b/src/__tests__/starWarsObjectIdentificationTests.js @@ -3,10 +3,10 @@ import { expect } from 'chai'; import { describe, it } from 'mocha'; import { StarWarsSchema } from './starWarsSchema.js'; -import { graphql } from 'graphql'; +import { graphqlSync } from 'graphql'; describe('Star Wars object identification', () => { - it('fetches the ID and name of the rebels', async () => { + it('fetches the ID and name of the rebels', () => { const query = ` query RebelsQuery { rebels { @@ -15,17 +15,18 @@ describe('Star Wars object identification', () => { } } `; - const expected = { - rebels: { - id: 'RmFjdGlvbjox', - name: 'Alliance to Restore the Republic', + + expect(graphqlSync(StarWarsSchema, query)).to.deep.equal({ + data: { + rebels: { + id: 'RmFjdGlvbjox', + name: 'Alliance to Restore the Republic', + }, }, - }; - const result = await graphql(StarWarsSchema, query); - expect(result).to.deep.equal({ data: expected }); + }); }); - it('refetches the rebels', async () => { + it('refetches the rebels', () => { const query = ` query RebelsRefetchQuery { node(id: "RmFjdGlvbjox") { @@ -36,17 +37,18 @@ describe('Star Wars object identification', () => { } } `; - const expected = { - node: { - id: 'RmFjdGlvbjox', - name: 'Alliance to Restore the Republic', + + expect(graphqlSync(StarWarsSchema, query)).to.deep.equal({ + data: { + node: { + id: 'RmFjdGlvbjox', + name: 'Alliance to Restore the Republic', + }, }, - }; - const result = await graphql(StarWarsSchema, query); - expect(result).to.deep.equal({ data: expected }); + }); }); - it('fetches the ID and name of the empire', async () => { + it('fetches the ID and name of the empire', () => { const query = ` query EmpireQuery { empire { @@ -55,17 +57,18 @@ describe('Star Wars object identification', () => { } } `; - const expected = { - empire: { - id: 'RmFjdGlvbjoy', - name: 'Galactic Empire', + + expect(graphqlSync(StarWarsSchema, query)).to.deep.equal({ + data: { + empire: { + id: 'RmFjdGlvbjoy', + name: 'Galactic Empire', + }, }, - }; - const result = await graphql(StarWarsSchema, query); - expect(result).to.deep.equal({ data: expected }); + }); }); - it('refetches the empire', async () => { + it('refetches the empire', () => { const query = ` query EmpireRefetchQuery { node(id: "RmFjdGlvbjoy") { @@ -76,17 +79,18 @@ describe('Star Wars object identification', () => { } } `; - const expected = { - node: { - id: 'RmFjdGlvbjoy', - name: 'Galactic Empire', + + expect(graphqlSync(StarWarsSchema, query)).to.deep.equal({ + data: { + node: { + id: 'RmFjdGlvbjoy', + name: 'Galactic Empire', + }, }, - }; - const result = await graphql(StarWarsSchema, query); - expect(result).to.deep.equal({ data: expected }); + }); }); - it('refetches the X-Wing', async () => { + it('refetches the X-Wing', () => { const query = ` query XWingRefetchQuery { node(id: "U2hpcDox") { @@ -97,13 +101,14 @@ describe('Star Wars object identification', () => { } } `; - const expected = { - node: { - id: 'U2hpcDox', - name: 'X-Wing', + + expect(graphqlSync(StarWarsSchema, query)).to.deep.equal({ + data: { + node: { + id: 'U2hpcDox', + name: 'X-Wing', + }, }, - }; - const result = await graphql(StarWarsSchema, query); - expect(result).to.deep.equal({ data: expected }); + }); }); }); diff --git a/src/connection/__tests__/connection.js b/src/connection/__tests__/connection.js index c43de6e..5b6be08 100644 --- a/src/connection/__tests__/connection.js +++ b/src/connection/__tests__/connection.js @@ -5,7 +5,7 @@ import { GraphQLObjectType, GraphQLSchema, GraphQLString, - graphql, + graphqlSync, } from 'graphql'; import { connectionFromArray } from '../arrayconnection.js'; @@ -90,7 +90,7 @@ const schema = new GraphQLSchema({ }); describe('connectionDefinition()', () => { - it('includes connection and edge fields', async () => { + it('includes connection and edge fields', () => { const query = ` query FriendsQuery { user { @@ -106,32 +106,29 @@ describe('connectionDefinition()', () => { } } `; - const expected = { - user: { - friends: { - totalCount: 4, - edges: [ - { - friendshipTime: 'Yesterday', - node: { - name: 'Nick', + + expect(graphqlSync(schema, query)).to.deep.equal({ + data: { + user: { + friends: { + totalCount: 4, + edges: [ + { + friendshipTime: 'Yesterday', + node: { name: 'Nick' }, }, - }, - { - friendshipTime: 'Yesterday', - node: { - name: 'Lee', + { + friendshipTime: 'Yesterday', + node: { name: 'Lee' }, }, - }, - ], + ], + }, }, }, - }; - const result = await graphql(schema, query); - expect(result).to.deep.equal({ data: expected }); + }); }); - it('works with forwardConnectionArgs', async () => { + it('works with forwardConnectionArgs', () => { const query = ` query FriendsQuery { user { @@ -145,29 +142,26 @@ describe('connectionDefinition()', () => { } } `; - const expected = { - user: { - friendsForward: { - edges: [ - { - node: { - name: 'Nick', + + expect(graphqlSync(schema, query)).to.deep.equal({ + data: { + user: { + friendsForward: { + edges: [ + { + node: { name: 'Nick' }, }, - }, - { - node: { - name: 'Lee', + { + node: { name: 'Lee' }, }, - }, - ], + ], + }, }, }, - }; - const result = await graphql(schema, query); - expect(result).to.deep.equal({ data: expected }); + }); }); - it('works with backwardConnectionArgs', async () => { + it('works with backwardConnectionArgs', () => { const query = ` query FriendsQuery { user { @@ -181,25 +175,22 @@ describe('connectionDefinition()', () => { } } `; - const expected = { - user: { - friendsBackward: { - edges: [ - { - node: { - name: 'Joe', + + expect(graphqlSync(schema, query)).to.deep.equal({ + data: { + user: { + friendsBackward: { + edges: [ + { + node: { name: 'Joe' }, }, - }, - { - node: { - name: 'Tim', + { + node: { name: 'Tim' }, }, - }, - ], + ], + }, }, }, - }; - const result = await graphql(schema, query); - expect(result).to.deep.equal({ data: expected }); + }); }); }); diff --git a/src/mutation/__tests__/mutation.js b/src/mutation/__tests__/mutation.js index 0300a5b..a8f201a 100644 --- a/src/mutation/__tests__/mutation.js +++ b/src/mutation/__tests__/mutation.js @@ -3,7 +3,13 @@ import { describe, it } from 'mocha'; import { expect } from 'chai'; -import { GraphQLInt, GraphQLObjectType, GraphQLSchema, graphql } from 'graphql'; +import { + GraphQLInt, + GraphQLObjectType, + GraphQLSchema, + graphql, + graphqlSync, +} from 'graphql'; import { mutationWithClientMutationId } from '../mutation'; @@ -104,7 +110,7 @@ const schema = new GraphQLSchema({ }); describe('mutationWithClientMutationId()', () => { - it('requires an argument', async () => { + it('requires an argument', () => { const query = ` mutation M { simpleMutation { @@ -112,7 +118,8 @@ describe('mutationWithClientMutationId()', () => { } } `; - expect(await graphql(schema, query)).to.deep.equal({ + + expect(graphqlSync(schema, query)).to.deep.equal({ errors: [ { message: @@ -123,7 +130,7 @@ describe('mutationWithClientMutationId()', () => { }); }); - it('returns the same client mutation ID', async () => { + it('returns the same client mutation ID', () => { const query = ` mutation M { simpleMutation(input: {clientMutationId: "abc"}) { @@ -133,7 +140,7 @@ describe('mutationWithClientMutationId()', () => { } `; - expect(await graphql(schema, query)).to.deep.equal({ + expect(graphqlSync(schema, query)).to.deep.equal({ data: { simpleMutation: { result: 1, @@ -143,7 +150,7 @@ describe('mutationWithClientMutationId()', () => { }); }); - it('supports thunks as input and output fields', async () => { + it('supports thunks as input and output fields', () => { const query = ` mutation M { simpleMutationWithThunkFields(input: { @@ -156,7 +163,7 @@ describe('mutationWithClientMutationId()', () => { } `; - expect(await graphql(schema, query)).to.deep.equal({ + expect(graphqlSync(schema, query)).to.deep.equal({ data: { simpleMutationWithThunkFields: { result: 1234, @@ -186,7 +193,7 @@ describe('mutationWithClientMutationId()', () => { }); }); - it('can access rootValue', async () => { + it('can access rootValue', () => { const query = ` mutation M { simpleRootValueMutation(input: {clientMutationId: "abc"}) { @@ -196,7 +203,7 @@ describe('mutationWithClientMutationId()', () => { } `; - expect(await graphql(schema, query, { result: 1 })).to.deep.equal({ + expect(graphqlSync(schema, query, { result: 1 })).to.deep.equal({ data: { simpleRootValueMutation: { result: 1, @@ -206,7 +213,7 @@ describe('mutationWithClientMutationId()', () => { }); }); - it('supports mutations returning null', async () => { + it('supports mutations returning null', () => { const query = ` mutation M { simpleRootValueMutation(input: {clientMutationId: "abc"}) { @@ -216,7 +223,7 @@ describe('mutationWithClientMutationId()', () => { } `; - expect(await graphql(schema, query, null)).to.deep.equal({ + expect(graphqlSync(schema, query, null)).to.deep.equal({ data: { simpleRootValueMutation: { result: null, @@ -227,7 +234,7 @@ describe('mutationWithClientMutationId()', () => { }); describe('introspection', () => { - it('contains correct input', async () => { + it('contains correct input', () => { const query = ` { __type(name: "SimpleMutationInput") { @@ -244,7 +251,7 @@ describe('mutationWithClientMutationId()', () => { } `; - expect(await graphql(schema, query)).to.deep.equal({ + expect(graphqlSync(schema, query)).to.deep.equal({ data: { __type: { name: 'SimpleMutationInput', @@ -263,7 +270,7 @@ describe('mutationWithClientMutationId()', () => { }); }); - it('contains correct payload', async () => { + it('contains correct payload', () => { const query = ` { __type(name: "SimpleMutationPayload") { @@ -280,7 +287,7 @@ describe('mutationWithClientMutationId()', () => { } `; - expect(await graphql(schema, query)).to.deep.equal({ + expect(graphqlSync(schema, query)).to.deep.equal({ data: { __type: { name: 'SimpleMutationPayload', @@ -306,7 +313,7 @@ describe('mutationWithClientMutationId()', () => { }); }); - it('contains correct field', async () => { + it('contains correct field', () => { const query = ` { __schema { @@ -334,7 +341,7 @@ describe('mutationWithClientMutationId()', () => { } `; - expect(await graphql(schema, query)).to.deep.equal({ + expect(graphqlSync(schema, query)).to.deep.equal({ data: { __schema: { mutationType: { @@ -446,7 +453,7 @@ describe('mutationWithClientMutationId()', () => { }); }); - it('contains correct descriptions', async () => { + it('contains correct descriptions', () => { const query = ` { __schema { @@ -460,7 +467,7 @@ describe('mutationWithClientMutationId()', () => { } `; - expect(await graphql(schema, query)).to.deep.equal({ + expect(graphqlSync(schema, query)).to.deep.equal({ data: { __schema: { mutationType: { @@ -492,7 +499,7 @@ describe('mutationWithClientMutationId()', () => { }); }); - it('contains correct deprecation reasons', async () => { + it('contains correct deprecation reasons', () => { const query = ` { __schema { @@ -507,7 +514,7 @@ describe('mutationWithClientMutationId()', () => { } `; - expect(await graphql(schema, query)).to.deep.equal({ + expect(graphqlSync(schema, query)).to.deep.equal({ data: { __schema: { mutationType: { diff --git a/src/mutation/mutation.js b/src/mutation/mutation.js index d630129..6fd59b1 100644 --- a/src/mutation/mutation.js +++ b/src/mutation/mutation.js @@ -96,12 +96,18 @@ export function mutationWithClientMutationId( args: { input: { type: new GraphQLNonNull(inputType) }, }, - resolve: (_, { input }, context, info) => - Promise.resolve(mutateAndGetPayload(input, context, info)).then( - (payload) => ({ - ...payload, - clientMutationId: input.clientMutationId, - }), - ), + resolve: (_, { input }, context, info) => { + const { clientMutationId } = input; + const payload = mutateAndGetPayload(input, context, info); + if (isPromise(payload)) { + return payload.then((data) => ({ ...data, clientMutationId })); + } + + return { ...payload, clientMutationId }; + }, }; } + +function isPromise(value: any): boolean { + return typeof value?.then === 'function'; +} diff --git a/src/node/__tests__/global.js b/src/node/__tests__/global.js index 8a7ded9..51d74d4 100644 --- a/src/node/__tests__/global.js +++ b/src/node/__tests__/global.js @@ -9,7 +9,7 @@ import { GraphQLObjectType, GraphQLSchema, GraphQLString, - graphql, + graphqlSync, } from 'graphql'; import { fromGlobalId, globalIdField, nodeDefinitions } from '../node'; @@ -130,7 +130,7 @@ const schema = new GraphQLSchema({ }); describe('global ID fields', () => { - it('gives different IDs', async () => { + it('gives different IDs', () => { const query = ` { allObjects { @@ -139,33 +139,21 @@ describe('global ID fields', () => { } `; - expect(await graphql(schema, query)).to.deep.equal({ + expect(graphqlSync(schema, query)).to.deep.equal({ data: { allObjects: [ - { - id: 'VXNlcjox', - }, - { - id: 'VXNlcjoy', - }, - { - id: 'UGhvdG86MQ==', - }, - { - id: 'UGhvdG86Mg==', - }, - { - id: 'UG9zdDox', - }, - { - id: 'UG9zdDoy', - }, + { id: 'VXNlcjox' }, + { id: 'VXNlcjoy' }, + { id: 'UGhvdG86MQ==' }, + { id: 'UGhvdG86Mg==' }, + { id: 'UG9zdDox' }, + { id: 'UG9zdDoy' }, ], }, }); }); - it('refetches the IDs', async () => { + it('refetches the IDs', () => { const query = ` { user: node(id: "VXNlcjox") { @@ -189,7 +177,7 @@ describe('global ID fields', () => { } `; - expect(await graphql(schema, query)).to.deep.equal({ + expect(graphqlSync(schema, query)).to.deep.equal({ data: { user: { id: 'VXNlcjox', diff --git a/src/node/__tests__/node.js b/src/node/__tests__/node.js index 9e319de..ab4f113 100644 --- a/src/node/__tests__/node.js +++ b/src/node/__tests__/node.js @@ -10,7 +10,7 @@ import { GraphQLObjectType, GraphQLSchema, GraphQLString, - graphql, + graphqlSync, } from 'graphql'; import { nodeDefinitions } from '../node'; @@ -98,7 +98,7 @@ const schema = new GraphQLSchema({ describe('Node interface and fields', () => { describe('refetchability', () => { - it('gets the correct ID for users', async () => { + it('gets the correct ID for users', () => { const query = ` { node(id: "1") { @@ -107,16 +107,14 @@ describe('Node interface and fields', () => { } `; - expect(await graphql(schema, query)).to.deep.equal({ + expect(graphqlSync(schema, query)).to.deep.equal({ data: { - node: { - id: '1', - }, + node: { id: '1' }, }, }); }); - it('gets the correct IDs for users', async () => { + it('gets the correct IDs for users', () => { const query = ` { nodes(ids: ["1", "2"]) { @@ -125,21 +123,14 @@ describe('Node interface and fields', () => { } `; - expect(await graphql(schema, query)).to.deep.equal({ + expect(graphqlSync(schema, query)).to.deep.equal({ data: { - nodes: [ - { - id: '1', - }, - { - id: '2', - }, - ], + nodes: [{ id: '1' }, { id: '2' }], }, }); }); - it('gets the correct ID for photos', async () => { + it('gets the correct ID for photos', () => { const query = ` { node(id: "4") { @@ -148,16 +139,14 @@ describe('Node interface and fields', () => { } `; - expect(await graphql(schema, query)).to.deep.equal({ + expect(graphqlSync(schema, query)).to.deep.equal({ data: { - node: { - id: '4', - }, + node: { id: '4' }, }, }); }); - it('gets the correct IDs for photos', async () => { + it('gets the correct IDs for photos', () => { const query = ` { nodes(ids: ["3", "4"]) { @@ -166,21 +155,14 @@ describe('Node interface and fields', () => { } `; - expect(await graphql(schema, query)).to.deep.equal({ + expect(graphqlSync(schema, query)).to.deep.equal({ data: { - nodes: [ - { - id: '3', - }, - { - id: '4', - }, - ], + nodes: [{ id: '3' }, { id: '4' }], }, }); }); - it('gets the correct IDs for multiple types', async () => { + it('gets the correct IDs for multiple types', () => { const query = ` { nodes(ids: ["1", "3"]) { @@ -189,21 +171,14 @@ describe('Node interface and fields', () => { } `; - expect(await graphql(schema, query)).to.deep.equal({ + expect(graphqlSync(schema, query)).to.deep.equal({ data: { - nodes: [ - { - id: '1', - }, - { - id: '3', - }, - ], + nodes: [{ id: '1' }, { id: '3' }], }, }); }); - it('gets the correct name for users', async () => { + it('gets the correct name for users', () => { const query = ` { node(id: "1") { @@ -215,7 +190,7 @@ describe('Node interface and fields', () => { } `; - expect(await graphql(schema, query)).to.deep.equal({ + expect(graphqlSync(schema, query)).to.deep.equal({ data: { node: { id: '1', @@ -225,7 +200,7 @@ describe('Node interface and fields', () => { }); }); - it('gets the correct width for photos', async () => { + it('gets the correct width for photos', () => { const query = ` { node(id: "4") { @@ -237,7 +212,7 @@ describe('Node interface and fields', () => { } `; - expect(await graphql(schema, query)).to.deep.equal({ + expect(graphqlSync(schema, query)).to.deep.equal({ data: { node: { id: '4', @@ -247,7 +222,7 @@ describe('Node interface and fields', () => { }); }); - it('gets the correct type name for users', async () => { + it('gets the correct type name for users', () => { const query = ` { node(id: "1") { @@ -257,7 +232,7 @@ describe('Node interface and fields', () => { } `; - expect(await graphql(schema, query)).to.deep.equal({ + expect(graphqlSync(schema, query)).to.deep.equal({ data: { node: { id: '1', @@ -267,7 +242,7 @@ describe('Node interface and fields', () => { }); }); - it('gets the correct type name for photos', async () => { + it('gets the correct type name for photos', () => { const query = ` { node(id: "4") { @@ -277,7 +252,7 @@ describe('Node interface and fields', () => { } `; - expect(await graphql(schema, query)).to.deep.equal({ + expect(graphqlSync(schema, query)).to.deep.equal({ data: { node: { id: '4', @@ -287,7 +262,7 @@ describe('Node interface and fields', () => { }); }); - it('ignores photo fragments on user', async () => { + it('ignores photo fragments on user', () => { const query = ` { node(id: "1") { @@ -299,16 +274,14 @@ describe('Node interface and fields', () => { } `; - expect(await graphql(schema, query)).to.deep.equal({ + expect(graphqlSync(schema, query)).to.deep.equal({ data: { - node: { - id: '1', - }, + node: { id: '1' }, }, }); }); - it('returns null for bad IDs', async () => { + it('returns null for bad IDs', () => { const query = ` { node(id: "5") { @@ -317,14 +290,14 @@ describe('Node interface and fields', () => { } `; - expect(await graphql(schema, query)).to.deep.equal({ + expect(graphqlSync(schema, query)).to.deep.equal({ data: { node: null, }, }); }); - it('returns nulls for bad IDs', async () => { + it('returns nulls for bad IDs', () => { const query = ` { nodes(ids: ["3", "5"]) { @@ -333,21 +306,16 @@ describe('Node interface and fields', () => { } `; - expect(await graphql(schema, query)).to.deep.equal({ + expect(graphqlSync(schema, query)).to.deep.equal({ data: { - nodes: [ - { - id: '3', - }, - null, - ], + nodes: [{ id: '3' }, null], }, }); }); }); describe('introspection', () => { - it('has correct node interface', async () => { + it('has correct node interface', () => { const query = ` { __type(name: "Node") { @@ -367,7 +335,7 @@ describe('Node interface and fields', () => { } `; - expect(await graphql(schema, query)).to.deep.equal({ + expect(graphqlSync(schema, query)).to.deep.equal({ data: { __type: { name: 'Node', @@ -389,7 +357,7 @@ describe('Node interface and fields', () => { }); }); - it('has correct node and nodes root fields', async () => { + it('has correct node and nodes root fields', () => { const query = ` { __schema { @@ -416,7 +384,7 @@ describe('Node interface and fields', () => { } `; - expect(await graphql(schema, query)).to.deep.equal({ + expect(graphqlSync(schema, query)).to.deep.equal({ data: { __schema: { queryType: { diff --git a/src/node/node.js b/src/node/node.js index 64381e9..d752b95 100644 --- a/src/node/node.js +++ b/src/node/node.js @@ -71,9 +71,7 @@ export function nodeDefinitions( }, }, resolve: (_obj, { ids }, context, info) => - Promise.all( - ids.map((id) => Promise.resolve(idFetcher(id, context, info))), - ), + ids.map((id) => idFetcher(id, context, info)), }; return { nodeInterface, nodeField, nodesField };