Skip to content

Allow an optional function to resolve the rootValue#1555

Merged
evans merged 4 commits into
apollographql:masterfrom
tgriesser:rootValueFn
Sep 20, 2018
Merged

Allow an optional function to resolve the rootValue#1555
evans merged 4 commits into
apollographql:masterfrom
tgriesser:rootValueFn

Conversation

@tgriesser

Copy link
Copy Markdown
Contributor

This allows providing a function to the rootValue option, which is called with the parsed query AST DocumentNode and the return value determines the value of the root.

This is useful in situations where you want to provide a different rootValue depending on the operation type, for instance if the rootValue should be different for a query vs a mutation

It also includes the commit from the type fixes in #1554

TODO:

  • Update CHANGELOG.md with your change (include reference to issue & this PR)
  • Make sure all of the significant new logic is covered by tests
  • Rebase your changes on master so that they can be merged easily
  • Make sure all tests and linter rules pass

@ghost ghost added the ⛲️ feature New addition or enhancement to existing solutions label Aug 20, 2018

@evans evans left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@tgriesser Thanks for adding this support! Let's get some documentation for it in the API reference and then we can merge it

@tgriesser

Copy link
Copy Markdown
Contributor Author

Great! Rebased & added API reference docs - let me know if you want me to add anything else.

@tgriesser

Copy link
Copy Markdown
Contributor Author

Not sure why the netlify check didn't pass

Passes the parsed DocumentNode AST to determine the root value,
useful when providing a different rootValue for query vs mutation
@tgriesser

Copy link
Copy Markdown
Contributor Author

@evans bump

@evans evans merged commit 4175f1b into apollographql:master Sep 20, 2018
@evans

evans commented Sep 20, 2018

Copy link
Copy Markdown
Contributor

@tgriesser Thank you!

@tgriesser tgriesser deleted the rootValueFn branch September 20, 2018 22:44
abernix added a commit that referenced this pull request Sep 24, 2018
abernix added a commit that referenced this pull request Sep 27, 2018
abernix pushed a commit that referenced this pull request Sep 27, 2018
* Allow an optional function to resolve the rootValue

Passes the parsed DocumentNode AST to determine the root value,
useful when providing a different rootValue for query vs mutation

* Add API docs for rootValue
@alexisbertholom

alexisbertholom commented Oct 5, 2018

Copy link
Copy Markdown

It would be nice if we could pass the QueryOptions to this function, so we can, for example, provide a different rootValue depending on the Context. I'd gladly send a PR, I already have the code ready.

@github-actions github-actions Bot locked as resolved and limited conversation to collaborators Apr 22, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

⛲️ feature New addition or enhancement to existing solutions

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants