Class: Ecoportal::API::GraphQL::Base::Page::DataField::People

Inherits:
DataField
  • Object
show all
Defined in:
lib/ecoportal/api/graphql/base/page/data_field/people.rb

Instance Method Summary collapse

Instance Method Details

#as_inputObject



28
29
30
31
32
# File 'lib/ecoportal/api/graphql/base/page/data_field/people.rb', line 28

def as_input
  return nil unless dirty?

  { people: { id: id, peopleIds: Array(peopleIds) } }
end

#people_idsObject



6
7
8
9
10
11
12
13
14
15
16
17
# File 'lib/ecoportal/api/graphql/base/page/data_field/people.rb', line 6

def people_ids
  ids = Array(peopleIds)
  return ids unless ids.empty?

  # Fallback: the read fragment populates `peopleIds`, but if a response ever returns it
  # null/empty while the expanded `people { id }` nodes ARE present (a partial / non-
  # $content read), seed from the nodes. The backend write replaces peopleIds wholesale,
  # so a `people_ids << x` append must start from the existing set or it would WIPE the
  # field. Mirrors CrossReference's references.nodes fallback. Read key == write key
  # (peopleIds), so this only widens the read; it never creates phantom-dirty.
  Array(doc['people']).map { |p| p.is_a?(Hash) ? p['id'] : p }.compact
end

#people_ids=(ids) ⇒ Object



19
20
21
# File 'lib/ecoportal/api/graphql/base/page/data_field/people.rb', line 19

def people_ids=(ids)
  doc['peopleIds'] = Array(ids).compact
end

#value=(ids) ⇒ Object

v2 compat: scripts may set via people_ids= or direct assignment



24
25
26
# File 'lib/ecoportal/api/graphql/base/page/data_field/people.rb', line 24

def value=(ids)
  self.people_ids = ids
end