From 32eef0fa37b5e73ca454885a62acb812460b1b33 Mon Sep 17 00:00:00 2001 From: stanig2106 Date: Thu, 9 Jan 2025 01:35:13 +0100 Subject: [PATCH] Fix non-null argument validation in parse_arguments Updated the Rails::GraphQL::Request::Organizable#parse_arguments method to ensure that non-nullable arguments are properly validated, even when nodes is blank. Replaced the premature return of EMPTY_HASH with safe navigation (&.) to allow the method to handle cases where nodes is nil. Ensured collect_arguments is always invoked, allowing the required argument validation logic to run correctly. Added a fallback (|| {}) to prevent errors in cases where nodes is nil. --- lib/rails/graphql/request/steps/organizable.rb | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/lib/rails/graphql/request/steps/organizable.rb b/lib/rails/graphql/request/steps/organizable.rb index e4baade..a558db6 100644 --- a/lib/rails/graphql/request/steps/organizable.rb +++ b/lib/rails/graphql/request/steps/organizable.rb @@ -118,11 +118,9 @@ def parse_variables(nodes) # Helper parser for arguments that also collect necessary variables # Default values forces this method to run even without nodes def parse_arguments(nodes) - return @arguments = EMPTY_HASH if nodes.blank? - - args = nodes.each.with_object({}) do |(name, value, var_name), hash| + args = nodes&.each&.with_object({}) do |(name, value, var_name), hash| hash[name.to_s] = var_name.nil? ? value : var_name - end + end || {} args = collect_arguments(self, args) @arguments = request.build(Request::Arguments, args).freeze