Is it possible to manually update the cache with a *nested* object from a subscription update?
See original GitHub issueOn Alec’s recommendation, I previously setup a subscription that updates when new records are created, the result were then added manually to the cache. Example: https://github.com/AlecAivazis/houdini/issues/94#issuecomment-859989593. Like in this example the query and its results were flat (single level) and the manual prepend to the cache worked well.
I have since updated my schema with nested queries. Something like this:
const { data } = subscription(
graphql`
subscription NewRecipe($id: String!) {
queryNewRecipe(id: $id) {
id
versions(first: 1) {
title
id
}
sourceRecipe {
id
domain
}
}
}
`,
{
id: $session.user.id
}
);
$: {
cache.list('Active_Recipes').prepend(
{
id: { type: 'ID', keyRaw: 'id' },
versions: [
{
title: { type: 'String', keyRaw: 'title' },
id: { type: 'ID', keyRaw: 'id' },
}
],
sourceRecipe: {
id: { type: 'ID', keyRaw: 'id' },
domain: { type: 'String', keyraw: 'domain' }
}
},
$data.queryNewRecipe
);
}
Unfortunately, now the manual prepend to the cache is failing with TypeError: key is not iterable
. When I inspect cache.js it looks like the code doesn’t really handle nested schemas like this, as the keys and values are showing as undefined
inside the insertSubscribers
method.
Assuming I understand the limitation correctly, how would you now recommend I manually update the cache with the incoming data to given its structure?
The full error:
Uncaught (in promise) TypeError: key is not iterable
at Cache.evaluateKey (cache.js?t=1629053326512:713)
at Cache.insertSubscribers (cache.js?t=1629053326512:665)
at ListHandler.addToList (list.js:107)
at ListHandler.prepend (list.js:33)
at Object.$$self.$$.update (Subscriptions.svelte:26)
at update (index.mjs?v=8f41bf68:1046)
at flush (index.mjs?v=8f41bf68:1018)
Issue Analytics
- State:
- Created 2 years ago
- Comments:22
Top GitHub Comments
fantastic this is super helpful. I’m going to go ahead and close the ticket since your issue has been resolved. Thanks again!
I believe @pixelmund is using
141
so I dont think there is some kind of incompatibility. I’ll try to find the time to update the example app this week