本文介绍了阿波罗graphql响应数据中未显示``扩展''字段的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
这是一个可复制的示例.运行 app.js
并在 http://localhost:4000/graphql
query RecipeQuery{
recipe(title:"Recipe 2"){
description
}
}
我需要响应数据中 extensions
字段中的调试信息.我说的是这个扩展名
字段:
"data":{....},
"extensions": {
"tracing": {}
"cacheControl":{}
}
But in reality, I'm only getting the data field:
"data":{....}
我已经在apollo服务器配置中启用了 tracing
和 cacheControl
,但是响应数据中仍然排除了 extensions
字段.如何获取扩展名
数据?
Here's how the apollo engine starts:
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
格式化来自阿波罗的响应.
You could format the response from apollo with formatResponse
.
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;
}
});
这篇关于阿波罗graphql响应数据中未显示``扩展''字段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!