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 theschema
and theexecution 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 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 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 Modifier and Type Class Description static class
GraphQL.Builder
-
Field Summary
Fields Modifier and Type Field Description private GraphQLSchema
graphQLSchema
private ExecutionIdProvider
idProvider
private Instrumentation
instrumentation
private static org.slf4j.Logger
log
private static org.slf4j.Logger
logNotSafe
private ExecutionStrategy
mutationStrategy
private PreparsedDocumentProvider
preparsedDocumentProvider
private ExecutionStrategy
queryStrategy
private ExecutionStrategy
subscriptionStrategy
private ValueUnboxer
valueUnboxer
-
Constructor Summary
Constructors Modifier Constructor Description private
GraphQL(GraphQL.Builder builder)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description private static Instrumentation
checkInstrumentationDefaultState(Instrumentation instrumentation, boolean doNotAddDefaultInstrumentations)
private ExecutionInput
ensureInputHasId(ExecutionInput executionInput)
ExecutionResult
execute(ExecutionInput executionInput)
Executes the graphql query using the provided input objectExecutionResult
execute(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)
ExecutionResult
execute(java.lang.String query)
Executes the specified graphql query/mutation/subscriptionExecutionResult
execute(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 builderGraphQLSchema
getGraphQLSchema()
ExecutionIdProvider
getIdProvider()
Instrumentation
getInstrumentation()
ExecutionStrategy
getMutationStrategy()
PreparsedDocumentProvider
getPreparsedDocumentProvider()
ExecutionStrategy
getQueryStrategy()
ExecutionStrategy
getSubscriptionStrategy()
ValueUnboxer
getValueUnboxer()
private java.util.concurrent.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(java.util.concurrent.atomic.AtomicReference<ExecutionInput> executionInputRef, GraphQLSchema graphQLSchema, InstrumentationState instrumentationState)
private java.util.concurrent.CompletableFuture<ExecutionResult>
parseValidateAndExecute(ExecutionInput executionInput, GraphQLSchema graphQLSchema, InstrumentationState instrumentationState)
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.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
GraphQL
instance
-
getQueryStrategy
public ExecutionStrategy getQueryStrategy()
- Returns:
- the execution strategy used for queries in this
GraphQL
instance
-
getMutationStrategy
public ExecutionStrategy getMutationStrategy()
- Returns:
- the execution strategy used for mutation in this
GraphQL
instance
-
getSubscriptionStrategy
public ExecutionStrategy getSubscriptionStrategy()
- Returns:
- the execution strategy used for subscriptions in this
GraphQL
instance
-
getIdProvider
public ExecutionIdProvider getIdProvider()
- Returns:
- the provider of execution ids for this
GraphQL
instance
-
getInstrumentation
public Instrumentation getInstrumentation()
- Returns:
- the Instrumentation for this
GraphQL
instance, if any
-
getPreparsedDocumentProvider
public PreparsedDocumentProvider getPreparsedDocumentProvider()
- Returns:
- the PreparsedDocumentProvider for this
GraphQL
instance
-
getValueUnboxer
public ValueUnboxer getValueUnboxer()
- Returns:
- the ValueUnboxer for this
GraphQL
instance
-
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
ExecutionResult
which 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
ExecutionResult
which 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
ExecutionResult
which can include errors
-
execute
public ExecutionResult execute(ExecutionInput executionInput)
Executes the graphql query using the provided input object- Parameters:
executionInput
-ExecutionInput
- Returns:
- an
ExecutionResult
which 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 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 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 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
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 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 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)
-
-