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

Pass rootValue from execution context to resolveType #103

Closed
charypar opened this issue Aug 3, 2015 · 3 comments
Closed

Pass rootValue from execution context to resolveType #103

charypar opened this issue Aug 3, 2015 · 3 comments

Comments

@charypar
Copy link

charypar commented Aug 3, 2015

It would be quite useful to get the rootValue in resolveType the same way you get it in field resolvers.

In my case I need to dynamically chose which fetching backend implementation to use and I'm passing it in in the rootValue. The backend also does list filtering by various predicates, one of which is the item type - the backend therefore needs to be able to resolve the item type the same way the interface does.

The natural place for this logic is the backend itself (all backend-specific things sit in one place), but since I only know the right implementation at query run time the type detection logic is now duplicated.

I can imagine other use-cases for the rootValue in resolveType - e.g. using an authorisation system to resolve to basic or extended type (guess that is kinda contrived) or some sort of user-specified type resolution rules maybe.

@leebyron
Copy link
Contributor

leebyron commented Aug 4, 2015

This happens today, though the variable naming is probably confusing. We're using the terms context and rootValue interchangeably. I'll keep this task open to resolve the naming sloppiness.

leebyron added a commit that referenced this issue Aug 11, 2015
This solves the issue raised in #103 by providing a second argument with this information.

There is also some minor renaming happening in this diff to match previous diffs.
@leebyron
Copy link
Contributor

These last two diffs should add the functionality you're looking for!

@leebyron
Copy link
Contributor

They will be released on npm in the near future.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants