I’ve got an application with several different kinds of queries on eventConnections
. The simplest looks like this:
export const GET_DRAFT_REAL_EVENT_BATCH = graphql(`
query GetDraftRealEventBatch($companyId: Int!, $offset: Int, $limit: Int) {
albumBatch: eventConnections(
where: {
creditedCompanyId: { _eq: $companyId }
event: {
publishedAt: { _is_null: true }
deletedAt: { _is_null: true }
}
}
order_by: { displaySortOrder: asc }
offset: $offset
limit: $limit
) {
...RealEventSearchResult
}
}
`);
I’ve set the type policy thus:
return new NextSSRApolloClient({
cache: new NextSSRInMemoryCache({
typePolicies: {
Query: {
fields: {
eventConnections: {
keyArgs: ["where", ["creditedCompanyId", ["_eq"]]],
merge(existing = [], incoming) {
return [...existing, ...incoming];
},
},
},
},
},
}),
This stores all the draft events in a single collection in the cache. However, I also want to be able to call this query on the field:
export const GET_HIDDEN_REAL_EVENT_BATCH = graphql(`
query GetHiddenRealEventBatch($companyId: Int!, $offset: Int, $limit: Int) {
albumBatch: eventConnections(
where: {
creditedCompanyId: { _eq: $companyId }
event: { publishedAt: { _is_null: false } }
displayStatus: { _eq: "hidden" }
}
order_by: { displaySortOrder: asc }
offset: $offset
limit: $limit
) {
...RealEventSearchResult
}
}
`);
If I leave the type policy in place, this will match the same cache element, meaning that the application will assume that all draft Events are also hidden events. What do I do?!
What I’d really like to do is cache the results by query name (GetDraftRealEventBatch
, GetHiddenRealEventBatch
etc). Is that possible?