Skip to content

Fix field usage on prepared input types #1

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/graphql/analysis/ast/field_usage.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Copy link

Choose a reason for hiding this comment

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

We are running into the same issue with the graphql-ruby upgrade and this problem also happens below on line 60.

That is the case where the argument is a list of input objects. The call to value.arguments there fails too.

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)
Expand Down
11 changes: 11 additions & 0 deletions spec/graphql/analysis/ast/field_usage_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
13 changes: 13 additions & 0 deletions spec/support/dummy/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down