Repository navigation
support async execution - #590
Conversation
| private ExecutionStrategy mutationExecutionStrategy = new SimpleExecutionStrategy(); | ||
| private ExecutionStrategy subscriptionExecutionStrategy = new SimpleExecutionStrategy(); | ||
| private ExecutionStrategy queryExecutionStrategy = new AsyncExecutionStrategy(); | ||
| private ExecutionStrategy mutationExecutionStrategy = new AsyncExecutionStrategy(); |
There was a problem hiding this comment.
Shouldn't this be AsyncSerialExecutionStrategy ?
bbakerman
left a comment
There was a problem hiding this comment.
I think DataFetcher needs more JavaDoc on what you can return (eg a CF is ok)
There was a problem hiding this comment.
Make sure graphql.NonNullHandlingTest works as well. Currently we are using graphql.execution.NonNullableFieldWasNullException as a way to jump out of a flow but adjust behaviour.
By going full async the order of field evaluation is now changed since evaluating A -> B -C can now be in any order
There was a problem hiding this comment.
this is outdated code and the NonNullHandlingTest works
There was a problem hiding this comment.
We have to agree on a JavaDoc set of settings
eg: lines between @params or not.
You and I are flip flopping here.
I argue for lines after each section but... lets make a decision and document it into the project README
| }); | ||
| } | ||
|
|
||
| private void futuresCompleted(ExecutionContext executionContext, |
There was a problem hiding this comment.
IDEA tells me that a lot of this code is repeated from AsyncExecutionStrategy - can we create a static OR a AsyncExecutionStrategyHelper common helper that an be used ot contain the common code
Same below on error handling
| result.complete(new ExecutionResultImpl(resolvedValuesByField, executionContext.getErrors())); | ||
| } | ||
|
|
||
| private void handleException(ExecutionContext executionContext, CompletableFuture<ExecutionResult> result, Throwable e) { |
There was a problem hiding this comment.
Again IDEA says this is repeated code. Can it go into a common place. Even into ExecutionStrategy perhaps as a protected method for this code
| schema | ||
| } | ||
|
|
||
|
|
There was a problem hiding this comment.
Check out the testing library awaitability
testCompile 'org.awaitility:awaitility:2.0.0'
https://github.com/awaitility/awaitility
examples where I used it
|
|
||
| then: | ||
| !result.isDone() | ||
| Thread.sleep(200) |
There was a problem hiding this comment.
awaitability makes this much cleaner
| /** | ||
| * The standard graphql execution strategy that runs fields asynchronously | ||
| */ | ||
| public class AsyncExecutionStrategy extends ExecutionStrategy { |
There was a problem hiding this comment.
We need to explain to people that DataFetchers can returns CFs and that they will be chained ok.
That needs to go on DataFetcher and in the general documentation.
I think the doco should have a "aasyncrhnous support in graphql" section (but not in this PR)
|
|
||
| fetchCtx.onEnd(fetchedValue); | ||
| Object fetchedValueRaw = dataFetcher.get(environment); | ||
| if (fetchedValueRaw instanceof CompletableFuture) { |
There was a problem hiding this comment.
I think this should accept a CompletionStage at this specific point.
While the JDK only has 1 implementation, people can write their own.
The toCompletableFuture is provided as a interop to allow 2 different CompletionStages to interop.
This would be a tiny minor thing to be honest since the work around is for them to call toCompletableFuture() themselves in the DF.
| fetchedValue = new CompletableFuture<>(); | ||
| fetchedValue.completeExceptionally(e); | ||
| } | ||
| return fetchedValue; |
There was a problem hiding this comment.
I think we need to fix Instrumentation up.
We would use .whenComplete((result,throwable) -> ....) to do this.
This does not have to go in this PR
| .subscriptionExecutionStrategy(new AsyncExecutionStrategy()) | ||
| .build(); | ||
|
|
||
| } |
There was a problem hiding this comment.
Do we have a test some where that tests how a mutation switches back to query strategy once the first level is resolved?
This will be more important with async if we get it wrong
There was a problem hiding this comment.
I added this test: 3cde546
this what you mean?
| import java.util.concurrent.CompletableFuture; | ||
| import java.util.concurrent.CompletionException; | ||
|
|
||
| public class AsyncSerialExecutionStrategy extends ExecutionStrategy { |
There was a problem hiding this comment.
Can we get some JavaDoc on this please
| this.mutationStrategy = mutationStrategy != null ? mutationStrategy : new SimpleExecutionStrategy(); | ||
| this.subscriptionStrategy = subscriptionStrategy != null ? subscriptionStrategy : new SimpleExecutionStrategy(); | ||
| this.queryStrategy = queryStrategy != null ? queryStrategy : new AsyncExecutionStrategy(); | ||
| this.mutationStrategy = mutationStrategy != null ? mutationStrategy : new AsyncExecutionStrategy(); |
There was a problem hiding this comment.
yes ... you are right ... too many different places where we use a default strategy.
(if further execution is needed)
`CompletableFuture`
|
Awesome!!!
…On 8/8/17, Andreas Marek ***@***.***> wrote:
Merged #590.
--
You are receiving this because you are subscribed to this thread.
Reply to this email directly or view it on GitHub:
#590 (comment)
|
|
Looking forward to this release ! |
The main change is that
ExecutionStrategy.fetchFieldreturns now aCompletableFutureinstead ofObjectand newExecutionStrategys.SimpleExecutionStrategyis nowSerialExecutionStrategyand is not used anymore by default, because it is blocking.The new default strategy is
AsyncExecutionStrategyfor queries andAsyncSerialExecutionStrategyfor mutations. Both are non blocking but are compatible to the old behaviour ifDataFetcherare still blocking and not async.