graphql-services / graphql-gateway

Apollo federation gateway wrapped in Docker image or AWS Lambda package.
MIT License
31 stars 8 forks source link

My extensions from error are missing #9

Closed danielvladco closed 4 years ago

danielvladco commented 5 years ago

Hi thanks for the great work and graphql/gateway docker image.

When I use the gateway to forward requests to other services for some reason in case of error my extensions are missing:

For example when my graphql field is expected to return an error I usually have this json:

"errors": [
    {
      "message": "user with this email already exists",
      "path": [
        "myField"
      ],
      "extensions": {
        "code": "AlreadyExists",
        "details": [],
        "message": "user with this email already exists"
      }
    }
  ],

Notice in extensions I have 2 more fields for additional information about the error. However when my request goes through the gateway it's missing these extensions. Example:

"errors": [
    {
      "message": "Unexpected error value: { message: \"user with this email already exists\", path: [\"myField\"], extensions: { code: \"AlreadyExists\", details: [], message: \"user with this email already exists\" } }",
      "locations": [
        {
          "line": 2,
          "column": 3
        }
      ],
      "path": [
        "myField"
      ]
    }
  ]

The image with tag is graphql/gateway:latest

Could you please look into this issue?

Thanks, Daniel

danielvladco commented 5 years ago

I figured a potential fix for this:

you need to convert the error form the remote to GraphQLError

/src/schema.ts

// ....
link = onError(({response}) => {
  response.errors = response.errors.map(err =>
        new GraphQLError(err.message, null, null, err.locations, err.path, null, err.extensions))
}).concat(link)

const schema = await introspectSchema(link);

return makeRemoteExecutableSchema({
    schema,
    link
});
//...
jakubknejzlik commented 5 years ago

Hi @danielvladco 👋! Thanks for reporting. This would make sense. Would you mind testing it on graphql/gateway:feature/add-graphqlerror-support image as I don't have any running api with error extensions?

jakubknejzlik commented 4 years ago

Moved to apollo federation should mitigate this issue