https://kotlinlang.org logo
#graphql-kotlin
Title
# graphql-kotlin
m

Martin Brehovsky

01/11/2022, 12:16 AM
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

Shane Myrick

01/11/2022, 12:56 AM
If you throw an exception in your data fetcher that will be mapped to a GraphQL error response
m

Martin Brehovsky

01/11/2022, 4:41 AM
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

Shane Myrick

01/11/2022, 10:08 PM
You can return a
DataFetcherResult
at the top level and just don't set any data, only errors
m

Martin Brehovsky

01/11/2022, 11:00 PM
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

Shane Myrick

01/11/2022, 11:11 PM
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

Martin Brehovsky

01/11/2022, 11:24 PM
As I wrote yesterday - I tried that, but the result was still a partial response, not full failure
s

Shane Myrick

01/11/2022, 11:38 PM
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?
2 Views