Skip to content

Commit

Permalink
fix: executeOperation passes the debug option (#4948)
Browse files Browse the repository at this point in the history
Fix the ApolloServerBase.executeOperation to pass the debug option in
the request context.
This change resolves an issue with `apollo-server-testing` that does not
return stacktraces with debug option enabled.
Add 2 unit tests with and without the debug option.

fixes #4107

Co-authored-by: David Glasser <glasser@apollographql.com>
  • Loading branch information
ibratoev and glasser authored Feb 23, 2021
1 parent f4dc23b commit 9c0129d
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 0 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ The version headers in this history reflect the versions of Apollo Server itself

> The changes noted within this `vNEXT` section have not been released yet. New PRs and commits which introduce changes should include an entry in this `vNEXT` section as part of their development. With few exceptions, the format of the entry should follow convention (i.e., prefix with package name, use markdown `backtick formatting` for package names and code, suffix with a link to the change-set à la `[PR #YYY](https://link/pull/YYY)`, etc.). When a release is being prepared, a new header will be (manually) created below and the appropriate changes within that release will be moved into the new section.
- The `debug` option to `new ApolloServer` (which adds stack traces to errors) now affects errors that come from requests executed with `server.executeOperation` (and its wrapper `apollo-server-testing`), instead of just errors that come from requests executed over HTTP. [Issue #4107](https://github.com/apollographql/apollo-server/issues/4107) [PR #4948](https://github.com/apollographql/apollo-server/pull/4948)

## v2.21.0

- Apollo Server can now be installed with `graphql@15` without causing peer dependency errors or warnings. (Apollo Server has a [file upload](https://www.apollographql.com/docs/apollo-server/data/file-uploads/) feature which was implemented as a wrapper around the `graphql-upload` package. We have been unable to upgrade our dependency on that package due to backwards-incompatible changes in later versions, and the version we were stuck on did not allow `graphql@15` as a peer dependency. We have now switched to a fork of that old version called `@apollographql/graphql-upload-8-fork` that allows `graphql@15`.) Also bump the `graphql-tools` dependency from 4.0.0 to 4.0.8 for `graphql@15` support. [Issue #4865](https://github.com/apollographql/apollo-server/issues/4865)
Expand Down
1 change: 1 addition & 0 deletions packages/apollo-server-core/src/ApolloServer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1015,6 +1015,7 @@ export class ApolloServerBase {
headers: new Headers(),
},
},
debug: options.debug,
};

return processGraphQLRequest(options, requestCtx);
Expand Down
34 changes: 34 additions & 0 deletions packages/apollo-server-core/src/__tests__/ApolloServerBase.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { Logger } from 'apollo-server-types';
const typeDefs = gql`
type Query {
hello: String
error: Boolean
}
`;

Expand All @@ -14,6 +15,9 @@ const resolvers = {
hello() {
return 'world';
},
error() {
throw new Error('A test error');
},
},
};

Expand Down Expand Up @@ -97,6 +101,36 @@ describe('ApolloServerBase construction', () => {
});
});

describe('ApolloServerBase executeOperation', () => {
it('returns error information without details by default', async () => {
const server = new ApolloServerBase({
typeDefs,
resolvers,
});

const result = await server.executeOperation({ query: 'query { error }' });

expect(result.errors).toHaveLength(1);
expect(result.errors?.[0].extensions).toStrictEqual({
code: 'INTERNAL_SERVER_ERROR',
});
});

it('returns error information with details when debug is enabled', async () => {
const server = new ApolloServerBase({
typeDefs,
resolvers,
debug: true,
});

const result = await server.executeOperation({ query: 'query { error }' });

expect(result.errors).toHaveLength(1);
expect(result.errors?.[0].extensions?.code).toBe('INTERNAL_SERVER_ERROR');
expect(result.errors?.[0].extensions?.exception?.stacktrace).toBeDefined();
});
});

describe('environment variables', () => {
const OLD_ENV = process.env;

Expand Down

0 comments on commit 9c0129d

Please sign in to comment.