Open andreialecu opened 4 years ago
Until merge of https://github.com/graphql/graphql-js/pull/2485 seems like the only solution is to disable caching on all data loaders via { cache: false }
check https://the-guild.dev/graphql/envelop/v3/guides/resolving-subscription-data-loader-caching-issues , it resolves the issue
It appears that when GQL Subscriptions are used, the data returned by dataloaders will remain stale for the duration of the subscription.
I believe this happens because the context is the same for the lifetime of the subscription, so once data gets initially cached, it keeps returning the same initial result for DataLoader-resolved fields.
Manually clearing the cache by injecting the Loader and calling
loader.clearAll()
prior to returning from the@Subscription()
method seems to work. This can be tricky to do depending on how many loaders are used and where they are defined, and is prone to bugs by forgetting to clear something.