All Downloads are FREE. Search and download functionalities are using the official Maven repository.

cc.voox.graphql.GraphQLInterceptor Maven / Gradle / Ivy

There is a newer version: 1.2.1
Show newest version
package cc.voox.graphql;

import graphql.ExecutionResult;
import graphql.execution.ExecutionContext;
import graphql.execution.instrumentation.DeferredFieldInstrumentationContext;
import graphql.execution.instrumentation.ExecutionStrategyInstrumentationContext;
import graphql.execution.instrumentation.Instrumentation;
import graphql.execution.instrumentation.InstrumentationContext;
import graphql.execution.instrumentation.InstrumentationState;
import graphql.execution.instrumentation.SimpleInstrumentation;
import graphql.execution.instrumentation.SimpleInstrumentationContext;
import graphql.execution.instrumentation.parameters.InstrumentationDeferredFieldParameters;
import graphql.execution.instrumentation.parameters.InstrumentationExecuteOperationParameters;
import graphql.execution.instrumentation.parameters.InstrumentationExecutionParameters;
import graphql.execution.instrumentation.parameters.InstrumentationExecutionStrategyParameters;
import graphql.execution.instrumentation.parameters.InstrumentationFieldCompleteParameters;
import graphql.execution.instrumentation.parameters.InstrumentationFieldFetchParameters;
import graphql.execution.instrumentation.parameters.InstrumentationFieldParameters;
import graphql.execution.instrumentation.parameters.InstrumentationValidationParameters;
import graphql.language.Document;
import graphql.schema.DataFetcher;
import graphql.schema.GraphQLSchema;
import graphql.validation.ValidationError;

import java.util.List;
import java.util.concurrent.CompletableFuture;

public interface GraphQLInterceptor extends Instrumentation {

    public static final SimpleInstrumentation INSTANCE = new SimpleInstrumentation();

    default int getOrder() {
        return 0;
    }

    public default InstrumentationContext beginExecution(InstrumentationExecutionParameters parameters) {
        return new SimpleInstrumentationContext();
    }

    public default InstrumentationContext beginParse(InstrumentationExecutionParameters parameters) {
        return new SimpleInstrumentationContext();
    }

    public default InstrumentationContext> beginValidation(InstrumentationValidationParameters parameters) {
        return new SimpleInstrumentationContext();
    }

    public default ExecutionStrategyInstrumentationContext beginExecutionStrategy(InstrumentationExecutionStrategyParameters parameters) {
        return new ExecutionStrategyInstrumentationContext() {
            public void onDispatched(CompletableFuture result) {
            }

            public void onCompleted(ExecutionResult result, Throwable t) {
            }
        };
    }

    public default DeferredFieldInstrumentationContext beginDeferredField(InstrumentationDeferredFieldParameters parameters) {
        return new DeferredFieldInstrumentationContext() {
            public void onDispatched(CompletableFuture result) {
            }

            public void onCompleted(ExecutionResult result, Throwable t) {
            }
        };
    }

    public default InstrumentationContext beginExecuteOperation(InstrumentationExecuteOperationParameters parameters) {
        return new SimpleInstrumentationContext();
    }

    public default InstrumentationContext beginField(InstrumentationFieldParameters parameters) {
        return new SimpleInstrumentationContext();
    }

    public default InstrumentationContext beginFieldFetch(InstrumentationFieldFetchParameters parameters) {
        return new SimpleInstrumentationContext();
    }

    public default InstrumentationContext beginFieldComplete(InstrumentationFieldCompleteParameters parameters) {
        return new SimpleInstrumentationContext();
    }

    public default InstrumentationContext beginFieldListComplete(InstrumentationFieldCompleteParameters parameters) {
        return new SimpleInstrumentationContext();
    }

    public default GraphQLSchema instrumentSchema(GraphQLSchema schema, InstrumentationExecutionParameters parameters) {
        return schema;
    }

    public default ExecutionContext instrumentExecutionContext(ExecutionContext executionContext, InstrumentationExecutionParameters parameters) {
        return executionContext;
    }

    public default DataFetcher instrumentDataFetcher(DataFetcher dataFetcher, InstrumentationFieldFetchParameters parameters) {
        return dataFetcher;
    }

    public default CompletableFuture instrumentExecutionResult(ExecutionResult executionResult, InstrumentationExecutionParameters parameters) {
        return CompletableFuture.completedFuture(executionResult);
    }
}