Class: Ecoportal::API::GraphQL::Base::Page::DataField::CrossReference
- Inherits:
-
DataField
- Object
- DataField
- Ecoportal::API::GraphQL::Base::Page::DataField::CrossReference
- Defined in:
- lib/ecoportal/api/graphql/base/page/data_field/cross_reference.rb
Overview
Cross-reference field — links to pages in another register.
Instance Method Summary collapse
- #as_input ⇒ Object
-
#dirty? ⇒ Boolean
Dirty only when the effective reference-id SET actually changed.
-
#page_ids ⇒ Object
Current reference ids.
- #page_ids=(ids) ⇒ Object
Instance Method Details
#as_input ⇒ Object
32 33 34 35 36 37 |
# File 'lib/ecoportal/api/graphql/base/page/data_field/cross_reference.rb', line 32 def as_input return nil unless dirty? # CrossReferenceInput uses `referenceIds` (schema-confirmed) — NOT pageIds. { crossReference: { id: id, referenceIds: page_ids } } end |
#dirty? ⇒ Boolean
Dirty only when the effective reference-id SET actually changed.
The field is READ into references.nodes but WRITTEN via pages (page_ids=). The
default key-level leaf diff therefore sees a brand-new pages key the moment any
setter runs and flags a change — even when the set is unchanged. The common offender
is clear on an already-empty field ([] -> []): eco-helpers scripts clear a reference
whenever the source value is blank, which under APIv2 was a no-op but on GraphQL
emitted a phantom referenceIds: [] update. Compare id SETS against the server
baseline (original_doc) instead — restoring v2 parity (empty->empty / same->same
is not dirty).
28 29 30 |
# File 'lib/ecoportal/api/graphql/base/page/data_field/cross_reference.rb', line 28 def dirty? ref_ids_from(doc).sort != ref_ids_from(original_doc).sort end |
#page_ids ⇒ Object
Current reference ids. The GraphQL response carries them under references.nodes
(CommonPageUnion's crossReferenceField), NOT pages — so read from there. After a
page_ids= write, prefer the staged pages value.
10 11 12 |
# File 'lib/ecoportal/api/graphql/base/page/data_field/cross_reference.rb', line 10 def page_ids ref_ids_from(doc) end |
#page_ids=(ids) ⇒ Object
14 15 16 |
# File 'lib/ecoportal/api/graphql/base/page/data_field/cross_reference.rb', line 14 def page_ids=(ids) doc['pages'] = Array(ids).map { |id_val| { 'id' => id_val } } end |