Skip to content

Errors are serialized to {} #39

@ikari-pl

Description

@ikari-pl

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions