Sha256: 92bdaacb44e25f2bc3e755096ef259cb53fcc2a5a521315918595b742d7d34e3

Contents?: true

Size: 987 Bytes

Versions: 13

Compression:

Stored size: 987 Bytes

Contents

# frozen_string_literal: true
module GraphQL
  module StaticValidation
    module FieldsAreDefinedOnType
      def on_field(node, parent)
        parent_type = @object_types[-2]
        field = context.query.types.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.graphql_name})",
              nodes: parent,
              node_name: parent_type.graphql_name
            ))
          else
            add_error(GraphQL::StaticValidation::FieldsAreDefinedOnTypeError.new(
              "Field '#{node.name}' doesn't exist on type '#{parent_type.graphql_name}'",
              nodes: node,
              field: node.name,
              type: parent_type.graphql_name
            ))
          end
        else
          super
        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/fields_are_defined_on_type.rb
graphql-2.3.19 lib/graphql/static_validation/rules/fields_are_defined_on_type.rb
graphql-2.3.18 lib/graphql/static_validation/rules/fields_are_defined_on_type.rb
graphql-2.3.17 lib/graphql/static_validation/rules/fields_are_defined_on_type.rb
graphql-2.3.16 lib/graphql/static_validation/rules/fields_are_defined_on_type.rb
graphql-2.3.15 lib/graphql/static_validation/rules/fields_are_defined_on_type.rb
graphql-2.3.14 lib/graphql/static_validation/rules/fields_are_defined_on_type.rb
graphql-2.3.13 lib/graphql/static_validation/rules/fields_are_defined_on_type.rb
graphql-2.3.12 lib/graphql/static_validation/rules/fields_are_defined_on_type.rb
graphql-2.3.11 lib/graphql/static_validation/rules/fields_are_defined_on_type.rb
graphql-2.3.10 lib/graphql/static_validation/rules/fields_are_defined_on_type.rb
graphql-2.3.9 lib/graphql/static_validation/rules/fields_are_defined_on_type.rb
graphql-2.3.8 lib/graphql/static_validation/rules/fields_are_defined_on_type.rb