Currently, Lighthouse always returns responses with a status code of 200. While GraphQL works in such a way that responses contain error information as JSON, it may still be useful to have actual HTTP status codes.
Use cases:
I think it might not be too hard to bubble up errors to the Controller and return a corresponding status code. We would have to work out the semantics of when to return what.
I also thought about this, but this does pose a problem when perfoming multiple queries. Consider the following example:
query data {
federationsPaginated(count: 1) {
data {
id
name
}
}
districtsPaginated(count: 1) {
data {
id
name
}
}
}
Response:
{
"errors": [
{
"category": "graphql",
"message": "Not authorized to access this field.",
"locations": null
}
],
"data": {
"federationsPaginated": null,
"districtsPaginated": {
"data": [
{
"id": "0c0679cc-a225-11e8-8d89-5254507c1b9f",
"name": "Name"
}
]
}
},
"extensions": []
}
The first query should return a 403, but the second should return 200.
Great point! That is a strong argument for always returning 200. While for a single query it might make sense to have another status code, i think it will be too confusing to make an exception.
There might be queries with multiple fields that return a multitude of errors. There is just no reasonable way to put that into a single status code.
Or maybe lets just add up the status code and take the average? /sarcasm
An extension could be created here that holds the status code for each query as well
Closing this, as i feel that @maarten00 comment has clearly shown we can not have HTTP status codes.
Most helpful comment
I also thought about this, but this does pose a problem when perfoming multiple queries. Consider the following example:
Response:
The first query should return a 403, but the second should return 200.