Search in sources :

Example 1 with SubscriptionPublisher

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;
}
Also used : GraphQLObjectType(graphql.schema.GraphQLObjectType) InstrumentationExecutionStrategyParameters(graphql.execution.instrumentation.parameters.InstrumentationExecutionStrategyParameters) Publisher(org.reactivestreams.Publisher) InstrumentationExecutionParameters(graphql.execution.instrumentation.parameters.InstrumentationExecutionParameters) SubscriptionPublisher(graphql.execution.reactive.SubscriptionPublisher) GraphQLFieldDefinition(graphql.schema.GraphQLFieldDefinition) CompletableFuture(java.util.concurrent.CompletableFuture) Field(graphql.language.Field) Function(java.util.function.Function) ExecutionResult(graphql.ExecutionResult) InstrumentationContext(graphql.execution.instrumentation.InstrumentationContext) CompletionStage(java.util.concurrent.CompletionStage) Instrumentation(graphql.execution.instrumentation.Instrumentation) Assert.assertTrue(graphql.Assert.assertTrue) PublicApi(graphql.PublicApi) Collections.singletonMap(java.util.Collections.singletonMap) InstrumentationFieldParameters(graphql.execution.instrumentation.parameters.InstrumentationFieldParameters) ExecutionStrategyInstrumentationContext(graphql.execution.instrumentation.ExecutionStrategyInstrumentationContext) ExecutionResultImpl(graphql.ExecutionResultImpl) Instrumentation(graphql.execution.instrumentation.Instrumentation) ExecutionResult(graphql.ExecutionResult) Publisher(org.reactivestreams.Publisher) SubscriptionPublisher(graphql.execution.reactive.SubscriptionPublisher) ExecutionStrategyInstrumentationContext(graphql.execution.instrumentation.ExecutionStrategyInstrumentationContext) ExecutionResultImpl(graphql.ExecutionResultImpl) SubscriptionPublisher(graphql.execution.reactive.SubscriptionPublisher) InstrumentationExecutionStrategyParameters(graphql.execution.instrumentation.parameters.InstrumentationExecutionStrategyParameters) CompletionStage(java.util.concurrent.CompletionStage)

Aggregations

Assert.assertTrue (graphql.Assert.assertTrue)1 ExecutionResult (graphql.ExecutionResult)1 ExecutionResultImpl (graphql.ExecutionResultImpl)1 PublicApi (graphql.PublicApi)1 ExecutionStrategyInstrumentationContext (graphql.execution.instrumentation.ExecutionStrategyInstrumentationContext)1 Instrumentation (graphql.execution.instrumentation.Instrumentation)1 InstrumentationContext (graphql.execution.instrumentation.InstrumentationContext)1 InstrumentationExecutionParameters (graphql.execution.instrumentation.parameters.InstrumentationExecutionParameters)1 InstrumentationExecutionStrategyParameters (graphql.execution.instrumentation.parameters.InstrumentationExecutionStrategyParameters)1 InstrumentationFieldParameters (graphql.execution.instrumentation.parameters.InstrumentationFieldParameters)1 SubscriptionPublisher (graphql.execution.reactive.SubscriptionPublisher)1 Field (graphql.language.Field)1 GraphQLFieldDefinition (graphql.schema.GraphQLFieldDefinition)1 GraphQLObjectType (graphql.schema.GraphQLObjectType)1 Collections.singletonMap (java.util.Collections.singletonMap)1 CompletableFuture (java.util.concurrent.CompletableFuture)1 CompletionStage (java.util.concurrent.CompletionStage)1 Function (java.util.function.Function)1 Publisher (org.reactivestreams.Publisher)1