You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The problem happens when using list-level cacheHint with findOne queries with nested findMany queries. Cache hint does not apply correctly due to missing cache hint application on findOne query.
But if the same query is executed as a nested query for a single user, say, a user's posts, the cache headers are set to "no-cache", even if the cacheHint for the User list is set to { maxAge: 60, scope: "PUBLIC" } as well.
query {
user(where: { id: "22fc8814-3845-4287-bbbe-34cb65ecebb6" }) {
nameposts(where: { category: { equals: "Category_1" } }) {
titlebody
}
}
}
# Returns no-cache, even though both lists are set to have# cache maxAge=60 and scope=PUBLIC
That happens because Apollo caching calculation strategy is to respect the most restrictive cache policy from all fields of a query, and the findOne resolver seems not to be setting the correct cache hinting.
After fiddling with the code, I managed to identify two places that need to be slightly modified:
1 - At core/queries/resolvers.ts, around line 105, right before the result for the findOne resolver is returned, it should check if a cache hint was defined for the list and let apollo know of the cache settings. Just as is done on the findMany and count resolvers.
2 - At core/queries/index.ts, around line 16, where the resolver is defined and the resolver info needs to be forwarded to the findOne resolver so that it may get cache info.
The problem happens when using list-level cacheHint with
findOne
queries with nestedfindMany
queries. Cache hint does not apply correctly due to missing cache hint application onfindOne
query.Say we have the following example:
The cache hint works perfectly when running a query for a list of posts:
But if the same query is executed as a nested query for a single user, say, a user's posts, the cache headers are set to "no-cache", even if the cacheHint for the User list is set to
{ maxAge: 60, scope: "PUBLIC" }
as well.That happens because Apollo caching calculation strategy is to respect the most restrictive cache policy from all fields of a query, and the
findOne
resolver seems not to be setting the correct cache hinting.After fiddling with the code, I managed to identify two places that need to be slightly modified:
1 - At
core/queries/resolvers.ts
, around line 105, right before the result for thefindOne
resolver is returned, it should check if a cache hint was defined for the list and let apollo know of the cache settings. Just as is done on the findMany and count resolvers.keystone/packages/core/src/lib/core/queries/resolvers.ts
Lines 78 to 106 in eddc0ff
Should become:
Just like the resolver for findMany:
keystone/packages/core/src/lib/core/queries/resolvers.ts
Lines 108 to 153 in eddc0ff
2 - At
core/queries/index.ts
, around line 16, where the resolver is defined and the resolver info needs to be forwarded to thefindOne
resolver so that it may get cache info.keystone/packages/core/src/lib/core/queries/index.ts
Lines 8 to 19 in eddc0ff
Should become:
Just like the resolver for
findMany
:keystone/packages/core/src/lib/core/queries/index.ts
Lines 21 to 27 in eddc0ff
In the coming days I'll take a deeper look and would be totally willing to submit a PR if that helps.
Thanks!
The text was updated successfully, but these errors were encountered: