Sha256: 229fe890bfd4fb5c334aa4b24c3c1f116073711c989d3a3ac7887335447487c0

Contents?: true

Size: 1.03 KB

Versions: 148

Compression:

Stored size: 1.03 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.graphql_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

148 entries across 148 versions & 2 rubygems

Version Path
graphql-2.2.16 lib/graphql/static_validation/rules/variables_are_input_types.rb
graphql-2.1.13 lib/graphql/static_validation/rules/variables_are_input_types.rb
graphql-2.3.7 lib/graphql/static_validation/rules/variables_are_input_types.rb
graphql-2.3.6 lib/graphql/static_validation/rules/variables_are_input_types.rb
graphql-2.3.5 lib/graphql/static_validation/rules/variables_are_input_types.rb
graphql-2.0.31 lib/graphql/static_validation/rules/variables_are_input_types.rb
graphql-2.3.2 lib/graphql/static_validation/rules/variables_are_input_types.rb
graphql-2.3.1 lib/graphql/static_validation/rules/variables_are_input_types.rb
graphql-1.13.23 lib/graphql/static_validation/rules/variables_are_input_types.rb
graphql-2.3.0 lib/graphql/static_validation/rules/variables_are_input_types.rb
graphql-2.2.14 lib/graphql/static_validation/rules/variables_are_input_types.rb
graphql-2.2.13 lib/graphql/static_validation/rules/variables_are_input_types.rb
graphql-2.2.12 lib/graphql/static_validation/rules/variables_are_input_types.rb
graphql-2.0.29 lib/graphql/static_validation/rules/variables_are_input_types.rb
graphql-2.1.12 lib/graphql/static_validation/rules/variables_are_input_types.rb
graphql-1.13.22 lib/graphql/static_validation/rules/variables_are_input_types.rb
graphql-2.2.11 lib/graphql/static_validation/rules/variables_are_input_types.rb
graphql-2.2.10 lib/graphql/static_validation/rules/variables_are_input_types.rb
graphql-2.2.9 lib/graphql/static_validation/rules/variables_are_input_types.rb
graphql-2.2.8 lib/graphql/static_validation/rules/variables_are_input_types.rb