diff --git a/packages/apollo-gateway/src/__tests__/__fixtures__/schemas/accounts.ts b/packages/apollo-gateway/src/__tests__/__fixtures__/schemas/accounts.ts index 375ea53b5e5..53fae843ce8 100644 --- a/packages/apollo-gateway/src/__tests__/__fixtures__/schemas/accounts.ts +++ b/packages/apollo-gateway/src/__tests__/__fixtures__/schemas/accounts.ts @@ -67,6 +67,13 @@ const users = [ username: '@complete', account: { __typename: 'SMSAccount', number: '8675309' }, }, + { + id: '3', + name: () => { throw new Error('Not Alan Not Turing') }, + birthDate: '1219-09-31', + username: '@incomplete', + account: { __typename: 'SMSAccount', number: '9035786' }, + }, ]; const metadata = [ @@ -78,6 +85,10 @@ const metadata = [ id: '2', metadata: [{ name: 'meta2', address: '3', description: '4' }], }, + { + id: '3', + metadata: [{ name: 'meta3', address: '5', description: '6' }], + }, ]; const libraryUsers: { [name: string]: string[] } = { diff --git a/packages/apollo-gateway/src/__tests__/__fixtures__/schemas/reviews.ts b/packages/apollo-gateway/src/__tests__/__fixtures__/schemas/reviews.ts index 69b8f58ef90..6408f4062bb 100644 --- a/packages/apollo-gateway/src/__tests__/__fixtures__/schemas/reviews.ts +++ b/packages/apollo-gateway/src/__tests__/__fixtures__/schemas/reviews.ts @@ -139,6 +139,12 @@ const reviews = [ product: { __typename: 'Book', isbn: '0201633612' }, body: 'A classic.', }, + { + id: '7', + authorID: '3', + product: { __typename: 'Furniture', isbn: '3' }, + body: 'Hmmm', + }, ]; export const resolvers: GraphQLResolverMap = { diff --git a/packages/apollo-gateway/src/__tests__/executeQueryPlan.test.ts b/packages/apollo-gateway/src/__tests__/executeQueryPlan.test.ts index cbf78b8ea5a..5973f1bbde9 100644 --- a/packages/apollo-gateway/src/__tests__/executeQueryPlan.test.ts +++ b/packages/apollo-gateway/src/__tests__/executeQueryPlan.test.ts @@ -210,6 +210,32 @@ describe('executeQueryPlan', () => { expect(response).toHaveProperty('data.me', null); expect(response).toHaveProperty('data.topReviews', expect.any(Array)); }); + + it.only(`should build proper path in case one of the services raised error field`, async () => { + const query = gql` + query { + topReviews(first: 10) { + author { + name + } + } + } + `; + + const operationContext = buildOperationContext(schema, query); + const queryPlan = buildQueryPlan(operationContext); + + const response = await executeQueryPlan( + queryPlan, + serviceMap, + buildRequestContext(), + operationContext, + ); + + expect(response).toHaveProperty('errors.0.path', ['topReviews', 7, 'author', 'name']) + expect(response).toHaveProperty('data.user', {name: null}); + expect(response).toHaveProperty('data.topReviews', expect.any(Array)); + }); }); it(`should only return fields that have been requested directly`, async () => {