Skip to content

Response containing errors parsing variables is nested twice #40

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

Closed
schwma opened this issue Jan 18, 2023 · 3 comments · Fixed by #45
Closed

Response containing errors parsing variables is nested twice #40

schwma opened this issue Jan 18, 2023 · 3 comments · Fixed by #45
Labels
bug Something isn't working released Has been released and published

Comments

@schwma
Copy link

schwma commented Jan 18, 2023

Screenshot
Screenshot 2023-01-18 at 13 28 46

Expected Behaviour
I expected the error response to be structured like this:

{
    "errors": [
        {
            "locations": [
                {
                    "column": 8,
                    "line": 1
                }
            ],
            "message": "Variable \"$input\" got invalid value \"foo\"; Int cannot represent non-integer value: \"foo\""
        }
    ]
}

Actual Behaviour
but instead it was nested twice like so:

{
    "errors": [
        {
            "errors": [
                {
                    "locations": [
                        {
                            "column": 8,
                            "line": 1
                        }
                    ],
                    "message": "Variable \"$input\" got invalid value \"foo\"; Int cannot represent non-integer value: \"foo\""
                }
            ]
        }
    ]
}

Debug Information
Minimal example to reproduce:

Code:

const { GraphQLSchema, GraphQLObjectType, GraphQLInt } = require("graphql");

const express = require("express");
const { createHandler } = require("graphql-http/lib/use/express");

const schema = new GraphQLSchema({
  query: new GraphQLObjectType({
    name: "Query",
    fields: {
      hello: {
        type: GraphQLInt,
        args: {
          input: {
            type: GraphQLInt,
          },
        },
      },
    },
  }),
});

const app = express();
app.all("/graphql", createHandler({ schema }));

app.listen({ port: 4000 });
console.log("Listening to port 4000");

Send a query such as:

query ($input: Int) {
  hello(input: $input)
}

with variables:

{ "input": "foo" }

At first glance after briefly debugging it appears as though the error is here in the makeResponse function.

Further Information
The nesting format shown above under the "Expected Behaviour" section is the response that is returned by other GraphQL server frameworks such as express-graphql and graphql-yoga. Other errors returned by graphql-http are also not nested twice, such as when sending the following query against the example above.

Query

{
  hello(input: "foo")
}

Response:

{
    "errors": [
        {
            "locations": [
                {
                    "column": 16,
                    "line": 1
                }
            ],
            "message": "Int cannot represent non-integer value: \"foo\""
        }
    ]
}
@enisdenjo
Copy link
Member

hey @schwma thank you for reporting this, IDK how we've missed this! A fix will be released soon.

@enisdenjo enisdenjo added the bug Something isn't working label Jan 20, 2023
@enisdenjo
Copy link
Member

🎉 This issue has been resolved in version 1.12.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

@enisdenjo enisdenjo added the released Has been released and published label Jan 20, 2023
@schwma
Copy link
Author

schwma commented Jan 20, 2023

Great, thanks for the fast fix and release!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working released Has been released and published
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants