Open pospi opened 1 year ago
@LeosPrograms let me know how you go with this one once all other work on Facets & whatever user requirements are outstanding is completed. Not terribly urgent an issue but should result in more immediate updates throughout the application, and resolve any situations where screens are not updated as expected. Hopefully the code in the linked examples is enough to follow the principles along, even though it's a Lit app rather than a Svelte one (and all the event binding conveniences of Svelte should make it much simpler to implement in this app).
Is this the cause of a problem I'm having: I updated something in an Offer, and when it went back to the Offer List page, it didn't show the updated data. If so, then this seems like a bug, not an enhancement to me, but discussion is welcome.
Curious: Is it that slow that we need to use any kind of caching?
[EDIT: If this is causing the list not to update, then it probably needs to go in the release milestone...]
Yep, that sounds like a culprit. If it's causing issues I will add it to the higher priority list.
We don't have to use the cache, really refetching from Holochain should be almost as quick. So if we are feeling pressured for time we could skip point 1 in the original issue and implement 3 without the fetchPolicy: 'cache-only'
as that will fetch it from Holochain instead.
@LeosPrograms please feel free to move this issue to the "later..." milestone after the quick fix for the Offers page is completed, and change the title to something like "Leverage GraphQL cache for related component updates" since that will be the only remaining work thereafter.
I notice there are also some dirty workarounds using polling in some components. For example in routes/+page.svelte
:
setInterval(function(){
fetchAgents()
}, 20000)
These measures should be removed and instead the update coordinated as needed via DOM events as above.
When I attempt to use subscribe, I get
Argument of type '{ fetchPolicy: string; }' is not assignable to parameter of type 'Subscriber<Result
I think that's fine for now? If you did not yet implement the update
callback in mutations to refresh the cache (doesn't seem so?) then it wouldn't have any effect anyway. So simply calling .subscribe()
without arguments is fine to trigger an update in a parent component; and the optimisation is only a minor one since the data will be re-pulled from Holochain's caches anyway.
Will leave this issue open, but set it to a low priority cleanup milestone.
In other work the easiest way of managing this has been via DOM events.
Unfortunately there is not a lot in the way of documentation on managing cache updates in GraphQL mutations, but once understood it is quite a powerful optimisation measure.
mutation
callback'supdate
option to specify custom handling to manage the query cachemutation()
call..subscribe({ fetchPolicy: 'cache-only' })
on any affectedquery
instances managed by the component.ReadableQuery
objects (generated fromquery()
) in child components so that a parent 'controller' component can manage linked updates across non-nested children (as per the linked example).fetchPolicy: 'cache-only'
is omitted, the data may will be re-queried from Holochain instead of the updated browser cache.