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
For one of our dataloaders in our NestJS GraphQL API, we have a composite key. Initially we had configured the dataloader to use this composite key as a tuple, but I noticed that this resulted in an issue with caching. The cache map has duplicated keys. When it eventually performs the SQL query, there are a lot of AND statements tied together with OR statements (one AND statement per composite key).
While this, performance wise does not cause issues, I still wanted to look into it. I tried using the cacheKeyFn function to transform the tuple into a string, so that the composite key would be saved in the cache as a string, and it would recognize the duplication itself.
This works as expected, but NOT with strict parameter enabled in tsconfig. I have to ignore the file from compilation errors to allow it to run. Below is the code of the creation of our DataLoader. The DataLoader still expects the composite key, as this is also what our repository layer expects. However, as you can see we use the cacheKeyFn to store the key as a string in the cache.
However, enabling the strict parameter, this error is logged:
src/modules/dataloader/dataloader.service.ts:91:17 - error TS2322: Type '(key: [string, string]) => string' is not assignable to type '(key: [string, string]) => [string, string]'.
Type 'string' is not assignable to type '[string, string]'.
91 cacheKeyFn: (key) => {
Am I implementing it incorrectly, or is something off in the typechecking?
The text was updated successfully, but these errors were encountered:
Hi,
For one of our dataloaders in our NestJS GraphQL API, we have a composite key. Initially we had configured the dataloader to use this composite key as a tuple, but I noticed that this resulted in an issue with caching. The cache map has duplicated keys. When it eventually performs the SQL query, there are a lot of AND statements tied together with OR statements (one AND statement per composite key).
While this, performance wise does not cause issues, I still wanted to look into it. I tried using the cacheKeyFn function to transform the tuple into a string, so that the composite key would be saved in the cache as a string, and it would recognize the duplication itself.
This works as expected, but NOT with strict parameter enabled in tsconfig. I have to ignore the file from compilation errors to allow it to run. Below is the code of the creation of our DataLoader. The DataLoader still expects the composite key, as this is also what our repository layer expects. However, as you can see we use the cacheKeyFn to store the key as a string in the cache.
When I log the codeDataLoader object, you can see the cache is correctly set.
However, enabling the strict parameter, this error is logged:
Am I implementing it incorrectly, or is something off in the typechecking?
The text was updated successfully, but these errors were encountered: