Skip to content

Fix nullability of GraphQL scalar types when passed as required arguments#2618

Open
joeytepp wants to merge 1 commit into
Shopify:mainfrom
joeytepp:fix-nilable-scalar-types
Open

Fix nullability of GraphQL scalar types when passed as required arguments#2618
joeytepp wants to merge 1 commit into
Shopify:mainfrom
joeytepp:fix-nilable-scalar-types

Conversation

@joeytepp
Copy link
Copy Markdown

@joeytepp joeytepp commented May 8, 2026

Motivation

Fixes #2337

Currently, the generated rbis for a GraphQL mutation that contains an argument that uses a scalar type will always treat the argument as nullable, even when it is required. This PR fixes it so that required arguments are treated as non-nullable.

Implementation

Updated GraphQLTypeHelper to use RBIHelper.as_non_nilable_type in the current branch of logic.

Tests

Added a new test in spec/tapioca/dsl/compilers/graphql_mutation_spec.rb

…ents

Currently, the generated rbis for a GraphQL mutation that contains an argument that uses a scalar type will always treat the argument as nullable, even when it is required. This PR fixes it so that required arguments are treated as non-nullable.
@joeytepp joeytepp requested a review from a team as a code owner May 8, 2026 20:19
@joeytepp
Copy link
Copy Markdown
Author

joeytepp commented May 8, 2026

I have signed the CLA!

return_type = signature&.return_type

valid_return_type?(return_type) ? return_type.to_s : "T.untyped"
valid_return_type?(return_type) ? RBIHelper.as_non_nilable_type(return_type.to_s) : "T.untyped"
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Can you give context on why we can assume coerce_input can't return nil?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

coerce_input has to handle both required and optional arguments, and for an optional argument it still gets called with an input of nil. So when we have a required argument the signature should no longer have a T.nilable(...) since we know the output won't be nil.

Copy link
Copy Markdown
Contributor

@KaanOzkan KaanOzkan May 11, 2026

Choose a reason for hiding this comment

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

Let's capture this in a comment since there's quite a bit going on, something like

# Wrap as non-nilable for required arguments. `coerce_input` supports both
# required and optional; optional arguments are re-wrapped below based on `type.non_null?`

@joeytepp joeytepp requested a review from KaanOzkan May 11, 2026 17:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Tapioca v0.17.5 doesn't handle typing of output of custom GraphQL Scalars correctly

2 participants