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

Allow an optional function to resolve the rootValue #1555

Merged
merged 4 commits into from Sep 20, 2018

Conversation

tgriesser
Copy link
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
Copy link
Contributor

@evans evans left a comment

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
Contributor Author

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

@tgriesser
Copy link
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
Contributor Author

@evans bump

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

evans commented Sep 20, 2018

@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
Copy link

alexisbertholom commented Oct 5, 2018

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.

None yet

4 participants