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

Fix bookkeeping of Resolution path when resolving #1208

Merged
merged 3 commits into from
Nov 28, 2022

Conversation

marcinkoziej
Copy link
Contributor

Addresses issue #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 #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.

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.
@benwilson512
Copy link
Contributor

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!

@marcinkoziej
Copy link
Contributor Author

Should I add it to the Interface test or into a separate file ?

@benwilson512
Copy link
Contributor

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 mix format on the code so that the test suite will run.

@marcinkoziej
Copy link
Contributor Author

Ran mix format and added a test.

@marcinkoziej
Copy link
Contributor Author

@benwilson512 👋

@benwilson512
Copy link
Contributor

Thank you!

@benwilson512 benwilson512 merged commit 972d7c8 into absinthe-graphql:master Nov 28, 2022
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

Successfully merging this pull request may close these issues.

2 participants