-
Notifications
You must be signed in to change notification settings - Fork 234
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 hooks to Mercurius #385
Add hooks to Mercurius #385
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've done a quick pass, I need to get deeper but I think there are a few things to fix already.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good work! How do the hooks play with subscriptions?
Thanks! I have tested on a very basic level and seems to be playing okay. I'll write some thorough tests for subscriptions for both normal server and gateway mode to make sure it is all working as expected :) I also noticed that the CI checks are intermittently failing for some of the subscription tests. At first glance it seems to be an environmental issue (other checks for the same node version pass fine) - did you have any thoughts on this? (Example run: https://github.com/mercurius-js/mercurius/pull/385/checks?check_run_id=1791951386) |
I've seen the flaky tests... can't do much about it right now. If you'd like to investigate and fix them, I'd be very grateful! |
For sure, very happy to take a look at the tests! :) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good work! I did another pass and I've left a few comments.
… clashes with sendRequest tests
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good work, one last nit.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you link the new docs pages from the README as well?
Sure thing!
After a bit of experimentation, I think we need to add a few more hook events within My only concern with this approach is the meaning of context when applied to the hooks. Because it is not strictly associated with a request over the wire, one could argue that we should have subscription specific hooks for this situation instead. I wondered what your thoughts were on this? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm
It's better to have a subscription specific hook, ideally in a follow up pull request. This is good to ship right now, so I'm shipping it as a few people are waiting on this! |
Yep, makes sense - happy to do a follow up PR for this as you suggested! Thanks for shipping this afternoon! :) |
By the time the `preValidation` hook triggers, the query string has been parsed into a GraphQL Document AST. | ||
|
||
```js | ||
fastify.addHook('preValidation', async (schema, document, context) => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should this be fastify.graphql.addHook
? only the first example in this document has that, not the others
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You're correct, yep - I'll submit a PR to fix this over lunch! Unless you want to! :)
Closes: #380