apollo-field-cache-resolver
v0.8.0
Published
A wrapper for your apollo graphql resolvers that uses your cache hints to cache the field
Readme
Apollo Cache Field Resolver (WIP)
The aim of this simple resolver wrapper is to enable caching on a field level basis, as apposed to the Apollo Response Cache
Spec
Cache Key Variants
There should be some default(s) for how to generate cache keys, and perhaps the option for a custom function to generate it.
For example:
node-id-> thenodename + thenodeid.parent-field-> the parentnodename + the field name + the parents id + field arguments.custom-> a function that returns a key given the resolved cache key type, the info object, the parent, and args.
node(definition) - A graphql type with the @key directive.
Issues/Prerequisites
- For
node-idhow to resolve the id before the node is fetched. - For
parent-fieldparent must be a node.
Possible solutions
- For
__resolveReferencefields use@keydirectivesfieldsargument. to get it from parent. - For any other case assume args contains the
fieldsof the@keydirective.
- Better solution for later could be recursively looking through the input ast
to find a single field with type
ID!, and/or finding a keyidor containingid(respecting snake/camel etc. case)
- For
parent-fieldThe parent may not exist, like in the case for aquery.
TODO
- [ ] Prettify generated
.d.ts - [ ] Improve
ID!resolving fornode-idcache key variant - [ ] Improve Docs
- [ ] Validate resulting
node's id with resolved cache key
