Sha256: 0413bd5770278c31bd2bee51fe6266434107bfb1697299f23727a0827b052d9e

Contents?: true

Size: 833 Bytes

Versions: 13

Compression:

Stored size: 833 Bytes

Contents

module GraphQL
  module StaticValidation
    class 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
  end
end

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
graphql-0.17.2 lib/graphql/static_validation/rules/variables_are_input_types.rb
graphql-0.17.1 lib/graphql/static_validation/rules/variables_are_input_types.rb
graphql-0.17.0 lib/graphql/static_validation/rules/variables_are_input_types.rb
graphql-0.16.1 lib/graphql/static_validation/rules/variables_are_input_types.rb
graphql-0.16.0 lib/graphql/static_validation/rules/variables_are_input_types.rb
graphql-0.15.3 lib/graphql/static_validation/rules/variables_are_input_types.rb
graphql-0.15.2 lib/graphql/static_validation/rules/variables_are_input_types.rb
graphql-0.14.2 lib/graphql/static_validation/rules/variables_are_input_types.rb
graphql-0.15.1 lib/graphql/static_validation/rules/variables_are_input_types.rb
graphql-0.15.0 lib/graphql/static_validation/rules/variables_are_input_types.rb
graphql-0.14.1 lib/graphql/static_validation/rules/variables_are_input_types.rb
graphql-0.14.0 lib/graphql/static_validation/rules/variables_are_input_types.rb
graphql-0.13.0 lib/graphql/static_validation/rules/variables_are_input_types.rb