Sha256: 9f4923a5840df0b3a352fd3c8f32f88d3a1fe1fa56b65f0c406ecd13f7e61389

Contents?: true

Size: 954 Bytes

Versions: 26

Compression:

Stored size: 954 Bytes

Contents

# frozen_string_literal: true
module GraphQL
  module StaticValidation
    module FieldsAreDefinedOnType
      def on_field(node, parent)
        parent_type = @object_types[-2]
        field = context.warden.get_field(parent_type, node.name)

        if field.nil?
          if parent_type.kind.union?
            add_error(GraphQL::StaticValidation::FieldsHaveAppropriateSelectionsError.new(
              "Selections can't be made directly on unions (see selections on #{parent_type.name})",
              nodes: parent,
              node_name: parent_type.name
            ))
          else
            add_error(GraphQL::StaticValidation::FieldsAreDefinedOnTypeError.new(
              "Field '#{node.name}' doesn't exist on type '#{parent_type.name}'",
              nodes: node,
              field: node.name,
              type: parent_type.name
            ))
          end
        else
          super
        end
      end
    end
  end
end

Version data entries

26 entries across 26 versions & 1 rubygems

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