-
Hi folks I'm completely new to graphql and I have a problem with cache exchanges now I have a Query to fetch my posts and one for creating post(this two are in the same page) query for fetching posts:
typeof variables :
PostsDocument
now in my "cacheExchange < updates < Mutation < createPost":
now as you can see variables from "cache.inspectFields" are missing "shortText" properye from Posts query I hope I defined my issue currectly |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 2 replies
-
Please format the code correctly. |
Beta Was this translation helpful? Give feedback.
-
I think you’re confusing However variables are the dollar-prefixed signature that only the query itself accepts. Luckily, queries don’t care about this. Basically what you’re trying to do in your updater is All that Graphcache cares about is the post’s ID and type name to match up items in the list as described here: https://formidable.com/open-source/urql/docs/graphcache/normalized-caching/ So your updater can also just use a smaller query that only updates:
And as long as the mutation contains this field the query will be able to update without a network request:
That being said, it should be fine to just update the above with just the ID if you’re fine with an additional network request. We’re trying to also make mutations like these simpler using the populate exchange in the future. |
Beta Was this translation helpful? Give feedback.
I think you’re confusing
variables
witharguments
here. A field can have arguments which is a field with a call signature basically:field(argument: true)
.However variables are the dollar-prefixed signature that only the query itself accepts.
Luckily, queries don’t care about this. Basically what you’re trying to do in your updater is
cachedData?.posts.unshift(realResult);
. So you don’t even need to use the same query.All that Graphcache cares about is the post’s ID and type name to match up items in the list as described here: https://formidable.com/open-source/urql/docs/graphcache/normalized-caching/
So your updater can also just use a smaller query that only updates: