Quick question about key equality and using it with gql
This might be obvious based on the docs:
As long as the query key is serializable using JSON.stringifyDoes this mean they are checked via the JSON serialised version for equality? So if I did: This would be perfectly acceptable and work as expected?
6 Replies
quickest-silverOP•3mo ago
I'm trying to make a generic wrapper like so:
but its late and I am tired
national-gold•3mo ago
I believe there used as keys for a Map
national-gold•3mo ago
MDN Web Docs
Map - JavaScript | MDN
The Map object holds key-value pairs and remembers the original insertion order of the keys.
Any value (both objects and primitive values) may be used as either a key or a value.
national-gold•3mo ago
I think if it was me, I do some work to extract a shorter key
(Probably means Id just dive into the Apollo codebase and reverse engineer that
national-gold•3mo ago
Actually uqrl is a better place to look; Apollo is normalised cache so they don't deal with keys the same way query does. Uqrl however does and they have some nice docs on how it works https://nearform.com/open-source/urql/docs/basics/document-caching/#operation-keys
optimistic-gold•3mo ago
we hash the key with the
queryKeyHashFn
, and that uses JSON.stringify
on the key itself. So if you have something inside the key that isn't json serializable, you have to provide your own queryKeyHashFn