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

Validate that deprecated requirements aren't required #3137

Merged

Conversation

jturkel
Copy link
Contributor

@jturkel jturkel commented Sep 8, 2020

Following up on the discussion in #3133, this adds validation to prevent deprecating required arguments in the class based API. The validation added in #3015 only covered the legacy API.

@@ -164,6 +165,11 @@ def to_graphql

def type=(new_type)
validate_input_type(new_type)
# This isn't true for LateBoundTypes, but we can assume those will
# be updated via this codepath later in schema setup.
if new_type.respond_to?(:non_null?)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Out of curiosity what's the expected relationship between new_type.non_null? and @null? Think we should validate that the two are consistent?

Copy link
Owner

Choose a reason for hiding this comment

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

I'm not sure... There are hacks that work like argument(name, type_string, required: false), where type_string may include !. For example, that's how parsing a schema from SDL works; The SDL loader code just passes the type string along as-is, with required: false:

type: type_resolver.call(argument_defn.type),
required: false,

As for @null, I consider it a private implementation detail of Argument. To find out if an argument's type is non-null, you can call argument.type.non_null? (with the exception noted here: GraphQL internal types don't have that available right away -- but by the time you run a query, argument.type.non_null? will work).

@rmosolgo
Copy link
Owner

rmosolgo commented Sep 9, 2020

The dang integration test is failing, but 👍. I pushed a commit to cover types defined by strings.

@rmosolgo rmosolgo added this to the 1.11.5 milestone Sep 9, 2020
@rmosolgo rmosolgo merged commit ac9f237 into rmosolgo:master Sep 9, 2020
@rmosolgo
Copy link
Owner

rmosolgo commented Sep 9, 2020

Thanks for the improvement!

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