Skip to content

Validate that deprecated requirements aren't required#3137

Merged
rmosolgo merged 2 commits intormosolgo:masterfrom
jturkel:feature/deprecated-required-arguments
Sep 9, 2020
Merged

Validate that deprecated requirements aren't required#3137
rmosolgo merged 2 commits intormosolgo:masterfrom
jturkel:feature/deprecated-required-arguments

Conversation

@jturkel
Copy link
Copy Markdown
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.

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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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