@@ -8,14 +8,15 @@ def initialize(query)
88 @used_fields = Set . new
99 @used_deprecated_fields = Set . new
1010 @used_deprecated_arguments = Set . new
11+ @used_deprecated_enum_values = Set . new
1112 end
1213
1314 def on_leave_field ( node , parent , visitor )
1415 field_defn = visitor . field_definition
1516 field = "#{ visitor . parent_type_definition . graphql_name } .#{ field_defn . graphql_name } "
1617 @used_fields << field
1718 @used_deprecated_fields << field if field_defn . deprecation_reason
18- arguments = visitor . query . arguments_for ( node , visitor . field_definition )
19+ arguments = visitor . query . arguments_for ( node , field_defn )
1920 # If there was an error when preparing this argument object,
2021 # then this might be an error or something:
2122 if arguments . respond_to? ( :argument_values )
@@ -28,6 +29,7 @@ def result
2829 used_fields : @used_fields . to_a ,
2930 used_deprecated_fields : @used_deprecated_fields . to_a ,
3031 used_deprecated_arguments : @used_deprecated_arguments . to_a ,
32+ used_deprecated_enum_values : @used_deprecated_enum_values . to_a ,
3133 }
3234 end
3335
@@ -41,19 +43,39 @@ def extract_deprecated_arguments(argument_values)
4143
4244 next if argument . value . nil?
4345
44- if argument . definition . type . kind . input_object?
46+ argument_type = argument . definition . type
47+ if argument_type . non_null?
48+ argument_type = argument_type . of_type
49+ end
50+
51+ if argument_type . kind . input_object?
4552 extract_deprecated_arguments ( argument . value . arguments . argument_values ) # rubocop:disable Development/ContextIsPassedCop -- runtime args instance
46- elsif argument . definition . type . kind . enum?
47- enum_value = argument . definition . type . values [ argument . value ]
48- @used_deprecated_arguments << argument . definition . path if enum_value . deprecation_reason
49- elsif argument . definition . type . list?
50- argument
51- . value
52- . select { |value | value . respond_to? ( :arguments ) }
53- . each { |value | extract_deprecated_arguments ( value . arguments . argument_values ) } # rubocop:disable Development/ContextIsPassedCop -- runtime args instance
53+ elsif argument_type . kind . enum?
54+ extract_deprecated_enum_value ( argument_type , argument . value )
55+ elsif argument_type . list?
56+ inner_type = argument_type . unwrap
57+ case inner_type . kind
58+ when TypeKinds ::INPUT_OBJECT
59+ argument . value . each do |value |
60+ extract_deprecated_arguments ( value . arguments . argument_values ) # rubocop:disable Development/ContextIsPassedCop -- runtime args instance
61+ end
62+ when TypeKinds ::ENUM
63+ argument . value . each do |value |
64+ extract_deprecated_enum_value ( inner_type , value )
65+ end
66+ else
67+ # Not a kind of input that we track
68+ end
5469 end
5570 end
5671 end
72+
73+ def extract_deprecated_enum_value ( enum_type , value )
74+ enum_value = @query . warden . enum_values ( enum_type ) . find { |ev | ev . value == value }
75+ if enum_value &.deprecation_reason
76+ @used_deprecated_enum_values << enum_value . path
77+ end
78+ end
5779 end
5880 end
5981 end
0 commit comments