Skip to content
This repository has been archived by the owner on Apr 14, 2023. It is now read-only.

Where to instantiate data loaders? #330

Closed
mxstbr opened this issue Jan 8, 2018 · 3 comments
Closed

Where to instantiate data loaders? #330

mxstbr opened this issue Jan 8, 2018 · 3 comments
Labels

Comments

@mxstbr
Copy link
Contributor

mxstbr commented Jan 8, 2018

I'm using this package in combination with a bunch of DataLoaders. At the moment, I just do the following:

SubscriptionServer.create({
  onConnect: () => ({ loaders: createDataLoaders() })
})

I thought that would get me unique dataloaders per query, but it actually gets me unique dataloaders per update. (which makes sense in hindsight) The issue is that if the same record is updated twice while a user stays subscribed throughout, they'll get stale data the second time the record is updated because the DataLoader will just return the value from its cache.

Really, what I want for my dataloaders is for them to be created every time a record is changed to avoid stale reads. How do I do that? (it's not onConnect, but it's also not onOperation since that runs once per subscription, which is also not what I need)

@mxstbr mxstbr added the question label Jan 8, 2018
@NeoPhi
Copy link
Contributor

NeoPhi commented Jan 8, 2018

This is a design issue with graphql. Some possible workarounds are listed in: graphql/graphql-js#894

@mxstbr
Copy link
Contributor Author

mxstbr commented Jan 8, 2018

Ugh, god dammit. Alright, nothing to see here folks—thank you @NeoPhi!

@mxstbr mxstbr closed this as completed Jan 8, 2018
baconz pushed a commit to PhiloInc/subscriptions-transport-ws that referenced this issue Apr 24, 2018
Update Lambda README to include more examples
@ash0080
Copy link

ash0080 commented Jan 5, 2020

any update?

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

3 participants