apollo graphql响应数据中未显示"Extensions"字段



这里是一个可复制的示例。运行app.js并在http://localhost:4000/graphql

您可以运行以下查询:

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

问题:

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

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

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

"data":{....}

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

以下是apollo引擎的启动方式:

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"
}

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

文档

相关内容

最新更新