本文整理了Java中graphql.GraphQL
类的一些代码示例,展示了GraphQL
类的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。GraphQL
类的具体详情如下:
包路径:graphql.GraphQL
类名称:GraphQL
[英]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 graphql.schema.GraphQLSchemaand the graphql.execution.ExecutionStrategyBuilding this object is very cheap and can be done on each execution if necessary. Building the schema is often not as cheap, especially if its parsed from graphql IDL schema format via graphql.schema.idl.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.
代码示例来源:origin: graphql-java/graphql-java
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();
}
}
代码示例来源:origin: graphql-java/graphql-java
private void equivalentSerialAndAsyncQueryExecution() throws Exception {
//::FigureC
ExecutionResult executionResult = graphQL.execute(executionInput);
// the above is equivalent to the following code (in long hand)
CompletableFuture<ExecutionResult> promise = graphQL.executeAsync(executionInput);
ExecutionResult executionResult2 = promise.join();
//::/FigureC
}
代码示例来源:origin: graphql-java/graphql-java
public GraphQL build() {
assertNotNull(graphQLSchema, "graphQLSchema must be non null");
assertNotNull(queryExecutionStrategy, "queryStrategy must be non null");
assertNotNull(idProvider, "idProvider must be non null");
return new GraphQL(graphQLSchema, queryExecutionStrategy, mutationExecutionStrategy, subscriptionExecutionStrategy, idProvider, instrumentation, preparsedDocumentProvider);
}
}
代码示例来源:origin: graphql-java/graphql-java
private CompletableFuture<ExecutionResult> parseValidateAndExecute(ExecutionInput executionInput, GraphQLSchema graphQLSchema, InstrumentationState instrumentationState) {
AtomicReference<ExecutionInput> executionInputRef = new AtomicReference<>(executionInput);
PreparsedDocumentEntry preparsedDoc = preparsedDocumentProvider.get(executionInput.getQuery(),
transformedQuery -> {
// if they change the original query in the pre-parser, then we want to see it downstream from then on
executionInputRef.set(executionInput.transform(bldr -> bldr.query(transformedQuery)));
return parseAndValidate(executionInputRef, graphQLSchema, instrumentationState);
});
if (preparsedDoc.hasErrors()) {
return CompletableFuture.completedFuture(new ExecutionResultImpl(preparsedDoc.getErrors()));
}
return execute(executionInputRef.get(), preparsedDoc.getDocument(), graphQLSchema, instrumentationState);
}
代码示例来源:origin: bpatters/schemagen-graphql
@SuppressWarnings("rawtypes")
private UserDTO getUserNode(String id) throws IOException {
ExecutionResult result = new GraphQL(schema).execute(String.format("{ node(id:\"%s\") {...on User {id, name, email} } }", id));
assertEquals(0, result.getErrors().size());
return objectMapper.readValue(objectMapper.writeValueAsString(((Map) result.getData()).get("node")), UserDTO.class);
}
代码示例来源:origin: graphql-java/graphql-java
/**
* Executes the graphql query using the provided input object builder
*
* @param executionInputBuilder {@link ExecutionInput.Builder}
*
* @return an {@link ExecutionResult} which can include errors
*/
public ExecutionResult execute(ExecutionInput.Builder executionInputBuilder) {
return execute(executionInputBuilder.build());
}
代码示例来源:origin: graphql-java/graphql-java
private GraphQL buildSchema() {
return GraphQL.newGraphQL(schema)
.build();
}
代码示例来源:origin: graphql-java/graphql-java
/**
* Executes the graphql query using the provided input object builder
* <p>
* This will return a promise (aka {@link CompletableFuture}) to provide a {@link ExecutionResult}
* which is the result of executing the provided query.
*
* @param executionInputBuilder {@link ExecutionInput.Builder}
*
* @return a promise to an {@link ExecutionResult} which can include errors
*/
public CompletableFuture<ExecutionResult> executeAsync(ExecutionInput.Builder executionInputBuilder) {
return executeAsync(executionInputBuilder.build());
}
代码示例来源:origin: bpatters/schemagen-graphql
@SuppressWarnings("rawtypes")
private GameDTO getGameNode(String id) throws IOException {
ExecutionResult result = new GraphQL(schema).execute(String.format("{ node(id:\"%s\") {...on Game {id, name} } }", id));
assertEquals(0, result.getErrors().size());
return objectMapper.readValue(objectMapper.writeValueAsString(((Map) result.getData()).get("node")), GameDTO.class);
}
代码示例来源:origin: opentripplanner/OpenTripPlanner
public Response getGraphQLResponse(String query, Map<String, Object> variables, String operationName) {
ExecutionResult executionResult = graphQL.execute(query, operationName, null, variables);
Response.ResponseBuilder res = Response.status(Response.Status.OK);
HashMap<String, Object> content = new HashMap<>();
if (!executionResult.getErrors().isEmpty()) {
res = Response.status(Response.Status.INTERNAL_SERVER_ERROR);
content.put("errors", executionResult.getErrors());
}
if (executionResult.getData() != null) {
content.put("data", executionResult.getData());
}
return res.entity(content).build();
}
代码示例来源:origin: graphql-java/graphql-java
private GraphQL buildSchema() {
return GraphQL.newGraphQL(schema)
.build();
}
代码示例来源:origin: graphql-java/graphql-java
/**
* Executes the graphql query using the provided input object
*
* @param executionInput {@link ExecutionInput}
*
* @return an {@link ExecutionResult} which can include errors
*/
public ExecutionResult execute(ExecutionInput executionInput) {
try {
return executeAsync(executionInput).join();
} catch (CompletionException e) {
if (e.getCause() instanceof RuntimeException) {
throw (RuntimeException) e.getCause();
} else {
throw e;
}
}
}
代码示例来源:origin: google/rejoiner
new DataLoaderDispatcherInstrumentation(dataLoaderRegistry),
new TracingInstrumentation()));
GraphQL graphql = GraphQL.newGraphQL(schema).instrumentation(instrumentation).build();
.context(dataLoaderRegistry)
.build();
ExecutionResult executionResult = graphql.execute(executionInput);
resp.setContentType("application/json");
resp.setStatus(HttpServletResponse.SC_OK);
代码示例来源:origin: bpatters/schemagen-graphql
private DeleteUserPayload deleteUser(String id, String clientMutationId) throws IOException {
ExecutionResult result = new GraphQL(schema).execute(String
.format("mutation M { Mutations { deleteUser(input: { id:\"%s\", clientMutationId:\"%s\"}) {clientMutationId} } }", id, clientMutationId));
assertEquals(0, result.getErrors().size());
DeleteUserPayload payload = objectMapper.readValue(objectMapper.writeValueAsString(getMutationResults(result, "deleteUser")), DeleteUserPayload.class);
assertEquals(clientMutationId, payload.getClientMutationId());
return payload;
}
代码示例来源:origin: graphql-java/graphql-java
/**
* Executes the graphql query using calling the builder function and giving it a new builder.
* <p>
* This allows a lambda style like :
* <pre>
* {@code
* ExecutionResult result = graphql.execute(input -> input.query("{hello}").root(startingObj).context(contextObj));
* }
* </pre>
*
* @param builderFunction a function that is given a {@link ExecutionInput.Builder}
*
* @return an {@link ExecutionResult} which can include errors
*/
public ExecutionResult execute(UnaryOperator<ExecutionInput.Builder> builderFunction) {
return execute(builderFunction.apply(ExecutionInput.newExecutionInput()).build());
}
代码示例来源:origin: graphql-java/graphql-java
private GraphQL buildSchema() {
return GraphQL.newGraphQL(schema)
.build();
}
代码示例来源:origin: graphql-java/graphql-java
/**
* Executes the graphql query using the provided input object builder
* <p>
* This will return a promise (aka {@link CompletableFuture}) to provide a {@link ExecutionResult}
* which is the result of executing the provided query.
* <p>
* This allows a lambda style like :
* <pre>
* {@code
* ExecutionResult result = graphql.execute(input -> input.query("{hello}").root(startingObj).context(contextObj));
* }
* </pre>
*
* @param builderFunction a function that is given a {@link ExecutionInput.Builder}
*
* @return a promise to an {@link ExecutionResult} which can include errors
*/
public CompletableFuture<ExecutionResult> executeAsync(UnaryOperator<ExecutionInput.Builder> builderFunction) {
return executeAsync(builderFunction.apply(ExecutionInput.newExecutionInput()).build());
}
代码示例来源:origin: opentripplanner/OpenTripPlanner
serviceCodes = graph.serviceCodes;
this.graph = graph;
graphQL = new GraphQL(
new IndexGraphQLSchema(this).indexSchema,
new ExecutorServiceExecutionStrategy(Executors.newCachedThreadPool(
代码示例来源:origin: google/rejoiner
new DataLoaderDispatcherInstrumentation(dataLoaderRegistry),
new TracingInstrumentation()));
GraphQL graphql = GraphQL.newGraphQL(schema).instrumentation(instrumentation).build();
.context(dataLoaderRegistry)
.build();
ExecutionResult executionResult = graphql.execute(executionInput);
resp.setContentType("application/json");
resp.setStatus(HttpServletResponse.SC_OK);
代码示例来源:origin: bpatters/schemagen-graphql
private DeleteGamePayload deleteGame(String id, String clientMutationId) throws IOException {
ExecutionResult result = new GraphQL(schema).execute(
String.format("mutation M { Mutations {deleteGame(input:{ id:\"%s\", clientMutationId:\"%s\"}) {clientMutationId} } }", id, clientMutationId));
assertEquals(0, result.getErrors().size());
DeleteGamePayload payload = objectMapper.readValue(objectMapper.writeValueAsString(getMutationResults(result, "deleteGame")), DeleteGamePayload.class);
assertEquals(clientMutationId, payload.getClientMutationId());
return payload;
}
内容来源于网络,如有侵权,请联系作者删除!