问题
Here is a reproducible example. Run app.js
and navigate the playground at http://localhost:4000/graphql
You can run queries like:
query RecipeQuery{
recipe(title:"Recipe 2"){
description
}
}
Problem:
I need debugging information from the extensions
field in the response data. I'm talking about this extensions
field:
"data":{....},
"extensions": {
"tracing": {}
"cacheControl":{}
}
But in reality, I'm only getting the data field:
"data":{....}
I have already enabled tracing
and cacheControl
in the apollo server config but the extensions
field is still excluded in the response data. How can I get the extensions
data back?
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
"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"
}
回答1:
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;
}
});
doc
来源:https://stackoverflow.com/questions/53367351/extensions-field-not-shown-in-apollo-graphql-response-data