【问题标题】:`Extensions` field not shown in apollo graphql response data`Extensions` 字段未显示在 apollo graphql 响应数据中
【发布时间】:2019-04-21 09:11:38
【问题描述】:

这是reproducible example。运行app.js 并在http://localhost:4000/graphql 的操场上导航

您可以运行如下查询:

query RecipeQuery{
  recipe(title:"Recipe 2"){
    description
  }
}

问题:

我需要来自响应数据中extensions 字段的调试信息。我说的是extensions这个字段:

  "data":{....},
  "extensions": {
    "tracing": {}
    "cacheControl":{}
  }

但实际上,我只得到数据字段:

  "data":{....}

我已经在阿波罗服务器配置中启用了tracingcacheControl,但是响应数据中仍然排除了extensions 字段。如何取回extensions 数据?

以下是阿波罗引擎的启动方式:

const expressApp = express();

const server = new ApolloServer({
    schema,
    tracing: true,
    cacheControl: true,
    engine: false, // we will provide our own ApolloEngine
});

server.applyMiddleware({ app: expressApp });

const engine = new ApolloEngine({
    apiKey: "YOUR_ID",

});

engine.listen(
    {
        port,
        expressApp,
        graphqlPaths: [graphqlEndpointPath],
    },
    () => console.log(`Server with Apollo Engine is running on http://localhost:${port}`),
);

依赖关系

  "dependencies": {
    "apollo-cache-control": "^0.1.1",
    "apollo-engine": "^1.1.2",
    "apollo-server-express": "^2.2.2",
    "graphql-depth-limit": "^1.1.0",
    "graphql-yoga": "^1.16.7",
    "type-graphql": "^0.15.0"
  }

【问题讨论】:

    标签: node.js express graphql apollo apollo-server


    【解决方案1】:

    您可以使用 formatResponse 格式化来自 apollo 的响应。

    const server = new ApolloServer({
      typeDefs,
      resolvers,
      formatResponse: response => {
        console.log(response); 
        /* 
        ** { data } with informations such as queryType,
        ** directives ...
        ** I guess there is also the extensions key 
        */
        return response;
      }
    });
    

    doc

    【讨论】:

    • 完成了,阿波罗已经重建了他们的整个文档,最近破坏了很多网址):
    猜你喜欢
    • 2019-03-10
    • 2018-09-19
    • 2020-01-18
    • 2020-04-20
    • 2020-10-06
    • 2020-05-05
    • 1970-01-01
    • 1970-01-01
    • 2013-11-15
    相关资源
    最近更新 更多