overblog / GraphQLBundle

This bundle provides tools to build a complete GraphQL API server in your Symfony App.
MIT License
783 stars 221 forks source link

Question: Recommended way to clear dataloader cache between two queries execution #1127

Open benjamindulau opened 1 year ago

benjamindulau commented 1 year ago
Q A
Bug report? no
Feature request? no
BC Break report? no
RFC? no
Version/Branch 0.15.2

Sometime we need to execute a query directly through the executor, make some mutations, and then execute the exact same query again so we get the updated result all in the same code execution. In this case the dataloader would not fetch data again for the second query but would get it directly from its internal cache. Normal behavior.

Instead of manually clearing the cache each time developers have to implement this type of use case, I'd like to automatically clear the dataloader cache between each query execution.

My first thought would be to create an event listener on the pre_executor event which would clear the cache on all the dataloader services.

Is there a better and recommended way to achieve this? Is there a way to apply this only when the query was not initiated through HTTP?

Thanks!