【发布时间】:2019-01-18 05:13:09
【问题描述】:
我正在使用 Spring 和 graphql-spring-boot-starter 构建一个 graphql 服务器。为了解决一个非常具体的问题,我想在 graphql HTTP 响应中添加一个 HTTP 标头。
我怎样才能做到这一点?
【问题讨论】:
标签: spring spring-boot graphql graphql-java
我正在使用 Spring 和 graphql-spring-boot-starter 构建一个 graphql 服务器。为了解决一个非常具体的问题,我想在 graphql HTTP 响应中添加一个 HTTP 标头。
我怎样才能做到这一点?
【问题讨论】:
标签: spring spring-boot graphql graphql-java
您可以在 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);
}
【讨论】: