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

Don't swallow all errors in graphql function #28

Closed
freiksenet opened this issue Jul 6, 2015 · 20 comments
Closed

Don't swallow all errors in graphql function #28

freiksenet opened this issue Jul 6, 2015 · 20 comments

Comments

@freiksenet
Copy link
Contributor

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!

@madjam002
Copy link

Yeah this would be useful. Maybe a dev flag which could be passed to the graphql function during dev which exposes stack traces as well as error messages?

@leebyron
Copy link
Contributor

leebyron commented Jul 6, 2015

Yeah, I feel this pain as well. I have a broader error handling refactor I need to do that should help this be less painful

@trobertsonsf
Copy link

👍 Really hard to debug ATM.

@johanatan
Copy link
Contributor

+1 on this.

@payneio
Copy link

payneio commented Aug 4, 2015

This is killing me.

@johanatan
Copy link
Contributor

in error/formatError.js I've added the line:

    stack: error.stack,

to the JSON returned and it has helped tremendously.

@rexxars
Copy link
Contributor

rexxars commented Aug 10, 2015

+1 for this

Thanks for the tip, @johanatan! Lifesaver!

@jsplink
Copy link

jsplink commented Aug 17, 2015

+1 good call johanastan

@mrjackdavis
Copy link

Now that #118 has been merged; what's the next step forward here? graphql/express-graphql#4 is closed but to my knowledge this issue is not resolved. How can we help?

@brokentone
Copy link

+1

@jeromecovington
Copy link

Has anybody patched this with #28 (comment) via @johanatan?

@vinerz
Copy link

vinerz commented Feb 16, 2016

+1, also, @johanatan, thanks a lot. I've already made a statue from you

@zuhair-naqvi
Copy link

+1

@tristanz
Copy link

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
  })

@leebyron
Copy link
Contributor

leebyron commented Apr 7, 2016

Closing this since graphql-js no longer formats Errors anymore (the errors field on the output is a list of the original Error instances now).

Formatting is still recommended when using over a web endpoint, and express-graphql does the simple thing by default and allows for customization.

@leebyron leebyron closed this as completed Apr 7, 2016
@luchillo17
Copy link

luchillo17 commented Feb 25, 2017

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));

@JanPeter
Copy link

JanPeter commented Sep 8, 2017

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?

@bkoltai
Copy link

bkoltai commented Oct 16, 2018

Agreed, how do we get a stack trace for the errors reported from using the graphql function directly, which I'm also doing in tests and get errors from my code with just the message and no trace.

@alfaproject
Copy link

Just stumbled upon this issue and not quite sure why is it closed. I only get the error title when invoking with graphql or execute...

@IvanGoncharov
Copy link
Member

@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));
  // ...
}

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

No branches or pull requests