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

Add logs for queries and mutations #732

Closed
paolochiodi opened this issue Feb 11, 2022 · 5 comments · Fixed by #734
Closed

Add logs for queries and mutations #732

paolochiodi opened this issue Feb 11, 2022 · 5 comments · Fixed by #734
Labels
enhancement New feature or request good first issue Good for newcomers

Comments

@paolochiodi
Copy link
Contributor

When a fastify + mercurius application receives a request with a query or a mutation, only the original fastify http request is logged.
Unfortunately this is not very useful as everything will be logged as a POST /graphql.

It would be great if mercurius could instead:

  • log the name of the mutation or query
  • extend the logger passed to the resolvers to include informations about the query or mutation
  • (optional) suppress default fastify logs

I guess what I'm saying is that it would be great to have some mercurius logging that works the way fastify logging works.

I understand this is feature request that will need some thinking / designing. Let me know if I can help.

@mcollina
Copy link
Collaborator

I think this should be implemented logging the query source right before

// Parse, with a little lru
as a new logging value at a debug level.

@mcollina mcollina added enhancement New feature or request good first issue Good for newcomers labels Feb 11, 2022
@paolochiodi
Copy link
Contributor Author

But what should be logged? I.e. I send multiple named queries like

query Query1 {
  currentUser {
    id
  }
}

query Query2 {
  categories {
    id
    name
  }
}

Will both queries be logged separately? Will it log the query name or the actual query?

@mcollina
Copy link
Collaborator

If you check in the actual code, it's just the source that is sent by the user before parsing it.

mcollina added a commit that referenced this issue Feb 11, 2022
…op-level resolver

Fixes #731
Fixes #732

Signed-off-by: Matteo Collina <hello@matteocollina.com>
@Eomm
Copy link
Contributor

Eomm commented Aug 21, 2022

I have created a plugin for this issue:
https://github.com/Eomm/mercurius-logging

@mcollina
Copy link
Collaborator

Could you add a link in the docs?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request good first issue Good for newcomers
Projects
None yet
3 participants