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

Improve type checks on variables #1141

Merged

Conversation

maartenvanvliet
Copy link
Contributor

@maartenvanvliet maartenvanvliet commented Jan 9, 2022

Currently the check was whether the unwrapped type of the variable and e.g. the argument were the same. The spec is stricter than this. In particular this section: https://spec.graphql.org/October2021/#sec-All-Variable-Usages-are-Allowed

This PR adds checks to see if the wrapped types are the same or the variable is stricter than the argument. Also, when default values are given some of these checks can be relaxed.

This is a bugfix in respect to the spec but will have the effect that some previously valid documents are now marked as invalid.

This fixes #1134

Necessary to get the name of the type when
the underlying type may not exist in the schema
and therefore `Absinthe.Type.name/1` won't work.
spec: https://spec.graphql.org/October2021/#sec-All-Variable-Usages-are-Allowed

fixes absinthe-graphql#1134

Several cases did not return errors
 * when the location type was non nullable and the variable nullable
 * when the location type was a list and the variable wasn't

Some cases are allowed:
  * contravariant, when the location type is nullable and the variable
    non-nullable
  * the the argument is non-nullable but either the variable or argument
    has a default value
With the changes on allowed variable usage they would only test
whether the directive variable in the operation was present. This
is covered elsewhere.
Copy link
Contributor

@benwilson512 benwilson512 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Dude you are on fire lately! Thanks for the contribution!

@benwilson512 benwilson512 merged commit 790e1c8 into absinthe-graphql:master Jan 18, 2022
@giddie
Copy link

giddie commented Jan 19, 2022

Great to see improved alignment to the spec, but I also wasn't expecting previously working queries to be rejected following a minor version bump, even after glancing through the changelog. I'm not sure how best to handle that sort of thing. Maybe a warning on the changelog entry?

@maartenvanvliet
Copy link
Contributor Author

The changelog could definitely be improved to list these sort of spec compliance bug fixes. I've done a PR here #1143 but more improvements are welcome.

@maartenvanvliet maartenvanvliet deleted the issues/var-typing branch January 19, 2022 10:14
@benwilson512
Copy link
Contributor

@giddie I think that's a fair concern. We could retire 1.6.7 and do a 1.7.0 release. @maartenvanvliet thoughts?

@maartenvanvliet
Copy link
Contributor Author

I think a 1.7 release makes sense. There may be other spec violation fixes that would break backwards compatibility but don't think there are any as impactful in day to day graphql usage as this one.

Some others like #921 would warrant clear opt-in behaviour

@benwilson512
Copy link
Contributor

1.6.7 has been retired, and 1.7.0 has been released.

@blakedietz
Copy link

If this is a potentially breaking change, why is this being pinned at 1.7.0 instead of 2.0.0?

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.

Nullability of operation variables missing validation
4 participants