Conversation
Contributor
|
You probably meant resolve: (val, args, { authToken }) { ... }Right? |
Contributor
|
I like the change otherwise, it clears the slightly confusing "root value as context" pattern. Also destructuring in resolve became much easier. |
Contributor
|
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 |
Contributor
Author
|
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. |
This was referenced Apr 19, 2016
|
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 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
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
rootValuecontain any authentication tokens, however this led to awkward code:Which can now be written as:
The
infoobject is still created and provided to resolution functions, and therootValueis still provided within it, however it is now the fourth argument rather than the third.