-
Notifications
You must be signed in to change notification settings - Fork 2k
[RFC] Add explicit context arg to graphql execution #326
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
Conversation
You probably meant resolve: (val, args, { authToken }) { ... } Right? |
I like the change otherwise, it clears the slightly confusing "root value as context" pattern. Also destructuring in resolve became much easier. |
I think its a good idea, not for the de-structuring sugar, but to give each value a single responsiblity. |
This *BREAKING* change introduces a new argument to the GraphQL execution API which is presented to resolution functions: `context`. This solves a long-standing point of confusion about the correct way to represent authentication or a "viewer context" in which a query is executed. Previously, we suggested that the `rootValue` contain any authentication tokens, however this led to awkward code: ``` resolve: (val, args, { rootValue: { authToken } }) { ... } ``` Which can now be written as: ``` resolve: (val, args, authToken) { ... } ``` The `info` object is still created and provided to resolution functions, and the `rootValue` is still provided within it, however it is now the *fourth* argument rather than the *third*.
Stupid question: - why wasn't the argument added after the AST |
The breaking change is undesirable, but the final state of the API is much better. The now-fourth info argument will only very rarely be accessed, and that also allows us some opportunities for future performance tuning. |
Apologies if this a stupid question, pretty new to graphQL and am updating our versions. Just to clarify, ...
technology: {
type: Page,
resolve: (root, _, { rootValue: { flags, backend = backendReal }}) =>
backend(flags).capi.page(sources.technology.uuid)
},
... Now becomes ...
technology: {
type: Page,
resolve: (root, _, { flags, backend = backendReal }) =>
backend(flags).capi.page(sources.technology.uuid)
},
... Is that right? |
This BREAKING change introduces a new argument to the GraphQL execution API which is presented to resolution functions:
context
.This solves a long-standing point of confusion about the correct way to represent authentication or a "viewer context" in which a query is executed.
Previously, we suggested that the
rootValue
contain any authentication tokens, however this led to awkward code:Which can now be written as:
The
info
object is still created and provided to resolution functions, and therootValue
is still provided within it, however it is now the fourth argument rather than the third.