question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

passing `debug:true` has no effect in forcing the addition of the stacktrace into errors on NODE_ENV test.

See original GitHub issue

The 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

change https://github.com/apollographql/apollo-server/blob/master/packages/apollo-server-core/src/ApolloServer.ts#L840

    const requestCtx: GraphQLRequestContext = {
      logger: this.logger,

to

    const requestCtx: GraphQLRequestContext = {
      debug: options.debug,
      logger: this.logger,

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:10
  • Comments:10 (4 by maintainers)

github_iconTop GitHub Comments

2reactions
ibratoevcommented, Feb 23, 2021

After I dug a bit in the codebase, I would consider that a bug so I opened a PR with a fix.

1reaction
santialbocommented, Dec 16, 2020

@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

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to Add Stacktrace or debug Option when Building ...
Run with --info or --debug option to get more log output. I suspect it has something to do with resource not found error....
Read more >
Getting JSON error from message when app.debug=True #1231
Testing app.debug-True in tutorials send vancouver and get ... It appears the stack trace is not in response - according to Chrome Dev...
Read more >
Error handling - Apollo GraphQL Docs
Whenever Apollo Server encounters errors while processing a GraphQL operation, its response to the client includes an errors array containing each error that ......
Read more >
Java Stack Trace: How to Read and Understand to Debug Code
A Java stack trace is a very useful debugging tool. ... it's best to check first whether the error is caused by how...
Read more >
Reactor 3 Reference Guide
Learn how to handle errors in the Handling Errors section. Unit testing? Yes it is possible with the reactor-test project! See Testing.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found