graphql-js: Don't swallow all errors in graphql function

There seems to be no way to get errors out of graphql function and one only gets error title, which can be the dreaded undefined is not a function deep inside schema or resolve. Would be nice if there’d be a flag to let errors pass through from graphql function, when they are not validation errors. I’d be willing to implement it if this change makes sense.

Thanks!

About this issue

  • Original URL
  • State: closed
  • Created 9 years ago
  • Reactions: 1
  • Comments: 20 (6 by maintainers)

Most upvoted comments

Using formatError as well, is there a way to pass the same error handler when using in testing? (in tests you most of the time query directly using the graphql object to execute the query with the schema.

import {
  graphql,
} from 'graphql';
...
let resp = (await graphql(Schema, query, {}, context));

This seems to be fixed here: https://github.com/graphql/express-graphql/pull/45/files

  graphiql: true,
  formatError: (error) => ({
    message: error.message,
    details: config.isProduction ? null : error.stack
  })

@bkoltai @alfaproject You can access original errors and their stack traces, like that:

const result = await execute(/* ... */);
if (result.errors) {
  result.errors.forEach(err => console.log(err.originalError));
  // ...
}

I have currently the same problem. I’m not quite sure how to test my custom error messages. Or is it better to test the whole express-graphql endpoint for the error messages?

👍 Really hard to debug ATM.