Sha256: 287aca6fe2d5bdc970b69c86bffee6f606e763e0f77b111c43193d44559e717c

Contents?: true

Size: 1.03 KB

Versions: 13

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.query.types.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

13 entries across 13 versions & 1 rubygems

Version Path
graphql-2.3.20 lib/graphql/static_validation/rules/variables_are_input_types.rb
graphql-2.3.19 lib/graphql/static_validation/rules/variables_are_input_types.rb
graphql-2.3.18 lib/graphql/static_validation/rules/variables_are_input_types.rb
graphql-2.3.17 lib/graphql/static_validation/rules/variables_are_input_types.rb
graphql-2.3.16 lib/graphql/static_validation/rules/variables_are_input_types.rb
graphql-2.3.15 lib/graphql/static_validation/rules/variables_are_input_types.rb
graphql-2.3.14 lib/graphql/static_validation/rules/variables_are_input_types.rb
graphql-2.3.13 lib/graphql/static_validation/rules/variables_are_input_types.rb
graphql-2.3.12 lib/graphql/static_validation/rules/variables_are_input_types.rb
graphql-2.3.11 lib/graphql/static_validation/rules/variables_are_input_types.rb
graphql-2.3.10 lib/graphql/static_validation/rules/variables_are_input_types.rb
graphql-2.3.9 lib/graphql/static_validation/rules/variables_are_input_types.rb
graphql-2.3.8 lib/graphql/static_validation/rules/variables_are_input_types.rb