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

RFC(graphcache): Configurable Cache Directives #3191

Closed
kitten opened this issue Apr 27, 2023 · 0 comments · Fixed by #3306
Closed

RFC(graphcache): Configurable Cache Directives #3191

kitten opened this issue Apr 27, 2023 · 0 comments · Fixed by #3306
Labels
future 🔮 An enhancement or feature proposal that will be addressed after the next release

Comments

@kitten
Copy link
Member

kitten commented Apr 27, 2023

Summary

We have three categories of features and problems that have come up repeatedly and have a potentially common solution:

  • When using relayPagination/simplePagination/custom resolvers that merge fields, it's impossible to tell when these resolvers should actually be not used
    • if a paginated field is used for infinite pagination and regular pagination, and both happen in the same query, they conflict.
    • if a paginated field shouldn't be infinitely paginated in another query, a custom wrapper must be written around the helpers to prevent this manually
  • We have considered the addition of @required and @optional directives, which “preempt” the support for nullability operators on the client-side, and are an alternative to schema awareness
    • They further become more important when we consider future scenarios where fragments may be partially loading, while the full query has only partially resolved against the cache
  • We have past requests for being able to selectively apply resolvers or not: RFC: Allow for selectively skipping local resolver with a hook option #2650

We could consider solving these problems in one go by adding custom directive support to Graphcache. With custom directives, instead of adding additional “switching/toggling” logic to Graphcache, we make potentially arbitrary resolvers configurable.

e.g. relayPagination could be included as an @relayPagination directive.

Proposed Solution

cacheExchange({
  directives: {
    relayPagination,
    required,
    optional,
    asDate: (parent, args, cache, info) {
      return new Date(cache.resolve(parent, info.parentFieldKey));
    },
  },
});

Some questions that require further consdieration (TBD):

  • Will directives simply ever be resolvers?
  • Will they have the same shape and should there be a shortcut for cache.resolve(parent, info.parentFieldKey)?
  • How does this affect typing and is @required and @optional feasibly implemented as a resolver?
  • How do we deal with directives on fragments?

Requirements

TBD

@kitten kitten added the future 🔮 An enhancement or feature proposal that will be addressed after the next release label Apr 27, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
future 🔮 An enhancement or feature proposal that will be addressed after the next release
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant