Class: Ecoportal::API::GraphQL::Logic::Input

Inherits:
Logic::BaseModel
  • Object
show all
Defined in:
lib/ecoportal/api/graphql/logic/input.rb

Class Method Summary collapse

Class Method Details

.from_model(model, client_mutation_id: '') ⇒ Hash?

Builds a mutation input hash from a model's diff. Subclasses override this to reshape fields (e.g. array → IdDiffInput).

Parameters:

Returns:

  • (Hash, nil)

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



13
14
15
16
17
18
19
20
# File 'lib/ecoportal/api/graphql/logic/input.rb', line 13

def from_model(model, client_mutation_id: '')
  diff = model.as_update
  return nil if diff.nil?

  diff[:patchVer]         = model.patchVer if model.respond_to?(:patchVer) && !model.patchVer.nil?
  diff[:clientMutationId] = client_mutation_id unless client_mutation_id.to_s.empty?
  diff
end