Class GraphQL
- java.lang.Object
-
- graphql.GraphQL
-
@PublicApi public class GraphQL extends java.lang.Object
This class is where all graphql-java query execution begins. It combines the objects that are needed to make a successful graphql query, with the most important being theschemaand theexecution strategyBuilding this object is very cheap and can be done on each execution if necessary. Building the schema is often not as cheap, especially if it's parsed from graphql IDL schema format via
SchemaParser.The data for a query is returned via
ExecutionResult.getData()and any errors encountered as placed inExecutionResult.getErrors().Runtime Exceptions
Runtime exceptions can be thrown by the graphql engine if certain situations are encountered. These are not errors in execution but rather totally unacceptable conditions in which to execute a graphql query.
CoercingSerializeException- is thrown when a value cannot be serialised by a Scalar type, for example a String value being coerced as an Int.UnresolvedTypeException- is thrown if aTypeResolverfails to provide a concrete object type given a interface or union type.InvalidSchemaException- is thrown if the schema is not valid when built viaGraphQLSchema.Builder.build()GraphQLException- is thrown as a general purpose runtime exception, for example if the code cant access a named field when examining a POJO.AssertException- is thrown as a low level code assertion exception for truly unexpected code conditions
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classGraphQL.Builder
-
Field Summary
Fields Modifier and Type Field Description private GraphQLSchemagraphQLSchemaprivate ExecutionIdProvideridProviderprivate Instrumentationinstrumentationprivate static org.slf4j.Loggerlogprivate static org.slf4j.LoggerlogNotSafeprivate ExecutionStrategymutationStrategyprivate PreparsedDocumentProviderpreparsedDocumentProviderprivate ExecutionStrategyqueryStrategyprivate ExecutionStrategysubscriptionStrategyprivate ValueUnboxervalueUnboxer
-
Constructor Summary
Constructors Modifier Constructor Description privateGraphQL(GraphQL.Builder builder)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description private static InstrumentationcheckInstrumentationDefaultState(Instrumentation instrumentation, boolean doNotAddDefaultInstrumentations)private ExecutionInputensureInputHasId(ExecutionInput executionInput)ExecutionResultexecute(ExecutionInput executionInput)Executes the graphql query using the provided input objectExecutionResultexecute(ExecutionInput.Builder executionInputBuilder)Executes the graphql query using the provided input object builderprivate java.util.concurrent.CompletableFuture<ExecutionResult>execute(ExecutionInput executionInput, Document document, GraphQLSchema graphQLSchema, InstrumentationState instrumentationState)ExecutionResultexecute(java.lang.String query)Executes the specified graphql query/mutation/subscriptionExecutionResultexecute(java.util.function.UnaryOperator<ExecutionInput.Builder> builderFunction)Executes the graphql query using calling the builder function and giving it a new builder.java.util.concurrent.CompletableFuture<ExecutionResult>executeAsync(ExecutionInput executionInput)Executes the graphql query using the provided input objectjava.util.concurrent.CompletableFuture<ExecutionResult>executeAsync(ExecutionInput.Builder executionInputBuilder)Executes the graphql query using the provided input object builderjava.util.concurrent.CompletableFuture<ExecutionResult>executeAsync(java.util.function.UnaryOperator<ExecutionInput.Builder> builderFunction)Executes the graphql query using the provided input object builderGraphQLSchemagetGraphQLSchema()ExecutionIdProvidergetIdProvider()InstrumentationgetInstrumentation()ExecutionStrategygetMutationStrategy()PreparsedDocumentProvidergetPreparsedDocumentProvider()ExecutionStrategygetQueryStrategy()ExecutionStrategygetSubscriptionStrategy()ValueUnboxergetValueUnboxer()private java.util.concurrent.CompletableFuture<ExecutionResult>handleAbortException(ExecutionInput executionInput, InstrumentationState instrumentationState, AbortExecutionException abortException)static GraphQL.BuildernewGraphQL(GraphQLSchema graphQLSchema)Helps you build a GraphQL object ready to execute queriesprivate ParseAndValidateResultparse(ExecutionInput executionInput, GraphQLSchema graphQLSchema, InstrumentationState instrumentationState)private PreparsedDocumentEntryparseAndValidate(java.util.concurrent.atomic.AtomicReference<ExecutionInput> executionInputRef, GraphQLSchema graphQLSchema, InstrumentationState instrumentationState)private java.util.concurrent.CompletableFuture<ExecutionResult>parseValidateAndExecute(ExecutionInput executionInput, GraphQLSchema graphQLSchema, InstrumentationState instrumentationState)GraphQLtransform(java.util.function.Consumer<GraphQL.Builder> builderConsumer)This helps you transform the current GraphQL object into another one by starting a builder with all the current values and allows you to transform it how you want.private java.util.List<ValidationError>validate(ExecutionInput executionInput, Document document, GraphQLSchema graphQLSchema, InstrumentationState instrumentationState)
-
-
-
Field Detail
-
log
private static final org.slf4j.Logger log
-
logNotSafe
private static final org.slf4j.Logger logNotSafe
-
graphQLSchema
private final GraphQLSchema graphQLSchema
-
queryStrategy
private final ExecutionStrategy queryStrategy
-
mutationStrategy
private final ExecutionStrategy mutationStrategy
-
subscriptionStrategy
private final ExecutionStrategy subscriptionStrategy
-
idProvider
private final ExecutionIdProvider idProvider
-
instrumentation
private final Instrumentation instrumentation
-
preparsedDocumentProvider
private final PreparsedDocumentProvider preparsedDocumentProvider
-
valueUnboxer
private final ValueUnboxer valueUnboxer
-
-
Constructor Detail
-
GraphQL
private GraphQL(GraphQL.Builder builder)
-
-
Method Detail
-
getGraphQLSchema
public GraphQLSchema getGraphQLSchema()
- Returns:
- the schema backing this
GraphQLinstance
-
getQueryStrategy
public ExecutionStrategy getQueryStrategy()
- Returns:
- the execution strategy used for queries in this
GraphQLinstance
-
getMutationStrategy
public ExecutionStrategy getMutationStrategy()
- Returns:
- the execution strategy used for mutation in this
GraphQLinstance
-
getSubscriptionStrategy
public ExecutionStrategy getSubscriptionStrategy()
- Returns:
- the execution strategy used for subscriptions in this
GraphQLinstance
-
getIdProvider
public ExecutionIdProvider getIdProvider()
- Returns:
- the provider of execution ids for this
GraphQLinstance
-
getInstrumentation
public Instrumentation getInstrumentation()
- Returns:
- the Instrumentation for this
GraphQLinstance, if any
-
getPreparsedDocumentProvider
public PreparsedDocumentProvider getPreparsedDocumentProvider()
- Returns:
- the PreparsedDocumentProvider for this
GraphQLinstance
-
getValueUnboxer
public ValueUnboxer getValueUnboxer()
- Returns:
- the ValueUnboxer for this
GraphQLinstance
-
newGraphQL
public static GraphQL.Builder newGraphQL(GraphQLSchema graphQLSchema)
Helps you build a GraphQL object ready to execute queries- Parameters:
graphQLSchema- the schema to use- Returns:
- a builder of GraphQL objects
-
transform
public GraphQL transform(java.util.function.Consumer<GraphQL.Builder> builderConsumer)
This helps you transform the current GraphQL object into another one by starting a builder with all the current values and allows you to transform it how you want.- Parameters:
builderConsumer- the consumer code that will be given a builder to transform- Returns:
- a new GraphQL object based on calling build on that builder
-
execute
public ExecutionResult execute(java.lang.String query)
Executes the specified graphql query/mutation/subscription- Parameters:
query- the query/mutation/subscription- Returns:
- an
ExecutionResultwhich can include errors
-
execute
public ExecutionResult execute(ExecutionInput.Builder executionInputBuilder)
Executes the graphql query using the provided input object builder- Parameters:
executionInputBuilder-ExecutionInput.Builder- Returns:
- an
ExecutionResultwhich can include errors
-
execute
public ExecutionResult execute(java.util.function.UnaryOperator<ExecutionInput.Builder> builderFunction)
Executes the graphql query using calling the builder function and giving it a new builder.This allows a lambda style like :
ExecutionResult result = graphql.execute(input -> input.query("{hello}").root(startingObj).context(contextObj));- Parameters:
builderFunction- a function that is given aExecutionInput.Builder- Returns:
- an
ExecutionResultwhich can include errors
-
execute
public ExecutionResult execute(ExecutionInput executionInput)
Executes the graphql query using the provided input object- Parameters:
executionInput-ExecutionInput- Returns:
- an
ExecutionResultwhich can include errors
-
executeAsync
public java.util.concurrent.CompletableFuture<ExecutionResult> executeAsync(ExecutionInput.Builder executionInputBuilder)
Executes the graphql query using the provided input object builderThis will return a promise (aka
CompletableFuture) to provide aExecutionResultwhich is the result of executing the provided query.- Parameters:
executionInputBuilder-ExecutionInput.Builder- Returns:
- a promise to an
ExecutionResultwhich can include errors
-
executeAsync
public java.util.concurrent.CompletableFuture<ExecutionResult> executeAsync(java.util.function.UnaryOperator<ExecutionInput.Builder> builderFunction)
Executes the graphql query using the provided input object builderThis will return a promise (aka
CompletableFuture) to provide aExecutionResultwhich is the result of executing the provided query.This allows a lambda style like :
ExecutionResult result = graphql.execute(input -> input.query("{hello}").root(startingObj).context(contextObj));- Parameters:
builderFunction- a function that is given aExecutionInput.Builder- Returns:
- a promise to an
ExecutionResultwhich can include errors
-
executeAsync
public java.util.concurrent.CompletableFuture<ExecutionResult> executeAsync(ExecutionInput executionInput)
Executes the graphql query using the provided input objectThis will return a promise (aka
CompletableFuture) to provide aExecutionResultwhich is the result of executing the provided query.- Parameters:
executionInput-ExecutionInput- Returns:
- a promise to an
ExecutionResultwhich can include errors
-
handleAbortException
private java.util.concurrent.CompletableFuture<ExecutionResult> handleAbortException(ExecutionInput executionInput, InstrumentationState instrumentationState, AbortExecutionException abortException)
-
ensureInputHasId
private ExecutionInput ensureInputHasId(ExecutionInput executionInput)
-
parseValidateAndExecute
private java.util.concurrent.CompletableFuture<ExecutionResult> parseValidateAndExecute(ExecutionInput executionInput, GraphQLSchema graphQLSchema, InstrumentationState instrumentationState)
-
parseAndValidate
private PreparsedDocumentEntry parseAndValidate(java.util.concurrent.atomic.AtomicReference<ExecutionInput> executionInputRef, GraphQLSchema graphQLSchema, InstrumentationState instrumentationState)
-
parse
private ParseAndValidateResult parse(ExecutionInput executionInput, GraphQLSchema graphQLSchema, InstrumentationState instrumentationState)
-
validate
private java.util.List<ValidationError> validate(ExecutionInput executionInput, Document document, GraphQLSchema graphQLSchema, InstrumentationState instrumentationState)
-
execute
private java.util.concurrent.CompletableFuture<ExecutionResult> execute(ExecutionInput executionInput, Document document, GraphQLSchema graphQLSchema, InstrumentationState instrumentationState)
-
checkInstrumentationDefaultState
private static Instrumentation checkInstrumentationDefaultState(Instrumentation instrumentation, boolean doNotAddDefaultInstrumentations)
-
-