【问题标题】:Add header to graphql response将标题添加到 graphql 响应
【发布时间】:2019-01-18 05:13:09
【问题描述】:

我正在使用 Spring 和 graphql-spring-boot-starter 构建一个 graphql 服务器。为了解决一个非常具体的问题,我想在 graphql HTTP 响应中添加一个 HTTP 标头。

我怎样才能做到这一点?

【问题讨论】:

    标签: spring spring-boot graphql graphql-java


    【解决方案1】:

    您可以在 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);
        }
    

    【讨论】:

      猜你喜欢
      • 2016-10-09
      • 1970-01-01
      • 2019-07-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-11-14
      • 2021-02-17
      相关资源
      最近更新 更多