Let's say I have a schema like this (pseudocode)
query comments: [Comment]
query comment(id: Int!): Comment
And I'm fetching comments like this (pseudocode)
comments {
id
text
}
comment {
id
text
author {
id
name
}
}
In my components (pseudo):
const comment = useQuery(COMMENT_QUERY, {variables: {id: 1}})
My question is this. If I have loaded a feed of comments
, with the id
and text
fields, and then I subsequently load an individual comment, with the added author
fields, is there a way to get the useQuery
for the individual comment query to pick up the cached object with the corresponding id from the comments
query, if it is available? That is to say, the comments
query should have the text
field already for a comment with an id that has already been loaded. An additional network request should only be necessary to pick up the author
fields. It would be lovely if Apollo were clever enough to give me back this partial result immediately, and then the rest of the fields, author
in my example, when the data become available.
Is that possible with apollo packages/cache, or do I need to write my own useQuery
wrappers to read the cache directly?