Sha256: 2be26e85244bb2832ad80bdc6038805d6f6cb71094c626f01cba8684365badca

Contents?: true

Size: 986 Bytes

Versions: 147

Compression:

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

147 entries across 147 versions & 2 rubygems

Version Path
graphql-1.10.3 lib/graphql/static_validation/rules/fields_are_defined_on_type.rb
graphql-1.10.2 lib/graphql/static_validation/rules/fields_are_defined_on_type.rb
graphql-1.10.1 lib/graphql/static_validation/rules/fields_are_defined_on_type.rb
graphql-1.10.0 lib/graphql/static_validation/rules/fields_are_defined_on_type.rb
graphql-1.10.0.pre4 lib/graphql/static_validation/rules/fields_are_defined_on_type.rb
graphql-1.10.0.pre3 lib/graphql/static_validation/rules/fields_are_defined_on_type.rb
graphql-1.10.0.pre2 lib/graphql/static_validation/rules/fields_are_defined_on_type.rb