passing `debug:true` has no effect in forcing the addition of the stacktrace into errors on NODE_ENV test.
See original GitHub issueThe problem
new ApolloServer({ …, debug: true })
should have forced enabling the stacktrace in NODE_ENV=test. It does not work though. Adding it to the ApolloServer used in tests
The code I am using
In my mocks.ts file which I use for tests, I have this function:
import { ApolloServerTestClient, createTestClient } from "apollo-server-testing";
//...
export function createTestApolloServer({
dataSources = {},
...customContextParams
}: MockContextParams = {}): ApolloServerTestClient {
const server = new ApolloServer({
schema,
dataSources: (): DataSources => mockDataSources(dataSources),
context: (): CustomContext => mockCustomContext(customContextParams),
debug: true,
});
return createTestClient(server);
}
the debug: true
doesn’t have any effect, and I still didn’t get the exception stacktrace, until I patched apollo-server-core in node_modules (see the solutions section)
Where seems to be the problem
I have tracked down the problem to apollo-server-core
in the current version.
The call to formatApolloError
in https://github.com/apollographql/apollo-server/blob/71361880b6ba284ee8d16d5091945a999b005703/packages/apollo-server-core/src/requestPipeline.ts#L567 uses requestContext.debug
.
While the type accepts an optional debug
boolean field, it is never added in the creation of requestContext https://github.com/apollographql/apollo-server/blob/master/packages/apollo-server-core/src/ApolloServer.ts#L840
The solution could be either to use the debug
from the config, or to add the debug
into the requestContext.
Why I haven’t opened a PR directly
I do not have enough knowledge of the roles that both config and requestContext have to make a decision on what is the best approach.
Possible solutions
Possible solution 1: Use the debug from config:
change this line https://github.com/apollographql/apollo-server/blob/71361880b6ba284ee8d16d5091945a999b005703/packages/apollo-server-core/src/requestPipeline.ts#L567 to be
debug: config.debug,
Possible solution 2: Add debug to requestContext
const requestCtx: GraphQLRequestContext = {
logger: this.logger,
to
const requestCtx: GraphQLRequestContext = {
debug: options.debug,
logger: this.logger,
Issue Analytics
- State:
- Created 3 years ago
- Reactions:10
- Comments:10 (4 by maintainers)
Top GitHub Comments
After I dug a bit in the codebase, I would consider that a bug so I opened a PR with a fix.
@jtomaszewski I recommend you have a look at https://www.npmjs.com/package/patch-package It allows you to do the same in a more maintainable way less susceptible to errors. I use it when having issues like this with other libraries