Search in sources :

Example 6 with ExecutionInput

use of graphql.ExecutionInput in project graphql-java by graphql-java.

the class ExecutionExamples method simpleAsyncQueryExecution.

@SuppressWarnings("Convert2MethodRef")
private void simpleAsyncQueryExecution() throws Exception {
    GraphQL graphQL = buildSchema();
    ExecutionInput executionInput = ExecutionInput.newExecutionInput().query("query { hero { name } }").build();
    CompletableFuture<ExecutionResult> promise = graphQL.executeAsync(executionInput);
    promise.thenAccept(executionResult -> {
        // here you might send back the results as JSON over HTTP
        encodeResultToJsonAndSendResponse(executionResult);
    });
    promise.join();
}
Also used : GraphQL(graphql.GraphQL) ExecutionResult(graphql.ExecutionResult) ExecutionInput(graphql.ExecutionInput)

Example 7 with ExecutionInput

use of graphql.ExecutionInput in project graphql-java by graphql-java.

the class BatchCompare method dataLoaderRun.

void dataLoaderRun() {
    System.out.println("=== AsyncExecutionStrategy with DataLoader ===");
    GraphQLSchema schema = buildDataLoaderSchema();
    DataLoaderRegistry dataLoaderRegistry = new DataLoaderRegistry();
    dataLoaderRegistry.register("departments", BatchCompareDataFetchers.departmentsForShopDataLoader);
    dataLoaderRegistry.register("products", BatchCompareDataFetchers.productsForDepartmentDataLoader);
    GraphQL graphQL = GraphQL.newGraphQL(schema).instrumentation(new DataLoaderDispatcherInstrumentation(dataLoaderRegistry)).build();
    ExecutionInput executionInput = ExecutionInput.newExecutionInput().query("query { shops { id name departments { id name products { id name } } } }").build();
    ExecutionResult result = graphQL.execute(executionInput);
    System.out.println("\nExecutionResult: " + result.toSpecification());
}
Also used : DataLoaderRegistry(org.dataloader.DataLoaderRegistry) GraphQL(graphql.GraphQL) ExecutionResult(graphql.ExecutionResult) ExecutionInput(graphql.ExecutionInput) GraphQLSchema(graphql.schema.GraphQLSchema)

Aggregations

ExecutionInput (graphql.ExecutionInput)7 ExecutionResult (graphql.ExecutionResult)7 GraphQL (graphql.GraphQL)5 GraphQLSchema (graphql.schema.GraphQLSchema)4 GraphQLError (graphql.GraphQLError)2 DataLoaderRegistry (org.dataloader.DataLoaderRegistry)2 JsonArray (com.google.gson.JsonArray)1 JsonObject (com.google.gson.JsonObject)1 ExecutionInput.newExecutionInput (graphql.ExecutionInput.newExecutionInput)1 BatchedExecutionStrategy (graphql.execution.batched.BatchedExecutionStrategy)1 ChainedInstrumentation (graphql.execution.instrumentation.ChainedInstrumentation)1 Instrumentation (graphql.execution.instrumentation.Instrumentation)1 DataLoaderDispatcherInstrumentation (graphql.execution.instrumentation.dataloader.DataLoaderDispatcherInstrumentation)1 TracingInstrumentation (graphql.execution.instrumentation.tracing.TracingInstrumentation)1 DataFetcher (graphql.schema.DataFetcher)1 DataFetchingEnvironment (graphql.schema.DataFetchingEnvironment)1 HashMap (java.util.HashMap)1