Coder Social home page Coder Social logo

Comments (4)

tothandras avatar tothandras commented on June 20, 2024

You can implement this with a query resolve hook.

from graffiti-mongoose.

rturk avatar rturk commented on June 20, 2024

Thanks. Including @sibeliusseraphini.
Maybe this should be implemented in the Graphql logic. Ideally any middleware logic ,such as logging, needs to be agnostic from the underling data source.
Comments?

from graffiti-mongoose.

tothandras avatar tothandras commented on June 20, 2024

@rturk Trust me, it's not so hard to implement these in resolve hooks:

const hooks = {
  plural: {
    pre: (next, root, args, context) => {
      context.rootValue.startTime = Date.now();
    },
    post: (next, value, args, asd, context) => {
      // 1) Query text
      const { query, variables } = context.rootValue.body // I need to add the body to rootValue in `graffiti`, you can open a PR too
      // 2) Execution time
      const executionTime = Date.now() - context.rootValue.startTime;
      // 3) Date
      const date = Date.now()
      // 4) Request source (IP, Auth code, etc)
      const { headers } = context.rootValue
      // 5) Info about required nodes
      const { fieldName, fieldASTs } = context
      // 6) Filter defines what queries will be logged or not
      if (/* custom filter */.filter(context)) {
        // save
      }
    }
  }
};
const schema = getSchema([/* models */], { hooks });

from graffiti-mongoose.

rturk avatar rturk commented on June 20, 2024

@tothandras tks!

from graffiti-mongoose.

Related Issues (20)

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.