graphql.nadel.instrumentation.parameters.NadelInstrumentationQueryExecutionParameters Maven / Gradle / Ivy
The newest version!
package graphql.nadel.instrumentation.parameters;
import graphql.ExecutionInput;
import graphql.PublicApi;
import graphql.execution.instrumentation.InstrumentationState;
import graphql.schema.GraphQLSchema;
import java.util.Collections;
import java.util.Map;
/**
* Parameters sent to {@link graphql.nadel.instrumentation.NadelInstrumentation} methods
*/
@PublicApi
public class NadelInstrumentationQueryExecutionParameters {
private final ExecutionInput executionInput;
private final String query;
private final String operation;
private final Object context;
private final Map variables;
private final InstrumentationState instrumentationState;
private final GraphQLSchema schema;
public NadelInstrumentationQueryExecutionParameters(ExecutionInput executionInput, GraphQLSchema schema, InstrumentationState instrumentationState) {
this.executionInput = executionInput;
this.query = executionInput.getQuery();
this.operation = executionInput.getOperationName();
this.context = executionInput.getContext();
this.variables = executionInput.getVariables() != null ? executionInput.getVariables() : Collections.emptyMap();
this.instrumentationState = instrumentationState;
this.schema = schema;
}
/**
* Returns a cloned parameters object with the new state
*
* @param instrumentationState the new state for this parameters object
*
* @return a new parameters object with the new state
*/
public NadelInstrumentationQueryExecutionParameters withNewState(InstrumentationState instrumentationState) {
return new NadelInstrumentationQueryExecutionParameters(this.getExecutionInput(), this.schema, instrumentationState);
}
public ExecutionInput getExecutionInput() {
return executionInput;
}
public String getQuery() {
return query;
}
public String getOperation() {
return operation;
}
@SuppressWarnings({"unchecked", "TypeParameterUnusedInFormals"})
public T getContext() {
return (T) context;
}
public Map getVariables() {
return variables;
}
@SuppressWarnings("TypeParameterUnusedInFormals")
public T getInstrumentationState() {
//noinspection unchecked
return (T) instrumentationState;
}
public GraphQLSchema getSchema() {
return this.schema;
}
}