★ wanayoo — archive 1999 https://github.com/graphql-java/graphql-java/pull/1387Nouvelle recherche | Portail wanayoo
Skip to content
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

removed ExecutionContext from DataFetcherEnvironment #1387

Merged

Conversation

@bbakerman
Copy link
Member

@bbakerman bbakerman commented Jan 13, 2019

This removes the ExecutionContext from the DataFetcher interface.

This removes the large implementation leak that is in the API.

@bbakerman bbakerman requested a review from andimarek Jan 13, 2019
…in execution context that makes sense to pass on
@cmonty
Copy link

@cmonty cmonty commented Jan 14, 2019

@bbakerman We currently use the ExecutionContext to pass authorization data to DataFetchers. Is there an alternative implementation for passing this type of per execution context to DataFetchers after this is released?

@andimarek
Copy link
Member

@andimarek andimarek commented Jan 14, 2019

@cmonty thanks for your feedback: can you give use more details how you use it? Also just to be clear: the ExecutionContext is different from context in the DataFetcherEnvironment. I would expect that you use context (which is an Object) to pass down authorization data.

Thanks

@cmonty
Copy link

@cmonty cmonty commented Jan 14, 2019

@andimarek Ah, you're correct. We use env.getContext() to pass authorization data, which is the Object you described. Sorry for the confusion!

We do use ExecutionContext and call addError when an exception is thrown.

@bbakerman
Copy link
Member Author

@bbakerman bbakerman commented Jan 14, 2019

@cmonty

We do use ExecutionContext and call addError when an exception is thrown.

Come 12.0 this will be removed and we will ask you to return a DataFetcherResult wrapper object from your data fetchers

This exists today and it can contain data (or null) and errors (or empty list) and the graphql engine will put the errors in the result for you today.

https://github.com/graphql-java/graphql-java/blob/master/src/main/java/graphql/execution/DataFetcherResult.java

So if you move to that system before adopting 12.0 then you will continue to work as expected

@cmonty
Copy link

@cmonty cmonty commented Jan 15, 2019

Awesome, thanks for the information!

@andimarek andimarek changed the title removed ExecutionContext from dataFetcher removed ExecutionContext from DataFetcherEnvironment Jan 16, 2019
@andimarek andimarek added this to the 12.0 milestone Jan 16, 2019
@bbakerman bbakerman merged commit 0f5a890 into graphql-java:master Jan 18, 2019
1 check passed
1 check passed
continuous-integration/travis-ci/pr The Travis CI build passed
Details
@Salrandin
Copy link

@Salrandin Salrandin commented Oct 4, 2019

Hi, I have a question about this. We are trying to update our GraphQL code where we also use ExecutionContext.addError(). In the DataFetcherExceptionHandler implementation we want to catch a few specific exceptions and log them as warnings rather than errors. It looks like we can still do that but the return for DataFetcherExceptionHandlerResult requires GraphQL errors. Is there something I can use to convert the regular throwables to GraphQL errors.

@bbakerman
Copy link
Member Author

@bbakerman bbakerman commented Oct 6, 2019

@Salrandin - seae the answer above

Use https://github.com/graphql-java/graphql-java/blob/master/src/main/java/graphql/execution/DataFetcherResult.java

The allows you to send back errors from a data fetcher without throwing an exception.

@Salrandin
Copy link

@Salrandin Salrandin commented Oct 7, 2019

I kinda get the solution but does this mean every datafetcher has its own responsibility for handling specific errors? The reason the implementation worked well was because we could handle it for all the datafetchers which kept our graphql instance uniform.

@bbakerman
Copy link
Member Author

@bbakerman bbakerman commented Oct 8, 2019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

None yet

4 participants
You can’t perform that action at this time.