[英]Add header to graphql response
I'm building a graphql server with Spring and graphql-spring-boot-starter. 我正在用Spring和graphql-spring-boot-starter构建一个graphql服务器。 To solve a very specific issue, I'd like to add a HTTP header to the graphql HTTP response. 为了解决一个非常具体的问题,我想在graphql HTTP响应中添加一个HTTP标头。
How can I achieve that? 我该如何实现?
You can add the add the headers in ResponseEntity. 您可以在ResponseEntity中添加添加标头。
public ResponseEntity<Object> callGraphQLService(@RequestBody String query) {
ExecutionInput input = ExecutionInput.newExecutionInput()
.query(query)
.build();
ExecutionResult result = graphService.getGraphQL().execute(input);
HttpHeaders headers = new HttpHeaders();
headers.add("Response-Code", "ABCD");
return new ResponseEntity<>(result, headers, HttpStatus.OK);
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.