Sha256: 65573f30d63bdc97008b5bff0c6d263d06e124842334947cc88d53722c28317a

Contents?: true

Size: 1.02 KB

Versions: 25

Compression:

Stored size: 1.02 KB

Contents

# frozen_string_literal: true
module GraphQL
  module StaticValidation
    module VariablesAreInputTypes
      def on_variable_definition(node, parent)
        type_name = get_type_name(node.type)
        type = context.warden.get_type(type_name)

        if type.nil?
          add_error(GraphQL::StaticValidation::VariablesAreInputTypesError.new(
            "#{type_name} isn't a defined input type (on $#{node.name})",
            nodes: node,
            name: node.name,
            type: type_name
          ))
        elsif !type.kind.input?
          add_error(GraphQL::StaticValidation::VariablesAreInputTypesError.new(
            "#{type.name} isn't a valid input type (on $#{node.name})",
            nodes: node,
            name: node.name,
            type: type_name
          ))
        end

        super
      end

      private

      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

25 entries across 25 versions & 1 rubygems

Version Path
graphql-1.9.21 lib/graphql/static_validation/rules/variables_are_input_types.rb
graphql-1.9.20 lib/graphql/static_validation/rules/variables_are_input_types.rb
graphql-1.9.19 lib/graphql/static_validation/rules/variables_are_input_types.rb
graphql-1.9.18 lib/graphql/static_validation/rules/variables_are_input_types.rb
graphql-1.9.17 lib/graphql/static_validation/rules/variables_are_input_types.rb
graphql-1.9.16 lib/graphql/static_validation/rules/variables_are_input_types.rb
graphql-1.9.15 lib/graphql/static_validation/rules/variables_are_input_types.rb
graphql-1.9.14 lib/graphql/static_validation/rules/variables_are_input_types.rb
graphql-1.9.13 lib/graphql/static_validation/rules/variables_are_input_types.rb
graphql-1.9.12 lib/graphql/static_validation/rules/variables_are_input_types.rb
graphql-1.9.11 lib/graphql/static_validation/rules/variables_are_input_types.rb
graphql-1.9.10 lib/graphql/static_validation/rules/variables_are_input_types.rb
graphql-1.9.9 lib/graphql/static_validation/rules/variables_are_input_types.rb
graphql-1.9.8 lib/graphql/static_validation/rules/variables_are_input_types.rb
graphql-1.9.7 lib/graphql/static_validation/rules/variables_are_input_types.rb
graphql-1.9.6 lib/graphql/static_validation/rules/variables_are_input_types.rb
graphql-1.9.5 lib/graphql/static_validation/rules/variables_are_input_types.rb
graphql-1.9.4 lib/graphql/static_validation/rules/variables_are_input_types.rb
graphql-1.9.3 lib/graphql/static_validation/rules/variables_are_input_types.rb
graphql-1.9.2 lib/graphql/static_validation/rules/variables_are_input_types.rb