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 theschemaand theexecution strategyBuilding 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 aTypeResolverfails 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 classGraphQL.Builder
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description ExecutionResultexecute(ExecutionInput executionInput)Executes the graphql query using the provided input objectExecutionResultexecute(ExecutionInput.Builder executionInputBuilder)Executes the graphql query using the provided input object builderExecutionResultexecute(java.lang.String query)Executes the specified graphql query/mutation/subscriptionExecutionResultexecute(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 builderGraphQLSchemagetGraphQLSchema()ExecutionIdProvidergetIdProvider()InstrumentationgetInstrumentation()ExecutionStrategygetMutationStrategy()PreparsedDocumentProvidergetPreparsedDocumentProvider()ExecutionStrategygetQueryStrategy()ExecutionStrategygetSubscriptionStrategy()ValueUnboxergetValueUnboxer()booleanisDoNotAutomaticallyDispatchDataLoader()static GraphQL.BuildernewGraphQL(GraphQLSchema graphQLSchema)Helps you build a GraphQL object ready to execute queriesGraphQLtransform(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
GraphQLinstance
-
getQueryStrategy
public ExecutionStrategy getQueryStrategy()
- Returns:
- the execution strategy used for queries in this
GraphQLinstance
-
getMutationStrategy
public ExecutionStrategy getMutationStrategy()
- Returns:
- the execution strategy used for mutation in this
GraphQLinstance
-
getSubscriptionStrategy
public ExecutionStrategy getSubscriptionStrategy()
- Returns:
- the execution strategy used for subscriptions in this
GraphQLinstance
-
getIdProvider
public ExecutionIdProvider getIdProvider()
- Returns:
- the provider of execution ids for this
GraphQLinstance
-
getInstrumentation
public Instrumentation getInstrumentation()
- Returns:
- the Instrumentation for this
GraphQLinstance, if any
-
isDoNotAutomaticallyDispatchDataLoader
public boolean isDoNotAutomaticallyDispatchDataLoader()
-
getPreparsedDocumentProvider
public PreparsedDocumentProvider getPreparsedDocumentProvider()
- Returns:
- the PreparsedDocumentProvider for this
GraphQLinstance
-
getValueUnboxer
public ValueUnboxer getValueUnboxer()
- Returns:
- the ValueUnboxer for this
GraphQLinstance
-
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
ExecutionResultwhich 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
ExecutionResultwhich 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
ExecutionResultwhich can include errors
-
execute
public ExecutionResult execute(ExecutionInput executionInput)
Executes the graphql query using the provided input object- Parameters:
executionInput-ExecutionInput- Returns:
- an
ExecutionResultwhich 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 aExecutionResultwhich is the result of executing the provided query.- Parameters:
executionInputBuilder-ExecutionInput.Builder- Returns:
- a promise to an
ExecutionResultwhich 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 aExecutionResultwhich 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
ExecutionResultwhich 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 aExecutionResultwhich is the result of executing the provided query.- Parameters:
executionInput-ExecutionInput- Returns:
- a promise to an
ExecutionResultwhich can include errors
-
-