Hi all, a quick question regarding partial / compl...
# graphql-kotlin
m
Hi all, a quick question regarding partial / complete failures. I know I can return both data and errors using
DataFetcherResult
, but I wonder if there is a way to completely fail the response (without any data being present), even though the fields might be nullable. I was looking around in the GraphQL Java Execution, but haven't found anything if there is a way to completely fail a query in the case of a specific error. However since this is the default policy in the case of non-nullable fields, I believe there must be a mechanism to do this. Any pointer? Thx!
s
If you throw an exception in your data fetcher that will be mapped to a GraphQL error response
m
Well, it looks like this will still end up setting the value as null and present this value as one of the errors. What I'm trying to do is to fail the whole response completely in some circumstances and not deliver any data.
@Shane Myrick do you know? ^
s
You can return a
DataFetcherResult
at the top level and just don't set any data, only errors
m
Hmm, how would I wire it it in when such a condition happens in data loaders. The only approach I can think of is to instrument execution result and fail the response if a certain condition is met. Is this the recommend way or there is a better mechanism?
s
If you throw an exception in your data loader it should bubble up: https://opensource.expediagroup.com/graphql-kotlin/docs/schema-generator/execution/exceptions
m
As I wrote yesterday - I tried that, but the result was still a partial response, not full failure
s
What do you mean a partial response? If there is an exception thrown it should get handled by the graphql-java code
DataFetcherExceptionHandler
Have you defined a custom handler that is executing to add a response?