use of graphql.GraphQL 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.GraphQL 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.GraphQL 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();
}
use of graphql.GraphQL in project structr by structr.
the class GraphQLCommand method createResult.
private List<GraphObject> createResult(final SecurityContext securityContext, final GraphQLRequest request) throws IOException, FrameworkException {
final List<GraphObject> resultList = new LinkedList<>();
if (request.hasSchemaQuery()) {
// schema query is serialized from GraphQL execution result, doesn't need enclosing JSON object
for (final GraphQLQuery query : request.getQueries()) {
if (query.isSchemaQuery()) {
// use graphql-java schema response
final String originalQuery = request.getOriginalQuery();
final GraphQL graphQL = GraphQL.newGraphQL(SchemaService.getGraphQLSchema()).build();
final ExecutionResult result = graphQL.execute(originalQuery);
if (result != null) {
resultList.add(GraphObjectMap.fromMap(result.getData()));
}
}
}
} else {
for (final GraphQLQuery query : request.getQueries()) {
if (query.isSchemaQuery()) {
// use graphql-java schema response
final String originalQuery = request.getOriginalQuery();
final GraphQL graphQL = GraphQL.newGraphQL(SchemaService.getGraphQLSchema()).build();
final ExecutionResult result = graphQL.execute(originalQuery);
if (result != null) {
resultList.add(GraphObjectMap.fromMap(result.getData()));
}
} else {
for (final GraphObject object : query.getEntities(securityContext)) {
resultList.add(object);
}
}
}
}
return resultList;
}
use of graphql.GraphQL in project vertx-examples by vert-x3.
the class SubscriptionServer method createGraphQL.
private GraphQL createGraphQL() {
String schema = vertx.fileSystem().readFileBlocking("links.graphqls").toString();
SchemaParser schemaParser = new SchemaParser();
TypeDefinitionRegistry typeDefinitionRegistry = schemaParser.parse(schema);
RuntimeWiring runtimeWiring = newRuntimeWiring().type("Subscription", builder -> builder.dataFetcher("links", this::linksFetcher)).build();
SchemaGenerator schemaGenerator = new SchemaGenerator();
GraphQLSchema graphQLSchema = schemaGenerator.makeExecutableSchema(typeDefinitionRegistry, runtimeWiring);
return GraphQL.newGraphQL(graphQLSchema).build();
}
Aggregations