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.18 lib/graphql/static_validation/rules/variables_are_input_types.rb
graphql-1.8.17 lib/graphql/static_validation/rules/variables_are_input_types.rb
graphql-1.8.16 lib/graphql/static_validation/rules/variables_are_input_types.rb
graphql-1.8.15 lib/graphql/static_validation/rules/variables_are_input_types.rb
graphql-1.8.14 lib/graphql/static_validation/rules/variables_are_input_types.rb
graphql-1.8.13 lib/graphql/static_validation/rules/variables_are_input_types.rb
graphql-1.8.12 lib/graphql/static_validation/rules/variables_are_input_types.rb
graphql-1.8.11 lib/graphql/static_validation/rules/variables_are_input_types.rb
graphql-1.8.10 lib/graphql/static_validation/rules/variables_are_input_types.rb
graphql-1.8.9 lib/graphql/static_validation/rules/variables_are_input_types.rb
graphql-1.8.8 lib/graphql/static_validation/rules/variables_are_input_types.rb
graphql-1.8.7 lib/graphql/static_validation/rules/variables_are_input_types.rb
graphql-1.8.6 lib/graphql/static_validation/rules/variables_are_input_types.rb
graphql-1.8.5 lib/graphql/static_validation/rules/variables_are_input_types.rb
graphql-1.8.4 lib/graphql/static_validation/rules/variables_are_input_types.rb
graphql-1.8.3 lib/graphql/static_validation/rules/variables_are_input_types.rb
graphql-1.8.2 lib/graphql/static_validation/rules/variables_are_input_types.rb
graphql-1.8.1 lib/graphql/static_validation/rules/variables_are_input_types.rb
graphql-1.8.0 lib/graphql/static_validation/rules/variables_are_input_types.rb
graphql-1.8.0.pre11 lib/graphql/static_validation/rules/variables_are_input_types.rb