Skip to content

Fix bug with error handling in the defer execution code #3640

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Conversation

felipe-gdr
Copy link
Member

Improvements in the error handling for deferred code.

  • fixes bug where errors added by data fetchers that returned DataFetcherResult where not being added to deferred payloads
  • Errors generated during the execution of deferred fields are kept in the correspondent DeferredCallContext only, no longer being duplicated in ExecutionContext

public void onFetchingException(ResultPath path, SourceLocation sourceLocation, Throwable throwable) {
ExceptionWhileDataFetching error = new ExceptionWhileDataFetching(path, throwable, sourceLocation);
onError(error);
public void addErrors(List<GraphQLError> errors) {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

keep naming consistent with ExecutionContext

@felipe-gdr felipe-gdr force-pushed the defer-error-handling-df-returns-data-and-error branch from 20bc193 to 037e06b Compare June 24, 2024 03:24
@@ -187,9 +218,6 @@ public Builder deferredCallContext(DeferredCallContext deferredCallContext) {
}

public ExecutionStrategyParameters build() {
if (deferredCallContext == null) {
deferredCallContext = new DeferredCallContext();
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There was no point in creating a new instance of DeferredCallContext by default.
With the current change, the presence of an instance of DeferredCallContext signifies that the execution is part of a deferred call.

Copy link
Contributor

@gnawf gnawf left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Left a comment, but this will work too

parameters.getDeferredCallContext().addError(error);
} else {
executionContext.addError(error, path);
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if there's a better way to do this, because this is fairly error prone.

i.e. if you're adding an error you have to remember to check for the presence of a deferred context first.

Could we clone the ExecutionContext for a defer and have a separate error array?

ofc this is only a problem for framework code, and end users should be ok… unless they invoke ExecutionContext.addError themselves? Seems like it's public API?

Copy link
Member Author

@felipe-gdr felipe-gdr Jun 24, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I totally agree about it being high error-prone, but I couldn't figure out a simple solution. As long as ExecutionContext#addError exists, any code can always add errors directly to ExecutionContext without checking for defer...

Could we clone the ExecutionContext for a defer and have a separate error array?

hm... DeferredCallContext is sort of that. Is a context but only with the state that is relevant for a defer block, which for now is just a list of errors.
Can you expand on your suggestion? :-)

@dondonz dondonz added this pull request to the merge queue Jul 4, 2024
Merged via the queue into graphql-java:master with commit 8c10ed0 Jul 4, 2024
1 check passed
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.

6 participants