graffiti icon indicating copy to clipboard operation
graffiti copied to clipboard

Errors are serialized to {}

Open ikari-pl opened this issue 8 years ago • 0 comments

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.

ikari-pl avatar Dec 08 '16 10:12 ikari-pl