@PublicApi public class GraphQL extends java.lang.Object
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 its 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 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 a TypeResolver
fails to provide a concrete
object type given a interface or union type.
InvalidSchemaException
- is thrown if the schema is not valid when built via
GraphQLSchema.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
Modifier and Type | Class and Description |
---|---|
static class |
GraphQL.Builder |
Constructor and Description |
---|
GraphQL(GraphQLSchema graphQLSchema)
Deprecated.
use the
newGraphQL(GraphQLSchema) builder instead. This will be removed in a future version. |
GraphQL(GraphQLSchema graphQLSchema,
ExecutionStrategy queryStrategy)
Deprecated.
use the
newGraphQL(GraphQLSchema) builder instead. This will be removed in a future version. |
GraphQL(GraphQLSchema graphQLSchema,
ExecutionStrategy queryStrategy,
ExecutionStrategy mutationStrategy)
Deprecated.
use the
newGraphQL(GraphQLSchema) builder instead. This will be removed in a future version. |
GraphQL(GraphQLSchema graphQLSchema,
ExecutionStrategy queryStrategy,
ExecutionStrategy mutationStrategy,
ExecutionStrategy subscriptionStrategy)
Deprecated.
use the
newGraphQL(GraphQLSchema) builder instead. This will be removed in a future version. |
Modifier and Type | Method and Description |
---|---|
ExecutionResult |
execute(ExecutionInput.Builder executionInputBuilder)
Executes the graphql query using the provided input object builder
|
ExecutionResult |
execute(ExecutionInput executionInput)
Executes the graphql query using the provided input object
|
ExecutionResult |
execute(java.lang.String query)
Executes the specified graphql query/mutation/subscription
|
ExecutionResult |
execute(java.lang.String query,
java.lang.Object context)
Deprecated.
|
ExecutionResult |
execute(java.lang.String query,
java.lang.Object context,
java.util.Map<java.lang.String,java.lang.Object> variables)
Deprecated.
|
ExecutionResult |
execute(java.lang.String query,
java.lang.String operationName,
java.lang.Object context)
Deprecated.
|
ExecutionResult |
execute(java.lang.String query,
java.lang.String operationName,
java.lang.Object context,
java.util.Map<java.lang.String,java.lang.Object> variables)
Deprecated.
|
ExecutionResult |
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.Builder executionInputBuilder)
Executes the graphql query using the provided input object builder
|
java.util.concurrent.CompletableFuture<ExecutionResult> |
executeAsync(ExecutionInput executionInput)
Executes the graphql query using the provided input object
|
java.util.concurrent.CompletableFuture<ExecutionResult> |
executeAsync(java.util.function.UnaryOperator<ExecutionInput.Builder> builderFunction)
Executes the graphql query using the provided input object builder
|
static GraphQL.Builder |
newGraphQL(GraphQLSchema graphQLSchema)
Helps you build a GraphQL object ready to execute queries
|
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.
|
@Deprecated public GraphQL(GraphQLSchema graphQLSchema)
newGraphQL(GraphQLSchema)
builder instead. This will be removed in a future version.graphQLSchema
- the schema to use@Deprecated public GraphQL(GraphQLSchema graphQLSchema, ExecutionStrategy queryStrategy)
newGraphQL(GraphQLSchema)
builder instead. This will be removed in a future version.graphQLSchema
- the schema to usequeryStrategy
- the query execution strategy to use@Deprecated public GraphQL(GraphQLSchema graphQLSchema, ExecutionStrategy queryStrategy, ExecutionStrategy mutationStrategy)
newGraphQL(GraphQLSchema)
builder instead. This will be removed in a future version.graphQLSchema
- the schema to usequeryStrategy
- the query execution strategy to usemutationStrategy
- the mutation execution strategy to use@Deprecated public GraphQL(GraphQLSchema graphQLSchema, ExecutionStrategy queryStrategy, ExecutionStrategy mutationStrategy, ExecutionStrategy subscriptionStrategy)
newGraphQL(GraphQLSchema)
builder instead. This will be removed in a future version.graphQLSchema
- the schema to usequeryStrategy
- the query execution strategy to usemutationStrategy
- the mutation execution strategy to usesubscriptionStrategy
- the subscription execution strategy to usepublic static GraphQL.Builder newGraphQL(GraphQLSchema graphQLSchema)
graphQLSchema
- the schema to usepublic GraphQL transform(java.util.function.Consumer<GraphQL.Builder> builderConsumer)
builderConsumer
- the consumer code that will be given a builder to transformpublic ExecutionResult execute(java.lang.String query)
query
- the query/mutation/subscriptionExecutionResult
which can include errors@Deprecated public ExecutionResult execute(java.lang.String query, java.lang.Object context)
execute(ExecutionInput)
query
- the query/mutation/subscriptioncontext
- custom object provided to each DataFetcher
ExecutionResult
which can include errors@Deprecated public ExecutionResult execute(java.lang.String query, java.lang.String operationName, java.lang.Object context)
execute(ExecutionInput)
query
- the query/mutation/subscriptionoperationName
- the name of the operation to executecontext
- custom object provided to each DataFetcher
ExecutionResult
which can include errors@Deprecated public ExecutionResult execute(java.lang.String query, java.lang.Object context, java.util.Map<java.lang.String,java.lang.Object> variables)
execute(ExecutionInput)
query
- the query/mutation/subscriptioncontext
- custom object provided to each DataFetcher
variables
- variable values uses as argumentExecutionResult
which can include errors@Deprecated public ExecutionResult execute(java.lang.String query, java.lang.String operationName, java.lang.Object context, java.util.Map<java.lang.String,java.lang.Object> variables)
execute(ExecutionInput)
query
- the query/mutation/subscriptionoperationName
- name of the operation to executecontext
- custom object provided to each DataFetcher
variables
- variable values uses as argumentExecutionResult
which can include errorspublic ExecutionResult execute(ExecutionInput.Builder executionInputBuilder)
executionInputBuilder
- ExecutionInput.Builder
ExecutionResult
which can include errorspublic ExecutionResult execute(java.util.function.UnaryOperator<ExecutionInput.Builder> builderFunction)
This allows a lambda style like :
ExecutionResult result = graphql.execute(input -> input.query("{hello}").root(startingObj).context(contextObj));
builderFunction
- a function that is given a ExecutionInput.Builder
ExecutionResult
which can include errorspublic ExecutionResult execute(ExecutionInput executionInput)
executionInput
- ExecutionInput
ExecutionResult
which can include errorspublic java.util.concurrent.CompletableFuture<ExecutionResult> executeAsync(ExecutionInput.Builder executionInputBuilder)
This will return a promise (aka CompletableFuture
) to provide a ExecutionResult
which is the result of executing the provided query.
executionInputBuilder
- ExecutionInput.Builder
ExecutionResult
which can include errorspublic java.util.concurrent.CompletableFuture<ExecutionResult> executeAsync(java.util.function.UnaryOperator<ExecutionInput.Builder> builderFunction)
This will return a promise (aka CompletableFuture
) to provide a ExecutionResult
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));
builderFunction
- a function that is given a ExecutionInput.Builder
ExecutionResult
which can include errorspublic java.util.concurrent.CompletableFuture<ExecutionResult> executeAsync(ExecutionInput executionInput)
This will return a promise (aka CompletableFuture
) to provide a ExecutionResult
which is the result of executing the provided query.
executionInput
- ExecutionInput
ExecutionResult
which can include errors