use of graphql.execution.reactive.SubscriptionPublisher in project graphql-java by graphql-java.
the class SubscriptionExecutionStrategy method execute.
@Override
public CompletableFuture<ExecutionResult> execute(ExecutionContext executionContext, ExecutionStrategyParameters parameters) throws NonNullableFieldWasNullException {
Instrumentation instrumentation = executionContext.getInstrumentation();
InstrumentationExecutionStrategyParameters instrumentationParameters = new InstrumentationExecutionStrategyParameters(executionContext, parameters);
ExecutionStrategyInstrumentationContext executionStrategyCtx = instrumentation.beginExecutionStrategy(instrumentationParameters);
CompletableFuture<Publisher<Object>> sourceEventStream = createSourceEventStream(executionContext, parameters);
//
// when the upstream source event stream completes, subscribe to it and wire in our adapter
CompletableFuture<ExecutionResult> overallResult = sourceEventStream.thenApply((publisher) -> {
if (publisher == null) {
return new ExecutionResultImpl(null, executionContext.getErrors());
}
Function<Object, CompletionStage<ExecutionResult>> mapperFunction = eventPayload -> executeSubscriptionEvent(executionContext, parameters, eventPayload);
SubscriptionPublisher mapSourceToResponse = new SubscriptionPublisher(publisher, mapperFunction);
return new ExecutionResultImpl(mapSourceToResponse, executionContext.getErrors());
});
// dispatched the subscription query
executionStrategyCtx.onDispatched(overallResult);
overallResult.whenComplete(executionStrategyCtx::onCompleted);
return overallResult;
}
Aggregations