use of graphql.ExecutionResult in project graphql-java by graphql-java.
the class BreadthFirstExecutionTestStrategy method completeValue.
private void completeValue(ExecutionContext executionContext, Map<String, Object> results, String fieldName, Object fetchedValue, ExecutionStrategyParameters newParameters) {
ExecutionResult resolvedResult = completeField(executionContext, newParameters, fetchedValue).join();
results.put(fieldName, resolvedResult != null ? resolvedResult.getData() : null);
}
use of graphql.ExecutionResult in project graphql-java by graphql-java.
the class BreadthFirstTestStrategy method completeFields.
private CompletableFuture<ExecutionResult> completeFields(ExecutionContext executionContext, ExecutionStrategyParameters parameters, Map<String, Object> fetchedValues) {
Map<String, List<Field>> fields = parameters.getFields();
// then for every fetched value, complete it, breath first
Map<String, Object> results = new LinkedHashMap<>();
for (String fieldName : fetchedValues.keySet()) {
List<Field> fieldList = fields.get(fieldName);
ExecutionStrategyParameters newParameters = newParameters(parameters, fields, fieldName);
Object fetchedValue = fetchedValues.get(fieldName);
try {
ExecutionResult resolvedResult = completeField(executionContext, newParameters, fetchedValue).join();
results.put(fieldName, resolvedResult != null ? resolvedResult.getData() : null);
} catch (NonNullableFieldWasNullException e) {
assertNonNullFieldPrecondition(e);
results = null;
break;
}
}
return CompletableFuture.completedFuture(new ExecutionResultImpl(results, executionContext.getErrors()));
}
use of graphql.ExecutionResult 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());
}
use of graphql.ExecutionResult in project graphql-java by graphql-java.
the class SubscriptionExamples method basicSubscriptionExample.
void basicSubscriptionExample() {
GraphQL graphQL = GraphQL.newGraphQL(schema).subscriptionExecutionStrategy(new SubscriptionExecutionStrategy()).build();
String query = "" + " subscription StockCodeSubscription {\n" + " stockQuotes(stockCode:\"IBM') {\n" + " dateTime\n" + " stockCode\n" + " stockPrice\n" + " stockPriceChange\n" + " }\n" + " }\n";
ExecutionResult executionResult = graphQL.execute(query);
Publisher<ExecutionResult> stockPriceStream = executionResult.getData();
AtomicReference<Subscription> subscriptionRef = new AtomicReference<>();
stockPriceStream.subscribe(new Subscriber<ExecutionResult>() {
@Override
public void onSubscribe(Subscription s) {
subscriptionRef.set(s);
s.request(1);
}
@Override
public void onNext(ExecutionResult er) {
//
// process the next stock price
//
processStockPriceChange(er.getData());
//
// ask the publisher for one more item please
//
subscriptionRef.get().request(1);
}
@Override
public void onError(Throwable t) {
//
// The upstream publishing data source has encountered an error
// and the subscription is now terminated. Real production code needs
// to decide on a error handling strategy.
//
}
@Override
public void onComplete() {
//
// the subscription has completed. There is not more data
//
}
});
}
use of graphql.ExecutionResult in project graphql-java by graphql-java.
the class DiffSet method introspect.
private static Map<String, Object> introspect(GraphQLSchema schema) {
GraphQL gql = GraphQL.newGraphQL(schema).build();
ExecutionResult result = gql.execute(IntrospectionQuery.INTROSPECTION_QUERY);
Assert.assertTrue(result.getErrors().size() == 0, "The schema has errors during Introspection");
return result.getData();
}
Aggregations