mercurius-js / mercurius

Implement GraphQL servers and gateways with Fastify
https://mercurius.dev/
MIT License
2.34k stars 234 forks source link

feat: Allow preExecution hook to modify variables #921

Closed curtiswilkinson closed 1 year ago

curtiswilkinson commented 1 year ago

I saw discussions about this on https://github.com/mercurius-js/mercurius/issues/876, which mainly talked about accessing variables, but there is a comment that also mentions updating them.

I require this use-case, where hooks can modify the incoming variables based on logic or contacting external systems. See the test included with the PR for an example.

This could have be achieved by putting the logic in a plugin earlier in the chain than Mercurius, but preventing double query parsing would be difficult, as the hooks need to be query-aware.

I'll admit I don't have a complete understanding of this codebase so forgive me if there are any things I've missed here, it's mainly to frame the requirement I have and start a discussion.

If there is any modifications you'd like here, let me know and I'd be happy to contribute; I can update any documentation as necessary, but wanted to wait until this feature was discussed.

curtiswilkinson commented 1 year ago

Apologies @mcollina, I didn't expect the "re-review" button to drop the reviewers you requested, but apparently it does for some reason