热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

graphql.GraphQL.executeAsync()方法的使用及代码示例

本文整理了Java中graphql.GraphQL.executeAsync()方法的一些代码示例,展示了GraphQL.executeAsync()

本文整理了Java中graphql.GraphQL.executeAsync()方法的一些代码示例,展示了GraphQL.executeAsync()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。GraphQL.executeAsync()方法的具体详情如下:
包路径:graphql.GraphQL
类名称:GraphQL
方法名:executeAsync

GraphQL.executeAsync介绍

[英]Executes the graphql query using the provided input object builder

This will return a promise (aka CompletableFuture) to provide a ExecutionResultwhich is the result of executing the provided query.
[中]使用提供的输入对象生成器执行graphql查询
这将返回一个承诺(也称为CompletableFuture),以提供ExecutionResultW,它是执行所提供查询的结果。

代码示例

代码示例来源:origin: graphql-java/graphql-java

/**
* Executes the graphql query using the provided input object builder
*


* 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 executeAsync(ExecutionInput.Builder executionInputBuilder) {
return executeAsync(executionInputBuilder.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: graphql-java/graphql-java

/**
* Executes the graphql query using the provided input object builder
*


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


* This allows a lambda style like :
*


* {@code
* ExecutionResult result = graphql.execute(input -> input.query("{hello}").root(startingObj).context(contextObj));
* }
*

*
* @param builderFunction a function that is given a {@link ExecutionInput.Builder}
*
* @return a promise to an {@link ExecutionResult} which can include errors
*/
public CompletableFuture executeAsync(UnaryOperator builderFunction) {
return executeAsync(builderFunction.apply(ExecutionInput.newExecutionInput()).build());
}

代码示例来源: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 promise = graphQL.executeAsync(executionInput);
ExecutionResult executionResult2 = promise.join();
//::/FigureC
}

代码示例来源:origin: graphql-java/graphql-java

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

代码示例来源:origin: com.graphql-java/graphql-java

/**
* Executes the graphql query using the provided input object builder
*


* 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 executeAsync(ExecutionInput.Builder executionInputBuilder) {
return executeAsync(executionInputBuilder.build());
}

代码示例来源:origin: com.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: com.graphql-java/graphql-java

/**
* Executes the graphql query using the provided input object builder
*


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


* This allows a lambda style like :
*


* {@code
* ExecutionResult result = graphql.execute(input -> input.query("{hello}").root(startingObj).context(contextObj));
* }
*

*
* @param builderFunction a function that is given a {@link ExecutionInput.Builder}
*
* @return a promise to an {@link ExecutionResult} which can include errors
*/
public CompletableFuture executeAsync(UnaryOperator builderFunction) {
return executeAsync(builderFunction.apply(ExecutionInput.newExecutionInput()).build());
}

代码示例来源:origin: leangen/graphql-spqr

@Override
public CompletableFuture executeAsync(ExecutionInput executionInput) {
return delegate.executeAsync(executionInput.transform(builder -> builder.context(new ContextWrapper(executionInput.getContext()))));
}

代码示例来源:origin: graphql-java/graphql-java-spring

@Test
public void endpointIsAvailable() {
String query = "{foo}";
ExecutionResultImpl executiOnResult= ExecutionResultImpl.newExecutionResult()
.data("bar")
.build();
CompletableFuture cf = CompletableFuture.completedFuture(executionResult);
ArgumentCaptor captor = ArgumentCaptor.forClass(ExecutionInput.class);
Mockito.when(graphql.executeAsync(captor.capture())).thenReturn(cf);
String body = this.restTemplate.getForObject("/graphql?query={query}", String.class, query);
assertThat(body, is("{\"data\":\"bar\"}"));
assertThat(captor.getValue().getQuery(), is(query));
}

代码示例来源:origin: graphql-java/graphql-java-spring

@Test
public void endpointIsAvailableWithDifferentUrl() {
String query = "{foo}";
ExecutionResultImpl executiOnResult= ExecutionResultImpl.newExecutionResult()
.data("bar")
.build();
CompletableFuture cf = CompletableFuture.completedFuture(executionResult);
ArgumentCaptor captor = ArgumentCaptor.forClass(ExecutionInput.class);
Mockito.when(graphql.executeAsync(captor.capture())).thenReturn(cf);
String body = this.restTemplate.getForObject("/otherUrl/?query={query}", String.class, query);
assertThat(body, is("{\"data\":\"bar\"}"));
assertThat(captor.getValue().getQuery(), is(query));
}

代码示例来源:origin: com.graphql-java/graphql-java-spring-webmvc

@Override
public CompletableFuture invoke(GraphQLInvocationData invocationData, WebRequest webRequest) {
ExecutionInput executiOnInput= ExecutionInput.newExecutionInput()
.query(invocationData.getQuery())
.operationName(invocationData.getOperationName())
.variables(invocationData.getVariables())
.build();
return graphQL.executeAsync(executionInput);
}

代码示例来源:origin: graphql-java/graphql-java-spring

@Override
public CompletableFuture invoke(GraphQLInvocationData invocationData, WebRequest webRequest) {
ExecutionInput executiOnInput= ExecutionInput.newExecutionInput()
.query(invocationData.getQuery())
.operationName(invocationData.getOperationName())
.variables(invocationData.getVariables())
.build();
return graphQL.executeAsync(executionInput);
}

代码示例来源:origin: graphql-java/graphql-java-spring

@Test
public void endpointIsAvailableWithDifferentUrl() {
String query = "{foo}";
ExecutionResultImpl executiOnResult= ExecutionResultImpl.newExecutionResult()
.data("bar")
.build();
CompletableFuture cf = CompletableFuture.completedFuture(executionResult);
ArgumentCaptor captor = ArgumentCaptor.forClass(ExecutionInput.class);
Mockito.when(graphql.executeAsync(captor.capture())).thenReturn(cf);
this.webClient.get().uri("/otherUrl?query={query}", query).exchange().expectStatus().isOk()
.expectBody(String.class).isEqualTo("{\"data\":\"bar\"}");
assertThat(captor.getValue().getQuery(), is(query));
}

代码示例来源:origin: graphql-java/graphql-java-spring

@Override
public Mono invoke(GraphQLInvocationData invocationData, ServerWebExchange serverWebExchange) {
ExecutionInput executiOnInput= ExecutionInput.newExecutionInput()
.query(invocationData.getQuery())
.operationName(invocationData.getOperationName())
.variables(invocationData.getVariables())
.build();
return Mono.fromCompletionStage(graphQL.executeAsync(executionInput));
}

代码示例来源:origin: graphql-java/graphql-java-spring

@Test
public void endpointIsAvailable() {
String query = "{foo}";
ExecutionResultImpl executiOnResult= ExecutionResultImpl.newExecutionResult()
.data("bar")
.build();
CompletableFuture cf = CompletableFuture.completedFuture(executionResult);
ArgumentCaptor captor = ArgumentCaptor.forClass(ExecutionInput.class);
Mockito.when(graphql.executeAsync(captor.capture())).thenReturn(cf);
this.webClient.get().uri("/graphql?query={query}", query).exchange().expectStatus().isOk()
.expectBody(String.class).isEqualTo("{\"data\":\"bar\"}");
assertThat(captor.getValue().getQuery(), is(query));
}

代码示例来源:origin: com.graphql-java/graphql-java-spring-webflux

@Override
public Mono invoke(GraphQLInvocationData invocationData, ServerWebExchange serverWebExchange) {
ExecutionInput executiOnInput= ExecutionInput.newExecutionInput()
.query(invocationData.getQuery())
.operationName(invocationData.getOperationName())
.variables(invocationData.getVariables())
.build();
return Mono.fromCompletionStage(graphQL.executeAsync(executionInput));
}

代码示例来源:origin: graphql-java/graphql-java-spring

@Test
public void testSimplePostRequest() throws Exception {
Map request = new LinkedHashMap<>();
String query = "{foo}";
request.put("query", query);
ExecutionResultImpl executiOnResult= ExecutionResultImpl.newExecutionResult()
.data("bar")
.build();
CompletableFuture cf = CompletableFuture.completedFuture(executionResult);
ArgumentCaptor captor = ArgumentCaptor.forClass(ExecutionInput.class);
Mockito.when(graphql.executeAsync(captor.capture())).thenReturn(cf);
client.post().uri("/graphql")
.body(Mono.just(request), Map.class)
.accept(MediaType.APPLICATION_JSON_UTF8)
.exchange()
.expectStatus().isOk()
.expectBody()
.jsonPath("data").isEqualTo("bar");
assertThat(captor.getAllValues().size(), is(1));
assertThat(captor.getValue().getQuery(), is(query));
}

代码示例来源:origin: graphql-java/graphql-java-spring

@Test
public void testSimpleGetRequest() throws Exception {
String query = "{foo}";
String queryString = URLEncoder.encode(query, "UTF-8");
ExecutionResultImpl executiOnResult= ExecutionResultImpl.newExecutionResult()
.data("bar")
.build();
CompletableFuture cf = CompletableFuture.completedFuture(executionResult);
ArgumentCaptor captor = ArgumentCaptor.forClass(ExecutionInput.class);
Mockito.when(graphql.executeAsync(captor.capture())).thenReturn(cf);
client.get().uri(uriBuilder -> uriBuilder.path("/graphql")
.queryParam("query", queryString)
.build())
.accept(MediaType.APPLICATION_JSON_UTF8)
.exchange()
.expectStatus().isOk()
.expectBody()
.jsonPath("data").isEqualTo("bar");
assertThat(captor.getAllValues().size(), is(1));
assertThat(captor.getValue().getQuery(), is(query));
}

代码示例来源:origin: graphql-java/graphql-java-spring

@Test
public void testDifferentUrl() throws Exception {
Map request = new LinkedHashMap<>();
String query = "{foo}";
request.put("query", query);
ExecutionResultImpl executiOnResult= ExecutionResultImpl.newExecutionResult()
.data("bar")
.build();
CompletableFuture cf = CompletableFuture.completedFuture(executionResult);
ArgumentCaptor captor = ArgumentCaptor.forClass(ExecutionInput.class);
Mockito.when(graphql.executeAsync(captor.capture())).thenReturn(cf);
MvcResult mvcResult = this.mockMvc.perform(post("/otherUrl")
.content(toJson(request))
.contentType(MediaType.APPLICATION_JSON_UTF8))
.andExpect(status().isOk())
.andExpect(request().asyncStarted())
.andReturn();
this.mockMvc.perform(asyncDispatch(mvcResult))
.andDo(print()).andExpect(status().isOk())
.andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8))
.andExpect(jsonPath("data", is("bar")))
.andReturn();
assertThat(captor.getAllValues().size(), is(1));
assertThat(captor.getValue().getQuery(), is(query));
}

推荐阅读
author-avatar
mobiledu2502912377
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有