Class: Tasker::Mutations::UpdateStep

Inherits:
BaseMutation
  • Object
show all
Defined in:
app/graphql/tasker/mutations/update_step.rb

Constant Summary collapse

ALLOWED_UPDATE_FIELDS =
%i[retry_limit inputs].freeze

Instance Method Summary collapse

Instance Method Details

#resolve(task_id:, step_id:, **args) ⇒ Object



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'app/graphql/tasker/mutations/update_step.rb', line 18

def resolve(task_id:, step_id:, **args)
  step = Tasker::WorkflowStep.where({ task_id: task_id, workflow_step_id: step_id }).first
  return { step: nil, errors: 'no such step' } unless step

  params = {}
  args.each do |key, val|
    params[key] = val if key.to_sym.in?(ALLOWED_UPDATE_FIELDS)
  end
  step.update!(params) unless params.empty?

  if step.errors.empty?
    Tasker::WorkflowStepSerializer.new(step).to_hash
  else
    { step: nil, errors: step.errors }
  end
end