Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug: Cache writes of incremental responses uses incorrect parent key (custom cache keys) #3380

Open
Tracked by #3093
calvincestari opened this issue May 14, 2024 · 0 comments
Assignees
Labels

Comments

@calvincestari
Copy link
Member

calvincestari commented May 14, 2024

When using custom cache keys the cache records written as a result of an incremental response do not use the correct parent entity cache key and instead default to the behaviour as if no custom cache key was provided.

Here is incremental cache data when not using a custom cache key

"_id" "key" "record"
4 "QUERY_ROOT" "{""allProducts"":[{""$reference"":""QUERY_ROOT.allProducts.0""},{""$reference"":""QUERY_ROOT.allProducts.1""},{""$reference"":""QUERY_ROOT.allProducts.2""}]}"
5 "QUERY_ROOT.allProducts.2" "{""variation"":{""$reference"":""QUERY_ROOT.allProducts.2.variation""},""dimensions"":{""$reference"":""QUERY_ROOT.allProducts.2.dimensions""},""sku"":""client"",""id"":""apollo-client"",""__typename"":""Product""}"
6 "QUERY_ROOT.allProducts.1" "{""variation"":{""$reference"":""QUERY_ROOT.allProducts.1.variation""},""dimensions"":{""$reference"":""QUERY_ROOT.allProducts.1.dimensions""},""sku"":""studio"",""id"":""apollo-studio"",""__typename"":""Product""}"
7 "QUERY_ROOT.allProducts.2.dimensions" "{""__typename"":""ProductDimension"",""size"":""1""}"
8 "QUERY_ROOT.allProducts.2.variation" "{""__typename"":""ProductVariation"",""id"":""OSS"",""name"":""client""}"
9 "QUERY_ROOT.allProducts.1.dimensions" "{""__typename"":""ProductDimension"",""size"":""1""}"
10 "QUERY_ROOT.allProducts.0.dimensions" "{""__typename"":""ProductDimension"",""size"":""1""}"
11 "QUERY_ROOT.allProducts.0" "{""variation"":{""$reference"":""QUERY_ROOT.allProducts.0.variation""},""dimensions"":{""$reference"":""QUERY_ROOT.allProducts.0.dimensions""},""sku"":""federation"",""id"":""apollo-federation"",""__typename"":""Product""}"
12 "QUERY_ROOT.allProducts.1.variation" "{""__typename"":""ProductVariation"",""id"":""platform"",""name"":""platform-name""}"
13 "QUERY_ROOT.allProducts.0.variation" "{""__typename"":""ProductVariation"",""id"":""OSS"",""name"":""platform""}"

And here is cache data when using a custom cache key during incremental responses. Note how the incremental responses end up using the list index ("QUERY_ROOT.allProducts.X") as the key for the record instead of the custom cache key derived key. This incorrectly breaks the cache record into two parts and makes the incremental cache records irretrievable because they're not linked by "QUERY_ROOT".

"_id" "key" "record"
1 "Product:apollo-client" "{""sku"":""client"",""__typename"":""Product"",""id"":""apollo-client""}"
2 "Product:apollo-federation" "{""id"":""apollo-federation"",""sku"":""federation"",""__typename"":""Product""}"
3 "Product:apollo-studio" "{""id"":""apollo-studio"",""sku"":""studio"",""__typename"":""Product""}"
4 "QUERY_ROOT" "{""allProducts"":[{""$reference"":""Product:apollo-federation""},{""$reference"":""Product:apollo-studio""},{""$reference"":""Product:apollo-client""}]}"
5 "QUERY_ROOT.allProducts.0.dimensions" "{""size"":""1"",""__typename"":""ProductDimension""}"
6 "QUERY_ROOT.allProducts.1" "{""variation"":{""$reference"":""ProductVariation:platform""},""dimensions"":{""$reference"":""QUERY_ROOT.allProducts.1.dimensions""}}"
7 "ProductVariation:platform" "{""id"":""platform"",""__typename"":""ProductVariation"",""name"":""platform-name""}"
8 "QUERY_ROOT.allProducts.2" "{""variation"":{""$reference"":""ProductVariation:OSS""},""dimensions"":{""$reference"":""QUERY_ROOT.allProducts.2.dimensions""}}"
9 "ProductVariation:OSS" "{""id"":""OSS"",""name"":""client"",""__typename"":""ProductVariation""}"
10 "QUERY_ROOT.allProducts.2.dimensions" "{""size"":""1"",""__typename"":""ProductDimension""}"
11 "QUERY_ROOT.allProducts.1.dimensions" "{""__typename"":""ProductDimension"",""size"":""1""}"
12 "QUERY_ROOT.allProducts.0" "{""variation"":{""$reference"":""ProductVariation:OSS""},""dimensions"":{""$reference"":""QUERY_ROOT.allProducts.0.dimensions""}}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant