Skip to content
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

GraphQL error not formatted properly when it returns a 4xx or 5xx http status #2940

Open
2 of 4 tasks
remonke opened this issue Jul 27, 2023 · 4 comments
Open
2 of 4 tasks

Comments

@remonke
Copy link

remonke commented Jul 27, 2023

Is there an existing issue for this?

  • I have searched the existing issues

Current behavior

In Apollo, there's a way of providing a custom http status via extensions on the GraphQLError / ApolloError, as is the case with the default validation error, which returns a status of 400. Unfortunately, instead of the response being formatted the usual way - with data and errors, everything gets wrapped inside of the error object. Is there any way to disable this behavior?

Screenshot_20230727_050425
Screenshot_20230727_050459

Minimum reproduction code

https://github.com/remonke/nest-graphql-error-bug

Steps to reproduce

Install the dependencies pnpm install
Start the server
Open the playground
Test the two available queries throwError and throwErrorWithHttpStatus

Expected behavior

I expect a GraphQL errror with a custom http status to get formatted like all the others.

Package version

12.0.8

Graphql version

graphql: 16.7.1
@apollo/server: 4.8.1
@nestjs/apollo: ^12.0.7

NestJS version

10.0.0

Node.js version

20.4.0

In which operating systems have you tested?

  • macOS
  • Windows
  • Linux

Other

No response

@kamilmysliwiec
Copy link
Member

Would you like to create a PR for this issue?

@remonke
Copy link
Author

remonke commented Jul 31, 2023

I would try, except I have no idea what causes this behavior - I tried this with Mercurius driver and it works just fine

@jan-hecker
Copy link

You can probably disable this behavior if you create a custom error formatter. You can provide the error formatter in the GraphQL options with the formatError argument

@tanmen
Copy link

tanmen commented Aug 13, 2024

You can probably disable this behavior if you create a custom error formatter. You can provide the error formatter in the GraphQL options with the formatError argument

I have tried this and it did not resolve the problem.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants