-
Notifications
You must be signed in to change notification settings - Fork 242
chore: propose @openfed__queryCache rfc #3039
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
Draft
Aenimus
wants to merge
1
commit into
main
Choose a base branch
from
david/eng-9829-openfed__queryCache
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,94 @@ | ||
| --- | ||
| title: "@openfed__queryCache: return a cache from a root query field" | ||
| author: David Stutt | ||
| --- | ||
|
|
||
| # Introduction | ||
| ```graphql | ||
| directive @openfed__queryCache( | ||
| maxAge: Int! | ||
| includeHeaders: Boolean = false | ||
| shadowMode: Boolean = false | ||
| ) on FIELD_DEFINITION | ||
| ``` | ||
|
|
||
| The intention of `@openfed__queryCache` is to allow the user to configure type agnostic caching for a query. | ||
| The premise is simple: | ||
| Has the query root field with its appropriate argument values been requested before within the maxAge limit? | ||
| Yes: retrieve from the cache | ||
| No: fetch and repopulate the cache | ||
|
|
||
| # Cache key | ||
|
|
||
| ## No field arguments | ||
| If the operation provides no argument values (regardless of whether the field defines arguments), the cache key might | ||
| simply be `Query.fieldName`. | ||
|
|
||
| ## Field arguments | ||
| If the the operation provides argument values, those values will need to be deterministically ordered. | ||
| For instance: | ||
| ```graphql | ||
| query { | ||
| user(a: 1, b: 2) | ||
| } | ||
| ``` | ||
|
|
||
| and | ||
| ```graphql | ||
| query { | ||
| user(b: 2, a: 1) | ||
| } | ||
| ``` | ||
|
|
||
| should hit the same cache value. | ||
|
|
||
| This should also be true for more complex inputs, e.g.: | ||
|
|
||
| ```graphql | ||
| query { | ||
| user( | ||
| inputA: { | ||
| a: "hello", | ||
| b: "world" | ||
| }, | ||
| inputB: { | ||
| a: 6.9 | ||
| inputC: { | ||
| x: 1, | ||
| y: true, | ||
| }, | ||
| }, | ||
| ) | ||
| } | ||
| ``` | ||
| and | ||
| ```graphql | ||
| query { | ||
| user( | ||
| inputB: { | ||
| inputC: { | ||
| y: true, | ||
| x: 1, | ||
| }, | ||
| a: 6.9 | ||
| }, | ||
| inputA: { | ||
| b: "world" | ||
| a: "hello", | ||
| }, | ||
| ) | ||
| } | ||
| ``` | ||
| should hit the same cache value. | ||
|
|
||
| # Interaction with @openfed__entityCache | ||
| `@openfed__queryCache` is intended to be type agnostic. | ||
| If the user defines this directive on a query field, the input is used as a key, and a value (if it exists) is | ||
| retrieved. | ||
| If the user intends to use the entity cache from a query field, a different method would be used (upcoming RFC). | ||
|
|
||
| # Errors | ||
| Errors will be returned from composition if: | ||
| 1. The directive is defined on a non query root field. | ||
| 2. The query root field defines any other caching directive. | ||
| 3. The max age is <= 0. | ||
|
Aenimus marked this conversation as resolved.
|
||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.