fix: Raise an Execution Exception before trying to decode a Query Response #150
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR fixes a bug where the full SwiftGraphQLClient would try to decode a faulty response and ignore errors that were raised during execution.
Now, all methods first check that the result contains no errors and only then try to decode the result.
cc #148
Important⚠️ ⚠️ ⚠️
This is not ideal and it shows that I made some assumptions that don't hold anymore. Namely, I assumed that the client can always enforce that the server conforms to the schema and that we can safely assume that if a field is non-optional that the data will be there.
Looking back on it, this is clearly wrong as we can easily see from numerous bug reports and all the fidgeting that's in the code. As per spec,
My reasoning back then was that since we generate the query, it couldn't happen that the query wouldn't conform to the schema, hence the query would always get executed. In the recent years, however, it seems like more and more of the authentication and authorization logic happens before execution, meaning that even if we generate the query, there's still a chance that we get back
null
or empty values.Plan going forward
This is an apparent issue and I am looking forward to fixing it, but I don't know when that'll be.
Workarond
The current workaround is that we defensively throw an error - given the changes from this PR. This means that the publisher may throw something (which in my ideal world wasn't the case before), and there's no way to differentiate between results that included some data and results that did not.
*You don't need to do anything, just be aware that there's a chance that the publishers for
query
,mutation
andsubscription
may throw.Next Version
Next version of SwiftGraphQL is going to rethink how we handle
nil
values. Perhaps we could make another GraphQLClient that has more lose requirements, and keep the one that we have now for the other times where you "just want something working".