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

feat(graphcache): local directives #3306

Merged
merged 16 commits into from
Jul 21, 2023

Conversation

JoviDeCroock
Copy link
Collaborator

@JoviDeCroock JoviDeCroock commented Jul 5, 2023

Resolves #3191

See #3317 for more information on client-only directives.

Summary

This introduces a new property to the Graphcache config named directives, this will function as a more selective way to apply resolvers. i.e. you can do @_relayPagination only when you want it.

The directives config is populated by object entries that define client-only/local directives. A directive is a function that accepts an object of arguments passed to directives and must return a resolver.

If you add an entry relayPagination: (directiveArgs) => yourResolver then @_relayPagination will become available. All directives with a leading underscore are stripped from queries sent to the API after #3317.

This means that you can selectively implement local/client-only directives that only change what resolver is used in Graphcache!

Additionally, this introduces two default directives @_optional and @_required as a means to facilitate optional query selections without the client-controlled nullability spec being shipped 😅 this bridges the gap between schemaless and schema-aware graphcache.

You can add @_optional to allow Graphcache to default any field to a null value.
And, you can add @_required to tell Graphcache that a field is required, even if it's cached as null.

docs/graphcache/local-directives.md Show resolved Hide resolved
exchanges/graphcache/src/cacheExchange.ts Outdated Show resolved Hide resolved
exchanges/graphcache/src/types.ts Outdated Show resolved Hide resolved
@JoviDeCroock JoviDeCroock force-pushed the graphcache-directives branch 3 times, most recently from 6f58479 to 4a59c8a Compare July 19, 2023 17:57
@JoviDeCroock JoviDeCroock marked this pull request as ready for review July 19, 2023 17:57
@JoviDeCroock JoviDeCroock force-pushed the graphcache-directives branch from 4a59c8a to 7148e5f Compare July 19, 2023 19:18
exchanges/graphcache/src/operations/query.ts Outdated Show resolved Hide resolved
exchanges/graphcache/src/operations/query.ts Outdated Show resolved Hide resolved
exchanges/graphcache/src/store/store.ts Outdated Show resolved Hide resolved
exchanges/graphcache/src/types.ts Outdated Show resolved Hide resolved
exchanges/graphcache/src/operations/query.ts Outdated Show resolved Hide resolved
@JoviDeCroock JoviDeCroock force-pushed the graphcache-directives branch 6 times, most recently from 9fadcdf to 2cc1f23 Compare July 19, 2023 20:42
@JoviDeCroock JoviDeCroock force-pushed the graphcache-directives branch 3 times, most recently from 31e7a77 to 48407f3 Compare July 19, 2023 20:52
@JoviDeCroock JoviDeCroock force-pushed the graphcache-directives branch from 48407f3 to eefd806 Compare July 19, 2023 20:53
@kitten kitten merged commit 7c509f4 into urql-graphql:main Jul 21, 2023
kitten added a commit that referenced this pull request Jul 21, 2023
@github-actions github-actions bot mentioned this pull request Jul 21, 2023
@JoviDeCroock JoviDeCroock deleted the graphcache-directives branch September 11, 2023 08:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

RFC(graphcache): Configurable Cache Directives
2 participants