-
Notifications
You must be signed in to change notification settings - Fork 2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Idiomatic logging of requests and responses #216
Comments
@0x6e6562 IIRC the log function gets called a bunch of times with different keys. The one you're interested in is the |
@helfer Thanks very much for the heads up - I think I'll go with a middleware to log this out. |
This has been working well for me: const server = new Apollo.ApolloServer({
schema: ...,
formatError: error => {
logger.warn(error);
return error;
},
formatResponse: (response, query) => {
logger.info('GraphQL query and variables', {
query: query.queryString,
vars: query.variables,
});
return response;
},
}); |
apollo-server 2.1.1 and laterNote that starting with apollo-server 2.2.1 (or possibly earlier), the method I described in my previous comment no longer works, because the I still haven't found clear documentation on how to log queries. Other hacks have been suggested in this StackOverflow question I asked. |
To anyone frustrated, you can actually pull the requestContext from |
What's the idiomatic way to log gql requests and responses?
I've seen that you can supply a
logFunction
to thegraphql-server-express
instance, but this is fired once for each portion of the request with different keys to denote the query, the operation, variables and other data.Is the idea that the supplier of the callback should accumulate these keys so that it in turn can generate a single log event for the application?
What I'd like to configure is a logger that pretty prints each client request as a single log entry.
The text was updated successfully, but these errors were encountered: