Sha256: b31bb989f0903a24e00755f72d3f3b000553299e8591ac7ddc1f52ad3b67d1dc

Contents?: true

Size: 1.01 KB

Versions: 75

Compression:

Stored size: 1.01 KB

Contents

# frozen_string_literal: true
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.warden.get_type(type_name)

        if type.nil?
          context.errors << message("#{type_name} isn't a defined input type (on $#{node.name})", node, context: context)
        elsif !type.kind.input?
          context.errors << message("#{type.name} isn't a valid input type (on $#{node.name})", node, context: context)
        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

75 entries across 75 versions & 1 rubygems

Version Path
graphql-1.8.0.pre10 lib/graphql/static_validation/rules/variables_are_input_types.rb
graphql-1.7.14 lib/graphql/static_validation/rules/variables_are_input_types.rb
graphql-1.8.0.pre9 lib/graphql/static_validation/rules/variables_are_input_types.rb
graphql-1.8.0.pre8 lib/graphql/static_validation/rules/variables_are_input_types.rb
graphql-1.7.13 lib/graphql/static_validation/rules/variables_are_input_types.rb
graphql-1.8.0.pre7 lib/graphql/static_validation/rules/variables_are_input_types.rb
graphql-1.7.12 lib/graphql/static_validation/rules/variables_are_input_types.rb
graphql-1.7.11 lib/graphql/static_validation/rules/variables_are_input_types.rb
graphql-1.7.10 lib/graphql/static_validation/rules/variables_are_input_types.rb
graphql-1.8.0.pre6 lib/graphql/static_validation/rules/variables_are_input_types.rb
graphql-1.8.0.pre5 lib/graphql/static_validation/rules/variables_are_input_types.rb
graphql-1.7.9 lib/graphql/static_validation/rules/variables_are_input_types.rb
graphql-1.8.0.pre4 lib/graphql/static_validation/rules/variables_are_input_types.rb
graphql-1.8.0.pre3 lib/graphql/static_validation/rules/variables_are_input_types.rb
graphql-1.7.8 lib/graphql/static_validation/rules/variables_are_input_types.rb
graphql-1.8.0.pre2 lib/graphql/static_validation/rules/variables_are_input_types.rb
graphql-1.7.7 lib/graphql/static_validation/rules/variables_are_input_types.rb
graphql-1.8.0.pre1 lib/graphql/static_validation/rules/variables_are_input_types.rb
graphql-1.7.6 lib/graphql/static_validation/rules/variables_are_input_types.rb
graphql-1.7.5 lib/graphql/static_validation/rules/variables_are_input_types.rb