Re:Migrating Netflix to GraphQL Safely
by withinboredom on Sunday June 18, 2023 @06:27PM
(#36385184)
Sure. I could respond with a 4xx code because you’re not authorized for that field. Ah, but maybe you want to know which field? Too bad GQL doesn’t really support that.
[ Parent
| on HN ]
Re:Migrating Netflix to GraphQL Safely
by cameronh90 on Sunday June 18, 2023 @06:45PM
(#36385308)
Authorization errors can go in the errors array which has a path reference in the standard.
You generally don't want to use HTTP error codes with field level errors in GQL.
Re:Migrating Netflix to GraphQL Safely
by paulryanrogers on Sunday June 18, 2023 @08:47PM
(#36386033)
So still a 200? Or a 202, 206, 207?
401 or 403. Why is this a question?
Re:Migrating Netflix to GraphQL Safely
by paulryanrogers on Monday June 19, 2023 @10:00AM
(#36391186)
Because there may be fields requested correctly alongside some requested incorrectly
Outside of very few cases it means the request was incorrect.
And bo one is stopping you from returning a response that contains error details.
Re:Migrating Netflix to GraphQL Safely
by satvikpendem on Sunday June 18, 2023 @07:45PM
(#36385698)
GraphQL has strongly typed errors unlike REST. It is very akin to the Result type in many languages in that you are forced to handle errors even when writing the query, and the query will simply not compile if you don't.
For example, the Pothos library implements this pattern automatically:
type Error {
message: String!
}
type Query {
hello(name: String!): QueryHelloResult
}
union QueryHelloResult = Error | QueryHelloSuccess
type QueryHelloSuccess {
data: String!
}
This field can be queried using fragments like: query {
hello(name: "World") {
__typename
... on Error {
message
}
... on QueryHelloSuccess {
data
}
}
}
https://pothos-graphql.dev/docs/plugins/errors
Re:Migrating Netflix to GraphQL Safely
by withinboredom on Monday June 19, 2023 @01:39AM
(#36387673)
But now I’m most likely returning a 2xx response. There are asshole corporate middle boxes somewhere that will cache it. If I return a 4xx response, from experience (albeit nearly 5 years ago) I’ll crash your client. Now what?
If someone has solved the asshole corporate middle box problem using GQL, that’s really good news.