Giter VIP home page Giter VIP logo

graphql-log's Introduction

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 +0ms
server:resolvers User.avatar +0ms
server:resolvers User.username +0ms
server:resolvers User.avatar +4ms
server:resolvers User.coverPhoto +0ms
server: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 module
const createGraphQLLogger = require('graphql-log');

// Create a logger
const logExecutions = createGraphQLLogger();

// Wrap your resolvers
logExecutions(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 like debug, pino or any other one.
  • prefix (string): Prefix all logs with a certain string
const logExecutions = createGraphQLLogger({
  // Prefix all logs with resolvers.
  prefix: 'resolvers.',
});

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 = require('debug')('server:resolvers');

const logExecutions = createGraphQLLogger({
  logger: debug,
});

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 = require('graphql-log');

const resolvers = {/*...*/};

if (process.env.NODE_ENV === 'development') {
  const logExecutions = createGraphQLLogger();
  logExecutions(resolvers);
}

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
logExecutions(schema);

Good first PR?

License

Licensed under the MIT License, Copyright Šī¸ 2017 Maximilian Stoiber. See LICENSE.md for more information.

graphql-log's People

Contributors

depfu[bot] avatar mxstbr avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

graphql-log's Issues

Why only log resolver path?

I am looking for a graphql logger that logs exactly what GraphQL query is passed, and with which arguments. Do you know if any library does this?

Passing a schema

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
logExecutions(schema);

take a look here https://github.com/apollographql/optics-agent-js

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤ī¸ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.