Sha256: adbf50bcd00cf2df6298dd40f9576d9f8b3c41e3817204c13164ae67a58eb3cd

Contents?: true

Size: 851 Bytes

Versions: 19

Compression:

Stored size: 851 Bytes

Contents

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.schema.types[type_name]
        if !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

19 entries across 19 versions & 1 rubygems

Version Path
graphql-0.19.2 lib/graphql/static_validation/rules/variables_are_input_types.rb
graphql-0.19.1 lib/graphql/static_validation/rules/variables_are_input_types.rb
graphql-0.19.0 lib/graphql/static_validation/rules/variables_are_input_types.rb
graphql-0.18.15 lib/graphql/static_validation/rules/variables_are_input_types.rb
graphql-0.18.14 lib/graphql/static_validation/rules/variables_are_input_types.rb
graphql-0.18.13 lib/graphql/static_validation/rules/variables_are_input_types.rb
graphql-0.18.12 lib/graphql/static_validation/rules/variables_are_input_types.rb
graphql-0.18.11 lib/graphql/static_validation/rules/variables_are_input_types.rb
graphql-0.18.10 lib/graphql/static_validation/rules/variables_are_input_types.rb
graphql-0.18.9 lib/graphql/static_validation/rules/variables_are_input_types.rb
graphql-0.18.8 lib/graphql/static_validation/rules/variables_are_input_types.rb
graphql-0.18.7 lib/graphql/static_validation/rules/variables_are_input_types.rb
graphql-0.18.6 lib/graphql/static_validation/rules/variables_are_input_types.rb
graphql-0.18.5 lib/graphql/static_validation/rules/variables_are_input_types.rb
graphql-0.18.4 lib/graphql/static_validation/rules/variables_are_input_types.rb
graphql-0.18.3 lib/graphql/static_validation/rules/variables_are_input_types.rb
graphql-0.18.2 lib/graphql/static_validation/rules/variables_are_input_types.rb
graphql-0.18.1 lib/graphql/static_validation/rules/variables_are_input_types.rb
graphql-0.18.0 lib/graphql/static_validation/rules/variables_are_input_types.rb