Module: GraphQL::StaticValidation::VariablesAreInputTypes
- Defined in:
- lib/graphql/static_validation/rules/variables_are_input_types.rb
Overview
-- @requires_ancestor: GraphQL::StaticValidation::BaseVisitor
Instance Method Summary collapse
-
#on_variable_definition(node, parent) ⇒ Object
: (GraphQL::Language::Nodes::VariableDefinition node, GraphQL::Language::Nodes::AbstractNode? parent) -> void.
Instance Method Details
#on_variable_definition(node, parent) ⇒ Object
: (GraphQL::Language::Nodes::VariableDefinition node, GraphQL::Language::Nodes::AbstractNode? parent) -> void
10 11 12 13 14 15 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 |
# File 'lib/graphql/static_validation/rules/variables_are_input_types.rb', line 10 def on_variable_definition(node, parent) type_name = get_type_name(node.type) type = context.types.type(type_name) if type.nil? suggestion = if schema.did_you_mean @all_possible_input_type_names ||= begin names = [] #: Array[String] context.types.all_types.each { |(t)| if t.kind.input? names << t.graphql_name end } names end #: Array[String]? context.did_you_mean_suggestion(type_name, @all_possible_input_type_names) end add_error(GraphQL::StaticValidation::VariablesAreInputTypesError.new( "#{type_name} isn't a defined input type (on $#{node.name})#{suggestion}", nodes: node, name: node.name, type: type_name )) elsif !type.kind.input? add_error(GraphQL::StaticValidation::VariablesAreInputTypesError.new( "#{type.graphql_name} isn't a valid input type (on $#{node.name})", nodes: node, name: node.name, type: type_name )) end super end |