Skip to content

GraphQLError does not contains variables and context. Additional error objects. #662

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

Open
nodkz opened this issue Jan 11, 2017 · 3 comments

Comments

@nodkz
Copy link
Contributor

nodkz commented Jan 11, 2017

I setup logging GraphQL errors on Sentry.io and got several issues with GraphQLError

1. Determining a type of the error:

RuntimeError (when resolvers throw errors on execution) or InvalidQuery (when provided invalid query). Right now I qualify a type of error via GraphQLError.pathproperty. If it is empty then I got InvalidQuery, if it is an array then RuntimeError.

What do you think about additional Error objects GraphQLRuntimeError, GraphQLInvalidQueryError (inherited from GraphQLError)?

2. Lack of context and variables in GraphQLError

Query I can get via GraphQLError.source.body, but did not found a proper way how to get variables and context.

Diving down to GraphQLError.nodes for obtaining variables is too complicated.

Passing context to formatError when defining express-graphql middleware is possible. But looks weird.

So will be cool if these properties somehow will be added to the GraphQLError.

@leebyron @schrockn what do you think about improving error object?


Some examples of error events which I got with my error catch setup for sentry.io

  • InvalidQuery example screen shot 2017-01-11 at 10 03 19
  • RuntimeError example screen shot 2017-01-11 at 10 32 26
@kirillgroshkov
Copy link

yes, I need it as well!

@samdenty
Copy link

samdenty commented May 18, 2018

For other people facing this issue, graphqlHTTP sends the variables in the params object:

const graphqlHTTP = require('express-graphql');
const {formatError} = require('graphql');

app.use('/', graphqlHTTP(function (req, res, params) {
    return {
        schema: Schema,
        graphiql: true,
        rootValue: {},
        context: buildContext(req),
        formatError: e => {
            const query = params.query;
            const variables = params.variables;
            console.log('Error!', query, JSON.stringify(variables, null, 2));
            return formatError(e);
       }
    };
}));```

@shinaBR2
Copy link

Do we have any further solution for Apollo-client?
:(

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants