diff --git a/lib/graphql/analysis/ast/field_usage.rb b/lib/graphql/analysis/ast/field_usage.rb index de95edd914..dc83577dbd 100644 --- a/lib/graphql/analysis/ast/field_usage.rb +++ b/lib/graphql/analysis/ast/field_usage.rb @@ -48,7 +48,7 @@ def extract_deprecated_arguments(argument_values) argument_type = argument_type.of_type end - if argument_type.kind.input_object? + if argument_type.kind.input_object? && argument.value.respond_to?(:arguments) # Skip if value is not a GraphQL::Schema::InputObject extract_deprecated_arguments(argument.value.arguments.argument_values) # rubocop:disable Development/ContextIsPassedCop -- runtime args instance elsif argument_type.kind.enum? extract_deprecated_enum_value(argument_type, argument.value) diff --git a/spec/graphql/analysis/ast/field_usage_spec.rb b/spec/graphql/analysis/ast/field_usage_spec.rb index 6e54ac38df..53cafb4851 100644 --- a/spec/graphql/analysis/ast/field_usage_spec.rb +++ b/spec/graphql/analysis/ast/field_usage_spec.rb @@ -254,6 +254,17 @@ end end + describe "mutation with deprecated arguments with prepared values does not break" do + let(:query_string) {%| + mutation { + pushValue(preparedTestInput: { deprecatedDate: "2020-10-10" }) + } + |} + + it "does not keeps track of nested deprecated arguments" do + assert_equal [], result[:used_deprecated_arguments] + end + end describe "when an argument prepare raises a GraphQL::ExecutionError" do class ArgumentErrorFieldUsageSchema < GraphQL::Schema diff --git a/spec/support/dummy/schema.rb b/spec/support/dummy/schema.rb index 206142cdb0..d88b2d2ab5 100644 --- a/spec/support/dummy/schema.rb +++ b/spec/support/dummy/schema.rb @@ -265,6 +265,18 @@ class DairyProductInput < BaseInputObject argument :old_source, String, required: false, deprecation_reason: "No longer supported" end + class PreparedDateInput < BaseInputObject + description "Input with prepared value" + argument :date, String, description: "date as a string", required: false + argument :deprecated_date, String, description: "date as a string", required: false, deprecation_reason: "Use date" + + def prepare + return nil unless date || deprecated_date + + Date.parse(date || deprecated_date) + end + end + class DeepNonNull < BaseObject field :non_null_int, Integer, null: false do argument :returning, Integer, required: false @@ -490,6 +502,7 @@ class DairyAppMutation < BaseObject field :push_value, [Integer], null: false, description: "Push a value onto a global array :D" do argument :value, Integer, as: :val argument :deprecated_test_input, DairyProductInput, required: false + argument :prepared_test_input, PreparedDateInput, required: false end def push_value(val:) GLOBAL_VALUES << val