graphql-log
Add logging to your GraphQL resolvers so you know what's going on in your app.
Everytime a resolver is executed it logs the full path to the resolver. The output in your terminal (when using the popular debug
module for logging) will be something like this:
server:resolvers Message.channel +0msserver:resolvers User.avatar +0msserver:resolvers User.username +0msserver:resolvers User.avatar +4msserver:resolvers User.coverPhoto +0msserver:resolvers User.username +0ms
Note: The "server:resolvers" and "+xms" parts are added by
debug
, this module only logs the path on execution.
Usage
This is the simplest example:
// Require the moduleconst createGraphQLLogger = ; // Create a loggerconst logExecutions = ; // Wrap your resolvers;
Note that your resolvers need to be a plain object of resolvers. (like you'd create for graphql-tools
makeExecutableSchema
function)
Options
graphql-log
has some options:
logger
(function, default:console.log
): Use a custom logger likedebug
,pino
or any other one.prefix
(string): Prefix all logs with a certain string
const logExecutions = ;
Usage with custom loggers
Let's say you want to use the popular debug
module for logging. Doing so would be as easy as passing it into the logger
option:
const debug = 'server:resolvers'; const logExecutions = ;
Usage only in development
Logging every execution of every resolver will have a performance impact on your app, so we recommend only enabling this module in development. A common way to do so (depending on your setup) would be something like this:
const createGraphQLLogger = ; const resolvers = /*...*/; if processenvNODE_ENV === 'development' const logExecutions = ; ;
Roadmap
The main thing I want to change is that instead of wrapping the resolvers this module would wrap a finished schema instead. This would make it compatible not only with folks who keep their resolvers separate, but with everybody.
That'd probably look something like this:
// I'd love to be able to pass a schema;
Good first PR?
License
Licensed under the MIT License, Copyright ©️ 2017 Maximilian Stoiber. See LICENSE.md for more information.