You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm using defineBasicLoader in combination with apollo to pull data. Apollo is already handling cache for me so I'm happy to let return the cached values immediately and load from the API if it's not cached yet.
The problem is when I'm updating data and calling the reload function from the data loader. As apollo already has the data cached, it returns immediately.
It would be nice to have something like this:
exportconstuseMyDataLoader=defineBasicLoader(async(route,{ isReload })=>{constresult=awaitapollo.query({
query,// if this is a reload we want to forcefully load the data from the API as it's likely changedfetchPolicy: isReload ? 'network-only' : 'cache-first',});// do some stuff with the resultreturn ...;});
Apollo does have functionality that allows me to update the cache directly when updating data but this is tricky in my application due to the way it's set up (though this would probably be the best thing to do). I'm asking here as I feel like this could be a useful feature regardless for similar situations.
It feels overkill to switch to the colada loader for this (which I believe may solve the issue as it is much more powerful than the basic loader) as the basic loader works pretty much completely for my usecase.
If this seems like a reasonable idea I can explore making a PR for this, though I haven't looked at the source for the basic loader properly (yet). If not I can work around this (or maybe switch to colada).
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
I'm using defineBasicLoader in combination with apollo to pull data. Apollo is already handling cache for me so I'm happy to let return the cached values immediately and load from the API if it's not cached yet.
The problem is when I'm updating data and calling the reload function from the data loader. As apollo already has the data cached, it returns immediately.
It would be nice to have something like this:
Apollo does have functionality that allows me to update the cache directly when updating data but this is tricky in my application due to the way it's set up (though this would probably be the best thing to do). I'm asking here as I feel like this could be a useful feature regardless for similar situations.
It feels overkill to switch to the colada loader for this (which I believe may solve the issue as it is much more powerful than the basic loader) as the basic loader works pretty much completely for my usecase.
If this seems like a reasonable idea I can explore making a PR for this, though I haven't looked at the source for the basic loader properly (yet). If not I can work around this (or maybe switch to colada).
Thank you for the fantastic libraries!
Beta Was this translation helpful? Give feedback.
All reactions