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

behavior of hooks #554

Open
YuriFontella opened this issue Aug 13, 2021 · 3 comments
Open

behavior of hooks #554

YuriFontella opened this issue Aug 13, 2021 · 3 comments

Comments

@YuriFontella
Copy link

Hello,
I would like to know if it is normal behavior for a hook to be triggered with graphql queries?
Considering, that it has its own hooks function.

hook that is loaded:

app.addHook('preHandler', async () => {
  ...
})

graphql specific hook in mercurius:

app.graphql.addHook('preParsing', async () => {
  ...
})

Demo project:
https://github.com/YuriFontella/graphql-add-hook-test

The hook loaded as a plugin, is called for every graphql query executed.

@smolinari
Copy link
Contributor

@YuriFontella - Every request to a Mercurius drivin graphql server triggers a hook.

https://mercurius.dev/#/docs/lifecycle

Scott

@YuriFontella
Copy link
Author

@YuriFontella - Every request to a Mercurius drivin graphql server triggers a hook.

https://mercurius.dev/#/docs/lifecycle

Scott

I looked at it, and it was weird. Because in the lifecycle there is no preHandler hook.
And mercurius has its own function to add hooks "app.graphql.addHook"

app.addHook('preHandler', async () => {
  console.log('Im executed in graphql queries')
})

It didn't make sense for me to call this hook in graphql queries

@smolinari
Copy link
Contributor

Yeah, so app.addhook would be for a fastify hook, right? And the same goes, they are for all requests.

https://www.fastify.io/docs/latest/Hooks/

Scott

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