Open roballsopp opened 4 years ago
My writeFragment
example works as expected with a cache redirect:
new ApolloClient({
...
cache: new InMemoryCache({
cacheRedirects: {
Query: {
getSurveyResponse: (_, args, { getCacheKey }) => getCacheKey({ __typename: 'SurveyResponse', id: args.id }),
},
},
}),
...
})
Still very curious why this doesn't seem to be the default behavior, and what I'm breaking by doing this.
Here's a mutation config I have that uses writeFragment in the updater:
Here's the component using the query I want to update:
And here's the query:
I know the
getSurveyTemplate
field is in the cache since I've visited this screen before and the data for that field is always the same (thesurveyTemplateId
variable is always the same). The only thing in theSurveyQueryContainerQuery
that changes each time is thesurveyResponseId
variable and therefore theSurveyResponse
. Given this setup, if I fire mycreateSurveyResponse
mutation before visiting the screen withSurveyQueryContainer
in it, I would expect the query component to render immediately because I have optimistically updated the cache with the correctSurveyQueryContainer_surveyResponse
fragment. I should have all the data needed to satisfySurveyQueryContainerQuery
present in the cache, so it shouldn't need to do a network fetch, yet it is still doing this. Am I doing something wrong here? Why can't it find the fragment I've written?This seems to work when I change my updater to:
But this is quite a bit more verbose, and seems like it shouldn't be necessary.