Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Problem
When defining a schema with a required (non-nullable) argument, the current implementation does not validate the presence of that argument when it's missing in a query. Instead of returning an error as expected, the query executes with the argument set to
nil
, leading to potentially unintended behavior.Example Schema
(as graphql schema :
)
Current Behavior
Query:
Response:
Expected Behavior:
The server should return an error indicating that the
name
argument cannot be null.Root Cause
The issue lies in the
Rails::GraphQL::Request::Organizable#parse_arguments
method, which returns an empty hash (EMPTY_HASH
) ifnodes
is blank. This bypasses the invocation of the::Organizable#collect_arguments
method, which contains the logic to check for non-nullable arguments.Relevant snippet from
collect_arguments
:Proposed Solution
Modify the
#parse_arguments
method to avoid returning prematurely whennodes
is blank. Instead, ensurecollect_arguments
is always called, even ifnodes
is nil. This is achieved by updating the code to handle the potential nullity ofnodes
using safe navigation (&.
).Why This Fix is Important
This bug is critical because it allows a query to bypass required argument checks, potentially leading to:
Implementation
#collect_arguments
is invoked regardless of whethernodes
is blank.nodes.each.with_object({})
logic with safe chaining (&.
) to gracefully handle cases wherenodes
is nil.Testing (TODO)
This fix addresses a critical validation bug in argument handling, improving both developer experience and application security.
Let me know if further details are needed!