Method: GraphQL::Schema::Resolver::HasPayloadType#field

Defined in:
lib/graphql/schema/resolver/has_payload_type.rb

#field(*args, **kwargs, &block) ⇒ Object



62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
# File 'lib/graphql/schema/resolver/has_payload_type.rb', line 62

def field(*args, **kwargs, &block)
  pt = payload_type # make sure it's initialized with any inherited fields
  field_defn = super

  # Remove any inherited fields to avoid false conflicts at runtime
  prev_fields = pt.own_fields[field_defn.graphql_name]
  case prev_fields
  when GraphQL::Schema::Field
    if prev_fields.owner != self
      pt.own_fields.delete(field_defn.graphql_name)
    end
  when Array
    prev_fields.reject! { |f| f.owner != self }
    if prev_fields.empty?
      pt.own_fields.delete(field_defn.graphql_name)
    end
  end

  pt.add_field(field_defn, method_conflict_warning: false)
  field_defn
end