Class GraphQL
schema
and the execution strategy
Building 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 in
ExecutionResult.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 aTypeResolver
fails 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 -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final GraphQLSchema
private final ExecutionIdProvider
private final Instrumentation
private static final org.slf4j.Logger
private static final org.slf4j.Logger
private final ExecutionStrategy
private final PreparsedDocumentProvider
private final ExecutionStrategy
private final ExecutionStrategy
private final ValueUnboxer
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprivate static Instrumentation
checkInstrumentationDefaultState
(Instrumentation instrumentation, boolean doNotAddDefaultInstrumentations) private ExecutionInput
ensureInputHasId
(ExecutionInput executionInput) execute
(ExecutionInput executionInput) Executes the graphql query using the provided input objectexecute
(ExecutionInput.Builder executionInputBuilder) Executes the graphql query using the provided input object builderprivate CompletableFuture
<ExecutionResult> execute
(ExecutionInput executionInput, Document document, GraphQLSchema graphQLSchema, InstrumentationState instrumentationState) Executes the specified graphql query/mutation/subscriptionexecute
(UnaryOperator<ExecutionInput.Builder> builderFunction) Executes the graphql query using calling the builder function and giving it a new builder.executeAsync
(ExecutionInput executionInput) Executes the graphql query using the provided input objectexecuteAsync
(ExecutionInput.Builder executionInputBuilder) Executes the graphql query using the provided input object builderexecuteAsync
(UnaryOperator<ExecutionInput.Builder> builderFunction) Executes the graphql query using the provided input object builderprivate CompletableFuture
<ExecutionResult> handleAbortException
(ExecutionInput executionInput, InstrumentationState instrumentationState, AbortExecutionException abortException) static GraphQL.Builder
newGraphQL
(GraphQLSchema graphQLSchema) Helps you build a GraphQL object ready to execute queriesprivate ParseAndValidateResult
parse
(ExecutionInput executionInput, GraphQLSchema graphQLSchema, InstrumentationState instrumentationState) private PreparsedDocumentEntry
parseAndValidate
(AtomicReference<ExecutionInput> executionInputRef, GraphQLSchema graphQLSchema, InstrumentationState instrumentationState) private CompletableFuture
<ExecutionResult> parseValidateAndExecute
(ExecutionInput executionInput, GraphQLSchema graphQLSchema, InstrumentationState instrumentationState) transform
(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 List
<ValidationError> validate
(ExecutionInput executionInput, Document document, GraphQLSchema graphQLSchema, InstrumentationState instrumentationState)
-
Field Details
-
log
private static final org.slf4j.Logger log -
logNotSafe
private static final org.slf4j.Logger logNotSafe -
graphQLSchema
-
queryStrategy
-
mutationStrategy
-
subscriptionStrategy
-
idProvider
-
instrumentation
-
preparsedDocumentProvider
-
valueUnboxer
-
-
Constructor Details
-
GraphQL
-
-
Method Details
-
getGraphQLSchema
- Returns:
- the schema backing this
GraphQL
instance
-
getQueryStrategy
- Returns:
- the execution strategy used for queries in this
GraphQL
instance
-
getMutationStrategy
- Returns:
- the execution strategy used for mutation in this
GraphQL
instance
-
getSubscriptionStrategy
- Returns:
- the execution strategy used for subscriptions in this
GraphQL
instance
-
getIdProvider
- Returns:
- the provider of execution ids for this
GraphQL
instance
-
getInstrumentation
- Returns:
- the Instrumentation for this
GraphQL
instance, if any
-
getPreparsedDocumentProvider
- Returns:
- the PreparsedDocumentProvider for this
GraphQL
instance
-
getValueUnboxer
- Returns:
- the ValueUnboxer for this
GraphQL
instance
-
newGraphQL
Helps you build a GraphQL object ready to execute queries- Parameters:
graphQLSchema
- the schema to use- Returns:
- a builder of GraphQL objects
-
transform
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
Executes the specified graphql query/mutation/subscription- Parameters:
query
- the query/mutation/subscription- Returns:
- an
ExecutionResult
which can include errors
-
execute
Executes the graphql query using the provided input object builder- Parameters:
executionInputBuilder
-ExecutionInput.Builder
- Returns:
- an
ExecutionResult
which can include errors
-
execute
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
ExecutionResult
which can include errors
-
execute
Executes the graphql query using the provided input object- Parameters:
executionInput
-ExecutionInput
- Returns:
- an
ExecutionResult
which can include errors
-
executeAsync
public CompletableFuture<ExecutionResult> executeAsync(ExecutionInput.Builder executionInputBuilder) Executes the graphql query using the provided input object builderThis will return a promise (aka
CompletableFuture
) to provide aExecutionResult
which is the result of executing the provided query.- Parameters:
executionInputBuilder
-ExecutionInput.Builder
- Returns:
- a promise to an
ExecutionResult
which can include errors
-
executeAsync
public CompletableFuture<ExecutionResult> executeAsync(UnaryOperator<ExecutionInput.Builder> builderFunction) Executes the graphql query using the provided input object builderThis will return a promise (aka
CompletableFuture
) to provide aExecutionResult
which 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
ExecutionResult
which can include errors
-
executeAsync
Executes the graphql query using the provided input objectThis will return a promise (aka
CompletableFuture
) to provide aExecutionResult
which is the result of executing the provided query.- Parameters:
executionInput
-ExecutionInput
- Returns:
- a promise to an
ExecutionResult
which can include errors
-
handleAbortException
private CompletableFuture<ExecutionResult> handleAbortException(ExecutionInput executionInput, InstrumentationState instrumentationState, AbortExecutionException abortException) -
ensureInputHasId
-
parseValidateAndExecute
private CompletableFuture<ExecutionResult> parseValidateAndExecute(ExecutionInput executionInput, GraphQLSchema graphQLSchema, InstrumentationState instrumentationState) -
parseAndValidate
private PreparsedDocumentEntry parseAndValidate(AtomicReference<ExecutionInput> executionInputRef, GraphQLSchema graphQLSchema, InstrumentationState instrumentationState) -
parse
private ParseAndValidateResult parse(ExecutionInput executionInput, GraphQLSchema graphQLSchema, InstrumentationState instrumentationState) -
validate
private List<ValidationError> validate(ExecutionInput executionInput, Document document, GraphQLSchema graphQLSchema, InstrumentationState instrumentationState) -
execute
private CompletableFuture<ExecutionResult> execute(ExecutionInput executionInput, Document document, GraphQLSchema graphQLSchema, InstrumentationState instrumentationState) -
checkInstrumentationDefaultState
private static Instrumentation checkInstrumentationDefaultState(Instrumentation instrumentation, boolean doNotAddDefaultInstrumentations)
-