Unable to return a different status code than 200 with graphql-yoga 3.0.1
See original GitHub issueDescribe 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: {
defaultQuery
},
schema,
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
https://codesandbox.io/s/strange-field-rsyzj8?file=/src/main.ts
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
Platform
graphql-yoga
version(s): 3.0.1
Additional context
No response
Issue Analytics
- State:
- Created 10 months ago
- Comments:5
Top 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 >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
It’s perfect, thanks for the quick fix!
Yoga now respects user defined http extensions, please update to v3.0.2 and try again.