Package graphql

Class 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 the 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

    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.

    • 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
      • 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​(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 a ExecutionInput.Builder
        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 builder

        This will return a promise (aka CompletableFuture) to provide a ExecutionResult 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 builder

        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));
         
         
        Parameters:
        builderFunction - a function that is given a ExecutionInput.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 object

        This will return a promise (aka CompletableFuture) to provide a ExecutionResult which is the result of executing the provided query.

        Parameters:
        executionInput - ExecutionInput
        Returns:
        a promise to an ExecutionResult which can include errors