Skip to content
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

FR - Middleware to log queries to a another repository #88

Closed
rturk opened this issue Jan 29, 2016 · 4 comments
Closed

FR - Middleware to log queries to a another repository #88

rturk opened this issue Jan 29, 2016 · 4 comments

Comments

@rturk
Copy link

rturk commented Jan 29, 2016

Feature request: Log queries to a database

  1. Query text
  2. Execution time
  3. Date
  4. Request source (IP, Auth code, etc)
  5. Info about required nodes
  6. Filter defines what queries will be logged or not
@tothandras
Copy link
Contributor

You can implement this with a query resolve hook.

@rturk
Copy link
Author

rturk commented Jan 31, 2016

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?

@tothandras
Copy link
Contributor

@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 });

@rturk
Copy link
Author

rturk commented Feb 1, 2016

@tothandras tks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants