Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: executeOperation passes the debug option #4948

Merged
merged 2 commits into from
Feb 23, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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