-
Notifications
You must be signed in to change notification settings - Fork 111
Description
I'm looking for a way to authorize requests, specifically mutations. For example, if a user without the required permission attempts to execute mutateFoo, they should be rejected with an error. Or maybe they do not have the permission to mutate this particular instance of Foo (so it depends on payload, not just mutation type). Offhand I would expect HTTP 403, unless the graphql-land wants to reinvent HTTP and put that in the payload.
Anyway, I don't really see a way to do this with GraphQLServlet at all. There doesn't seem to be a pre-execution hook that could veto execution and let me return an error. When an exception is thrown, it's always caught and translated to the generic:
{"data":{"mutateFoo":null},"errors":[{"message":"Internal Server Error(s) while executing query"}]}
Ideally, I should be able to throw an exception from anywhere in my business logic, and have it translated to a meaningful GraphQL response. That's even more flexible than the abovementioned execution hook.
I don't want to use something like servlet filters for this, since that would mean interpreting the GraphQL request myself, and it's on the wrong level.