Graphcache: querying from cache immediately after creating an entity #3397
-
In short, I'm working on a user registration flow and I'd like to avoid the network call that fetches the user I just created. I saw there was a similar discussion here, though I'm not using schema awareness and after updating my cache config accordingly I'm still seeing the network call when querying for the user that was just created. I believe my schema and urql config are setup correctly to enable this:
updates: {
Mutation: {
createUser(result, args, cache) {
const user = result.createUser.user;
cache.link('Query', 'getUser', { id: args.id }, user);
},
},
}, Yet I'm still seeing a network call go out for the I'm not sure if the following is needed (it didn't seem to make a difference), but I also tried adding a local resolver so urql would know where to look for cached entities: resolvers: {
Query: {
getUser: (_, args, cache) => {
return { __typename: 'User', id: args.id };
},
},
}, Do I have this configured incorrectly? Or is there something else I'm missing? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 3 replies
-
Is it possible that The reasons behind me asking is that this relies heavily on As an alternative you could try using |
Beta Was this translation helpful? Give feedback.
Is it possible that
createUser
has less fields than whatgetUser
is asking for? Are both the__typename
andid
returned fromcreateUser
?The reasons behind me asking is that this relies heavily on
createUser
writing everything correctly forgetUser
to resolve it.As an alternative you could try using
updateQuery
ongetUser
and see if that does the trick, if it does there might be a discrepancy between the two.