apollo-feature-requests
apollo-feature-requests copied to clipboard
Apollo 3 typePolicies - pass parent entity inside Context to generate keyArgs based on top of args + entity
Hey!
Apollo 3 introduces new mechanics called typePolicies, and it provides an api called keyArgs to generate id based on top of args & context, but sometimes it's needed to get "parent" entity too to generate id.
For example
query GetPodcastWithEpisodesQuery($id: String!) {
podcast(id: $id) {
id,
title,
episodes(order: { published: DESC }) {
edges {
node {
id,
title,
pid
}
},
pageInfo {
endCursor,
hasNextPage,
},
aggregate {
count,
}
}
}
}
Problem
I am interested to create calculate keyArgs for episodes based on top of ${podcast.id}-${args.order.published}, but I am not able to do it, because keyArgs didnt pass "parent type"
return new InMemoryCache({
typePolicies: {
podcast: {
fields: {
episodes: {
keyArgs: (args: any, context) => {
// I am not able to get parent entity
const podcast = { id: 5 };
return podcast.id + buildQueryCacheFromObject(args, ['order']);
},
}
}
}
},
});
Thanks