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

Variables Passed in the request should be accessible by the context. Expose helpers to get arguments at any level #836

Closed
jkporter opened this issue Jun 12, 2019 · 8 comments · Fixed by #958
Assignees
Labels
❓ question This issue is a question about feature of Hot Chocolate.
Milestone

Comments

@jkporter
Copy link

Is your feature request related to a problem? Please describe.
I'm creating a resolver that translates SQL to GraphQL. In order to construct the hierarchy I effectively need the resolver context information of each child. Since I can walk the selections and have access the the schema I can create most the information I need at each level, I cannot however get access to variable values w/o adding them to the context or properties and then doing quite a bit of work to figure the argument values at each level.

Describe the solution you'd like
A clear way to get argument values from any field selection.

Describe alternatives you've considered
Per above passing variable values in context or properties and then doing the work to get the values thereafter which isn't trivial.

@jkporter
Copy link
Author

Also looking at the JavaScript reference implementation the analog of resolver context does seem to expose variables and values.

@michaelstaib
Copy link
Member

There is a more efficient way to do that actually, although I have to put you some things together here for you so I will look into this tomorrow.

But just to give you a hint how this would work.

We can do a look ahead with the resolver context by using `CollectFields. Collect fields basically does all the hard work and gets you the field of the next level and prepares the arguments.

This is also what we internally do when we complete an object.

We have two overloads of CollectFields allowing us to walk the graph. Collect fields will compute @skip and @include and we get the fields correctly computed that really have to be fetched from the database storage.

We now only need to create the argument collection which will compute what the actual values are for each field.

That should basically give you everything and in a much more performant way.

I will paste some code examples tomorrow to get you started.

@michaelstaib michaelstaib self-assigned this Jun 12, 2019
@michaelstaib michaelstaib added 🔍 investigate Indicates that an issue or pull request needs more information. ❓ question This issue is a question about feature of Hot Chocolate. labels Jun 12, 2019
@michaelstaib michaelstaib added this to the 9.1.0 milestone Jun 12, 2019
@jkporter
Copy link
Author

Wow thanks for feedback and support. That would greatly appreciated! started looking into CollectFields but didn't quite get how to take advantage of it and I was squarely focused on resolving argument values at the time. For traversal the current method has a non-trivial amount of edge cases and being able to build the query at each step is w/o the expectation that the parent is already resolved would probably a better route.

@jkporter
Copy link
Author

The CollectFields method seems pretty straightforward and I'm just starting to migrate my code to using that. Per your last response it would seem that I'd still need access to the IExecutionContext to capture and pass the needed IVariableCollection?

We now only need to create the argument collection which will compute what the actual values are for each field.

Wasn't clear if you meant this work was still pending or simply the last step.

@michaelstaib
Copy link
Member

I think we have still to make the helpers public .... but I will do that with the next preview.

@michaelstaib michaelstaib added enhancement and removed 🔍 investigate Indicates that an issue or pull request needs more information. labels Jul 31, 2019
@michaelstaib
Copy link
Member

michaelstaib commented Aug 3, 2019

I will put this in preview 41 tomorrow

@michaelstaib
Copy link
Member

This one is not implemented and will be released as preview 43

@michaelstaib
Copy link
Member

The resolver context (IResolverContext) has now a property variables that gives access to the coerced variables of the execution context.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
❓ question This issue is a question about feature of Hot Chocolate.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants