16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
|
# File 'lib/graphql/static_validation/rules/variable_usages_are_allowed.rb', line 16
def on_argument(node, parent)
node_values = if node.value.is_a?(Array)
node.value
else
[node.value]
end
node_values = node_values.select { |value| value.is_a? GraphQL::Language::Nodes::VariableIdentifier }
if node_values.any?
arguments = case parent
when GraphQL::Language::Nodes::Field
context.field_definition.arguments
when GraphQL::Language::Nodes::Directive
context.directive_definition.arguments
when GraphQL::Language::Nodes::InputObject
arg_type = context.argument_definition.type.unwrap
if arg_type.is_a?(GraphQL::InputObjectType)
arguments = arg_type.input_fields
else
nil
end
else
raise("Unexpected argument parent: #{parent}")
end
node_values.each do |node_value|
var_defn_ast = @declared_variables[node_value.name]
var_defn_ast && arguments && validate_usage(arguments, node, var_defn_ast)
end
end
super
end
|