graffiti
graffiti copied to clipboard
Errors are serialized to {}
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:
- 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."
- 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.