package graphql.execution.instrumentation;

import graphql.ExecutionResult;
import graphql.PublicApi;
import graphql.execution.instrumentation.parameters.InstrumentationExecuteOperationParameters;
import graphql.execution.instrumentation.parameters.InstrumentationExecutionParameters;
import graphql.execution.instrumentation.parameters.InstrumentationExecutionStrategyParameters;
import graphql.execution.instrumentation.parameters.InstrumentationFieldFetchParameters;
import graphql.execution.instrumentation.parameters.InstrumentationFieldParameters;
import graphql.execution.instrumentation.parameters.InstrumentationValidationParameters;
import graphql.language.Document;
import graphql.validation.ValidationError;

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

/**
 * An implementation of {@link graphql.execution.instrumentation.Instrumentation} that does nothing.  It can be used
 * as a base for derived classes where you only implement the methods you want to
 */
@PublicApi
public class SimpleInstrumentation implements Instrumentation {

    /**
     * A singleton instance of a {@link graphql.execution.instrumentation.Instrumentation} that does nothing
     */
    public static final SimpleInstrumentation INSTANCE = new SimpleInstrumentation();

    public SimpleInstrumentation() {
    }

    @Override
    public InstrumentationContext<ExecutionResult> beginExecution(InstrumentationExecutionParameters parameters) {
        return new SimpleInstrumentationContext<>();
    }

    @Override
    public InstrumentationContext<Document> beginParse(InstrumentationExecutionParameters parameters) {
        return new SimpleInstrumentationContext<>();
    }

    @Override
    public InstrumentationContext<List<ValidationError>> beginValidation(InstrumentationValidationParameters parameters) {
        return new SimpleInstrumentationContext<>();
    }

    @Override
    public ExecutionStrategyInstrumentationContext beginExecutionStrategy(InstrumentationExecutionStrategyParameters parameters) {
        return new ExecutionStrategyInstrumentationContext() {
            @Override
            public void onDispatched(CompletableFuture<ExecutionResult> result) {

            }

            @Override
            public void onCompleted(ExecutionResult result, Throwable t) {

            }
        };
    }

    @Override
    public InstrumentationContext<ExecutionResult> beginExecuteOperation(InstrumentationExecuteOperationParameters parameters) {
        return new SimpleInstrumentationContext<>();
    }

    @Override
    public InstrumentationContext<ExecutionResult> beginField(InstrumentationFieldParameters parameters) {
        return new SimpleInstrumentationContext<>();
    }

    @Override
    public InstrumentationContext<Object> beginFieldFetch(InstrumentationFieldFetchParameters parameters) {
        return new SimpleInstrumentationContext<>();
    }
}

@@ -1460,36 +1460,32 @@
 %0A        return 
-new 
 SimpleInstrument
@@ -1488,34 +1488,37 @@
 mentationContext
-%3C%3E
+.noOp
 ();%0A    %7D%0A%0A    @
@@ -1637,36 +1637,32 @@
 %0A        return 
-new 
 SimpleInstrument
@@ -1665,34 +1665,37 @@
 mentationContext
-%3C%3E
+.noOp
 ();%0A    %7D%0A%0A    @
@@ -1833,36 +1833,32 @@
 %0A        return 
-new 
 SimpleInstrument
@@ -1861,34 +1861,37 @@
 mentationContext
-%3C%3E
+.noOp
 ();%0A    %7D%0A%0A    @
@@ -2493,36 +2493,32 @@
 %0A        return 
-new 
 SimpleInstrument
@@ -2521,34 +2521,37 @@
 mentationContext
-%3C%3E
+.noOp
 ();%0A    %7D%0A%0A    @
@@ -2673,36 +2673,32 @@
 %0A        return 
-new 
 SimpleInstrument
@@ -2701,34 +2701,37 @@
 mentationContext
-%3C%3E
+.noOp
 ();%0A    %7D%0A%0A    @
@@ -2862,20 +2862,16 @@
  return 
-new 
 SimpleIn
@@ -2894,10 +2894,13 @@
 text
-%3C%3E
+.noOp
 ();%0A

fix #2131: less allocations in SimpleInstrumentation (#2184)