Sha256: 9bb370225e7d4ccabf75dfe3f73b418ffa67de9253d89a8388e615e7565b8631

Contents?: true

Size: 717 Bytes

Versions: 4

Compression:

Stored size: 717 Bytes

Contents

class GraphQL::StaticValidation::VariablesAreInputTypes
  include GraphQL::StaticValidation::Message::MessageHelper

  def validate(context)
    context.visitor[GraphQL::Language::Nodes::VariableDefinition] << -> (node, parent) {
      validate_is_input_type(node, context)
    }
  end

  private

  def validate_is_input_type(node, context)
    type_name = get_type_name(node.type)
    type = context.schema.types[type_name]
    if !type.kind.input?
      context.errors << message("#{type.name} isn't a valid input type (on $#{node.name})", node)
    end
  end

  def get_type_name(ast_type)
    if ast_type.respond_to?(:of_type)
      get_type_name(ast_type.of_type)
    else
      ast_type.name
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
graphql-0.12.1 lib/graphql/static_validation/rules/variables_are_input_types.rb
graphql-0.12.0 lib/graphql/static_validation/rules/variables_are_input_types.rb
graphql-0.11.1 lib/graphql/static_validation/rules/variables_are_input_types.rb
graphql-0.11.0 lib/graphql/static_validation/rules/variables_are_input_types.rb