@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 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 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 |
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.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
|
GraphQLSchema |
getGraphQLSchema() |
ExecutionIdProvider |
getIdProvider() |
Instrumentation |
getInstrumentation() |
ExecutionStrategy |
getMutationStrategy() |
PreparsedDocumentProvider |
getPreparsedDocumentProvider() |
ExecutionStrategy |
getQueryStrategy() |
ExecutionStrategy |
getSubscriptionStrategy() |
ValueUnboxer |
getValueUnboxer() |
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.
|
public GraphQLSchema getGraphQLSchema()
GraphQL
instancepublic ExecutionStrategy getQueryStrategy()
GraphQL
instancepublic ExecutionStrategy getMutationStrategy()
GraphQL
instancepublic ExecutionStrategy getSubscriptionStrategy()
GraphQL
instancepublic ExecutionIdProvider getIdProvider()
GraphQL
instancepublic Instrumentation getInstrumentation()
GraphQL
instance, if anypublic PreparsedDocumentProvider getPreparsedDocumentProvider()
GraphQL
instancepublic ValueUnboxer getValueUnboxer()
GraphQL
instancepublic 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 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