Skip to content

Ensure field errors are populated in FetchedResult#2520

Merged
andimarek merged 4 commits intographql-java:masterfrom
schenkman:instrumentation_field_errors
Aug 27, 2021
Merged

Ensure field errors are populated in FetchedResult#2520
andimarek merged 4 commits intographql-java:masterfrom
schenkman:instrumentation_field_errors

Conversation

@schenkman
Copy link
Copy Markdown
Contributor

Currently if a DataFetcher raises an exception in any way, the FetchedValue given in the instrumentation beginFieldComplete method does not contain any errors information. The only place errors are available are on the ExecutionContext within a list, which is not ideal to determine if the current field has an error. This change ensures that FetchedValue contains errors if any was raised during DataFetcher.get.

The solution simply allows the unboxPossibleDataFetcherResult to hit the result instanceof DataFetcherResult case which properly passes through errors in the ExecutionContext and in the FetchedResult itself. Since I'm not super familiar with the code base, this implementation has to cast to type T, which seems safe since the method was returning null in the first place but would defer to your suggestions to change.

Another possible solution is to expose a containsErrorPath method on ExecutionContext as the context maintains a Set<ResultPath> errorPaths which could be used to look up the current ResultPath in the instrumentation to see if it's an error. However, having the error directly on the FetchedValue seems to make more sense.

Chris Schenk added 3 commits August 20, 2021 10:11
…tion `beginFieldComplete` is called

Currently if a DataFetcher raises an exception in any way, the FetchedValue given in the
instrumentation does not contain any errors information. The only place errors are available
are on the ExecutionContext within a list, which is not ideal to determine if the current
field has an error. This change ensures that FetchedValue contains errors if any was raised
during `DataFetcher.get`.
@bbakerman
Copy link
Copy Markdown
Member

Thanks for this PR. I think this is a more elegant way for exceptions errors .

The old code looks a bit crusty and I think its come from a time when graphql-java was "synchronous" and we didn't have CompletableFuture everywhere.

I think this is a valuable editions for Instrumentations that want to get all the returned values including errors.

ps. if we had out time again we would have made DataFetcher have this signature

public interface DataFetcher<T> {
       DataFetcherResult<T> get(DataFetchingEnvironment environment);
}       

and then we would garuntee that you should not come back out from a fetch with anything else but data, errors or both. But anyway I disgress

@bbakerman bbakerman added this to the 18.0 milestone Aug 25, 2021
@schenkman
Copy link
Copy Markdown
Contributor Author

Thanks @bbakerman!

@andimarek andimarek modified the milestones: 18.0, 17.2 Aug 27, 2021
@andimarek andimarek merged commit 45b5901 into graphql-java:master Aug 27, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants