4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
|
# File 'lib/graph_ql/static_validation/rules/variable_usages_are_allowed.rb', line 4
def validate(context)
declared_variables = {}
context.visitor[GraphQL::Nodes::OperationDefinition] << -> (node, parent) {
declared_variables = node.variables.each_with_object({}) { |var, memo| memo[var.name] = var }
}
context.visitor[GraphQL::Nodes::Argument] << -> (node, parent) {
return if !node.value.is_a?(GraphQL::Nodes::VariableIdentifier)
if parent.is_a?(GraphQL::Nodes::Field)
arguments = context.field_definition.arguments
elsif parent.is_a?(GraphQL::Nodes::Directive)
arguments = context.directive_definition.arguments
end
var_defn_ast = declared_variables[node.value.name]
validate_usage(arguments, node, var_defn_ast, context)
}
end
|