mercurius-js / mercurius

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

Properly clone context for batched queries #858

Closed drakhart closed 2 years ago

drakhart commented 2 years ago

849 didn't finally fix #842.

For some reason I'm still investigating, Object.create(request) is not creating a truly independent clone of the request object, so the Mercurius context is still getting shared among all the batched queries.

This needs further investigation to find a proper fix, and once fixed hook spies (i.e. onResolution) should be added to double check the context values at different points of the request (since the resolver spy has proven to be incapable of catching the error).

drakhart commented 2 years ago

My fault: when I moved from cloning just the context to cloning the full request I didn't take into account that Object.create(request) would not clone the properties inside the context, just reference them (as they sit at a 2nd level inside the request).

I'm creating a new PR that will fix this.