-
Notifications
You must be signed in to change notification settings - Fork 527
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
Fix bookkeeping of Resolution path when resolving #1208
Conversation
Addresses issue absinthe-graphql#1149. module `Absinthe.Phase.Document.Execution.Resolution` walks the result tree and tracks `path` using a function parameter. At the same time, a `Resolution` struct is passed, which `path` field is not consistently tracked. The problem manifests itself in bogus Resolution path passed onto `resolve_type` function as described in function absinthe-graphql#1149. The reason for not updating the resolution.path in the walk process can be explained by comment of @benwilson512: `Traditionally the reason we pass in the env has more to do with making the schema available and the context available, I don't know that the other values in that struct have been validated in this situation.` Perhaps path parameter was used in the beginning and later resolution paramter was added, but not used to track current tree walk in it's path field. Nevertheless, the resolution is passed on to user code - into `resolve_type(value, resolution)` callback, which might use path to understand the context of value (eg. what is the type of parent?). This PR fixes the bookkeeping of `resolution.path` field. I have not inspected the use of other field, I am not sure which ones would change during the value walk (`parent_type` maybe?). One could consider to just use `resolution.path` instead of `path` parameter - so there is not double bookkeeping of this value. This is up to maintainers to decide, I did not make such a change.
Hi @marcinkoziej thanks for taking a crack at this. I'm open to moving forward with this but it definitely needs a test case or two. I'll also need some time to get my head back into this module and make sure there aren't any unintended consequences of this change. Thanks for taking a step towards fixing it! |
Should I add it to the Interface test or into a separate file ? |
I think an interface_test would be good, and then any other more general resolution test that could demo the behavior could be interesting. Please also run |
Ran mix format and added a test. |
Thank you! |
Addresses issue #1149
module
Absinthe.Phase.Document.Execution.Resolution
walks the result tree and trackspath
using a function parameter. At the same time, aResolution
struct is passed, whichpath
field is not consistently tracked.The problem manifests itself in bogus Resolution path passed onto
resolve_type
function as described in function #1149.The reason for not updating the resolution.path in the walk process can be explained by comment of @benwilson512:
Traditionally the reason we pass in the env has more to do with making the schema available and the context available, I don't know that the other values in that struct have been validated in this situation.
Perhaps path parameter was used in the beginning and later resolution paramter was added, but not used to track current tree walk in it's path field.Nevertheless, the resolution is passed on to user code - into
resolve_type(value, resolution)
callback, which might use path to understand the context of value (eg. what is the type of parent?).This PR fixes the bookkeeping of
resolution.path
field. I have not inspected the use of other field, I am not sure which ones would change during the value walk (parent_type
maybe?).One could consider to just use
resolution.path
instead ofpath
parameter - so there is not double bookkeeping of this value. This is up to maintainers to decide, I did not make such a change.