Replies: 4 comments 10 replies
-
You can populate extra variables that aren't defined in the mutation itself. That's an escape hatch we made possible explicitly in case it's never possible to have all the data be present from the cache. It's an escape hatch because our cache assumes that all data that is needed to process a mutation is present in the variables, locally, or in the cache. That's because these are configurations matching the server's operations closely. So the idea is that if you ever have to pass extra information in it has an effect on what the UI has to pass, at which point the question arises why that information isn't in the cache. So be aware that you can also query the cache locally with stuff like Or read individual entries in the cache using But if you want a quick solution or this isn't possible, passing extra variables in that aren't in your mutation/query definition is always possible, since those are only filtered once the query/mutation is sent to your API. |
Beta Was this translation helpful? Give feedback.
-
Holy smokes, thanks for the fast response. Actually I tried to add some metadata to my variables, but couldn‘t access them because they were filtered out 🤔 Another use case is a drag‘n‘drop sitemap creator. Once I‘ve dropped the page to another place, I need the old record (before the mutation ran), to move the pages around in the array that I have in the cache (from old page index to the new one). I‘m going to try to add that to the variables again. I‘m using GraphQL codegen, but don‘t think that the generated code does filtering or things like that. |
Beta Was this translation helpful? Give feedback.
-
Yes, additional variables are filtered out: moveSitemapPageMutation({ input: { id, toPage }, foo: 'bar' })
const cacheExchange = createCacheExchange({
updates: {
Mutation: {
moveSitemapPage: (result, args, cache, info) => {
console.log(args)
}
}
}
}) results to {
input: {
id: 4,
toPage: 6
}
} instead of {
input: {
id: 4,
toPage: 6
},
foo: "bar"
} Apart from this, extending the variables object breaks the typescript definitions, but that's another issue 😂 |
Beta Was this translation helpful? Give feedback.
-
@kitten hey there! I was just wondering where this got to? I have run into the same problem where I need to pass additional variables into the mutation to update the local cache. I am unable to get the variable from the existing data or from the args/mutation response so I need to pass the variable in. The same as above seems true where any additional variables I add (after lying to typescript) are filtered out and don't exist in the I wonder if adding an additional option in addition to the
The cache variable could then be added to the |
Beta Was this translation helpful? Give feedback.
-
It would be great if we could add custom metadata to mutations. If I want to update the cache manually, I need all the variables for the current query I want to update:
An idea would be something like
moveSitemapPageMutation({ input: { id, toPage } }, { extras: { foo: "bar" } })
.extras
could be available in the info object:Beta Was this translation helpful? Give feedback.
All reactions