Skip to content

Commit

Permalink
feat: introduce failing tests for nested services path building
Browse files Browse the repository at this point in the history
  • Loading branch information
mpospelov committed Jun 3, 2020
1 parent 02f1fb6 commit cd9cc24
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [
Expand All @@ -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[] } = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<any> = {
Expand Down
26 changes: 26 additions & 0 deletions packages/apollo-gateway/src/__tests__/executeQueryPlan.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 () => {
Expand Down

0 comments on commit cd9cc24

Please sign in to comment.