Module: Ecoportal::API::GraphQL::Logic::Input::FullArrayFields

Included in:
Input::Action::Update
Defined in:
lib/ecoportal/api/graphql/logic/input.rb

Overview

Declarative FULL-ARRAY macro for id-list fields that the schema exposes as a plain [ID!] on the update mutation (NOT IdDiffInput). The server expects the COMPLETE current array, replacing the stored value wholesale — there is no additions/removals delta shape. This is the counterpart to IdDiffFields.

Mixed into any Input class via extend, exactly like IdDiffFields. Data-model Input classes call extend Logic::Input::FullArrayFields explicitly.

Usage:

class Update < Base::Action
extend Logic::Input::FullArrayFields
full_array_fields :assignedPersonMemberIds, :locationIds, :fileContainerIds
end

It installs (or augments) a from_model that, for each declared field, emits the FULL current array taken DIRECTLY from the READ model's doc[key] whenever it differs from original_doc[key]. A field is omitted when unchanged. The value is read directly (NOT via the cascaded DiffService) because these array fields are dropped from the flat diff and the read model is root!.

Schema evidence (live introspection 20260605, UpdateActionInput):

assignedPersonMemberIds : [ID!]
locationIds             : [ID!]
fileContainerIds        : [ID!]

None are IdDiffInput — hence full-array, not delta.

Instance Method Summary collapse

Instance Method Details

#from_model(model, **kargs) ⇒ Hash?

Reshaping from_model: base diff (via Ecoportal::API::GraphQL::Logic::Input.from_model) + full arrays.

Parameters:

Returns:

  • (Hash, nil)

    the mutation input hash, or nil when there are no changes.



129
130
131
132
# File 'lib/ecoportal/api/graphql/logic/input.rb', line 129

def from_model(model, **kargs)
  diff = Logic::Input.from_model(model, **kargs)
  merge_full_arrays(model, diff)
end

#full_array_fields(*fields) ⇒ void

This method returns an undefined value.

Declares the id-list fields that must be emitted as their COMPLETE current array.

Parameters:

  • fields (Array<Symbol>)

    field names (as they appear in the read model's doc).



103
104
105
# File 'lib/ecoportal/api/graphql/logic/input.rb', line 103

def full_array_fields(*fields)
  full_array_fields_list.concat(fields.flatten.map(&:to_sym)).uniq!
end

#full_array_fields_listArray<Symbol>

Returns the fields declared for full-array emission on this class.

Returns:

  • (Array<Symbol>)

    the fields declared for full-array emission on this class.



96
97
98
# File 'lib/ecoportal/api/graphql/logic/input.rb', line 96

def full_array_fields_list
  @full_array_fields_list ||= []
end

#merge_full_arrays(model, diff) ⇒ Hash?

Emits the full current array for each changed declared field and merges it into diff.

Parameters:

  • model (Common::GraphQL::Model)

    the subject (read) model.

  • diff (Hash, nil)

    the base mutation input hash to augment (may be nil).

Returns:

  • (Hash, nil)

    diff with per-field full arrays merged in, or the original value when nothing changed.



112
113
114
115
116
117
118
119
120
121
122
123
124
# File 'lib/ecoportal/api/graphql/logic/input.rb', line 112

def merge_full_arrays(model, diff)
  full_array_fields_list.each do |field|
    key      = field.to_s
    current  = Array(model.doc[key])
    original = Array(model.original_doc[key])
    next if current == original

    diff        ||= {}
    diff[:id]   ||= model.id if model.respond_to?(:id)
    diff[field]   = current
  end
  diff
end