graphql.execution.instrumentation.InstrumentationContext Java Examples

The following examples show how to use graphql.execution.instrumentation.InstrumentationContext. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: FederatedTracingInstrumentation.java    From federation-jvm with MIT License 6 votes vote down vote up
@Override
public InstrumentationContext<Object> beginFieldFetch(InstrumentationFieldFetchParameters parameters) {
    FederatedTracingState state = parameters.getInstrumentationState();
    if (state == null) {
        return super.beginFieldFetch(parameters);
    }

    SourceLocation fieldLocation = parameters.getEnvironment().getField().getSourceLocation();

    long startNanos = System.nanoTime();
    return whenCompleted((result, throwable) -> {
        long endNanos = System.nanoTime();

        ExecutionStepInfo executionStepInfo = parameters.getEnvironment().getExecutionStepInfo();
        state.addFieldFetchData(
                executionStepInfo,
                // relative to the trace's start_time, in ns
                startNanos - state.getStartRequestNanos(),
                // relative to the trace's start_time, in ns
                endNanos - state.getStartRequestNanos(),
                convertErrors(throwable, result),
                fieldLocation
        );
    });
}
 
Example #2
Source File: FederatedTracingInstrumentation.java    From federation-jvm with MIT License 5 votes vote down vote up
@Override
public InstrumentationContext<Document> beginParse(InstrumentationExecutionParameters parameters) {
    FederatedTracingState state = parameters.getInstrumentationState();
    if (state == null) {
        return super.beginParse(parameters);
    }

    return whenCompleted((document, throwable) -> {
        for (GraphQLError error : convertErrors(throwable, null)) {
            state.addRootError(error);
        }
    });
}
 
Example #3
Source File: QueryCache.java    From smallrye-graphql with Apache License 2.0 5 votes vote down vote up
@Override
public InstrumentationContext<List<ValidationError>> beginValidation(
        InstrumentationValidationParameters parameters) {

    ExecutionFunction executionFunction = executionFunctionTL.get();
    executionFunctionTL.remove();
    if (executionFunction != null) {
        return new ValidationInstrumentationContext(executionFunction);
    }
    return super.beginValidation(parameters);
}
 
Example #4
Source File: ComplexityAnalysisInstrumentation.java    From graphql-spqr with Apache License 2.0 5 votes vote down vote up
@Override
public InstrumentationContext<ExecutionResult> beginExecuteOperation(InstrumentationExecuteOperationParameters parameters) {
    ResolvedField root = new ComplexityAnalyzer(complexityFunction, maximumComplexity).collectFields(parameters.getExecutionContext());
    if (log.isDebugEnabled()) {
        log.debug("Operation {} has total complexity of {}",
                AstPrinter.printAst(parameters.getExecutionContext().getOperationDefinition().getSelectionSet().getSelections().get(0)),
                root.getComplexityScore());
    }
    log.info("Total operation complexity: {}", root.getComplexityScore());
    return super.beginExecuteOperation(parameters);
}