Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Unable to return a different status code than 200 with graphql-yoga 3.0.1

See original GitHub issue

Describe the bug

Since the 3.0.1, if we throw a GraphQLError with a custom http code, it always return 200.

I tried to create a thing on codesandbox but it always say “Reloading too fast”, I’ve no idea how to fix it.

But I think that snippet reproduce the bug:

const yoga = createYoga({
  graphiql: {
  landingPage: false,
  graphqlEndpoint: "/",
  plugins: [
    () => ({
      onParams() {
        throw new GraphQLError("Not found!", {
          extensions: {
            http: {
              status: 404,
              headers: {
                Allow: "GET"

Requesting the server will return a 200 but we expect to be 404 instead.

Your Example Website or App

Steps to Reproduce the Bug or Issue

Just throw a custom GraphQLError with a custom http code.

Expected behavior

If a GraphQLError is throw with a custom http code, it should be return to the client.

Screenshots or Videos

No response


  • graphql-yoga version(s): 3.0.1

Additional context

No response

Issue Analytics

  • State:closed
  • Created 10 months ago
  • Comments:5

github_iconTop GitHub Comments

j0k3rcommented, Nov 24, 2022

It’s perfect, thanks for the quick fix!

enisdenjocommented, Nov 23, 2022

Yoga now respects user defined http extensions, please update to v3.0.2 and try again.

Read more comments on GitHub >

github_iconTop Results From Across the Web

fix: allow user to set a status code even if content-type ... - GitHub
Successfully merging this pull request may close these issues. Unable to return a different status code than 200 with graphql-yoga 3.0.1.
Read more >
return status code from graphql yoga - Stack Overflow
The response has status 200 though, which is not correct. I'd like to be able to choose my own status, like 403 for...
Read more >
Status Codes in GraphQL - Medium
As you all know, REST APIs use status codes as a part of the response (200-ok, 404-not found, 500-internal server error etc.).
Read more >
Error Masking – GraphQL Yoga
The default status code of 200 can be overwritten by specifying the extensions.http.status field. In case of multiple errors that try to alter ......
Read more >
GraphQL | RedwoodJS Docs
GraphQL Yoga takes a different approach—it just provides a handful of ... which returns a 200 status code with a result of {...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Post

No results found

github_iconTop Related Hashnode Post

No results found