`Extensions` 字段未显示在 apollo graphql 响应数据中
`Extensions` field not shown in apollo graphql response data
这是一个reproducible example. Run app.js
and navigate the playground at http://localhost:4000/graphql
您可以 运行 查询,例如:
query RecipeQuery{
recipe(title:"Recipe 2"){
description
}
}
问题:
我需要来自响应数据中 extensions
字段的调试信息。我说的是这个 extensions
字段:
"data":{....},
"extensions": {
"tracing": {}
"cacheControl":{}
}
但实际上,我只得到了数据字段:
"data":{....}
我已经在 apollo 服务器配置中启用了 tracing
和 cacheControl
,但是响应数据中仍然排除了 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"
}
您可以将 apollo 的响应格式化为 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;
}
});
这是一个reproducible example. Run app.js
and navigate the playground at http://localhost:4000/graphql
您可以 运行 查询,例如:
query RecipeQuery{
recipe(title:"Recipe 2"){
description
}
}
问题:
我需要来自响应数据中 extensions
字段的调试信息。我说的是这个 extensions
字段:
"data":{....},
"extensions": {
"tracing": {}
"cacheControl":{}
}
但实际上,我只得到了数据字段:
"data":{....}
我已经在 apollo 服务器配置中启用了 tracing
和 cacheControl
,但是响应数据中仍然排除了 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"
}
您可以将 apollo 的响应格式化为 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;
}
});