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

Errors are serialized to {} #39

Open
ikari-pl opened this issue Dec 8, 2016 · 0 comments
Open

Errors are serialized to {} #39

ikari-pl opened this issue Dec 8, 2016 · 0 comments

Comments

@ikari-pl
Copy link

ikari-pl commented Dec 8, 2016

Overview of the Issue

Something I have seen in the koa adapter at least. When graphql promise returns an object with a list of errors, they are of the Error type (obviously), so they get/might get serialized to {} in the JSON response (which is worse).

Reproduce the Error

Provide an unambiguous set of steps, Node version, package version, etc.

Steps to reproduce:

  1. Have a bad graphql setup or something similar to my error which was "Schema must be an instance of GraphQLSchema. Also ensure that there are not multiple versions of GraphQL installed in your node_modules directory."
  2. get { "errors": [ {} ] } response

Node version: 7.0.0
Graffiti version: 3.2.0

Quick & dirty fix

The solution that I hacked for myself to see the error was something like changing in koa.js

this.body = yield graphql(schema, query, { request: this.request }, context, parsedVariables);

to

this.body = yield graphql(schema, query, { request: this.request }, context, parsedVariables)
                  .then((response) => {
                    if (response.errors) {
                      response.errors = response.errors.map((err) => err.message);
                    }
                    return response;
                  });

This is an ugly solution. I see the syntax errors are mapped elsewhere to something readable, but my error wasn't.

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

1 participant