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
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description 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 builderExecutionResult
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()
static GraphQL.Builder
newGraphQL(GraphQLSchema graphQLSchema)
Helps you build a GraphQL object ready to execute queriesGraphQL
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.
-
-
-
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
-
-