Class: Tasker::GraphQLTypes::WorkflowStepType

Inherits:
BaseObject
  • Object
show all
Defined in:
app/graphql/tasker/graph_ql_types/workflow_step_type.rb

Instance Method Summary collapse

Instance Method Details

#child_countObject



108
109
110
111
112
113
114
115
# File 'app/graphql/tasker/graph_ql_types/workflow_step_type.rb', line 108

def child_count
  # Handle both WorkflowStep objects and Hash objects from mutations
  if object.is_a?(Hash)
    child_step_ids.length
  else
    object.step_dag_relationship&.child_count || 0
  end
end

#child_step_idsObject



72
73
74
75
76
77
78
79
# File 'app/graphql/tasker/graph_ql_types/workflow_step_type.rb', line 72

def child_step_ids
  # Handle both WorkflowStep objects and Hash objects from mutations
  if object.is_a?(Hash)
    object[:children_ids] || []
  else
    object.step_dag_relationship&.child_step_ids_array || []
  end
end

#childrenObject



135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
# File 'app/graphql/tasker/graph_ql_types/workflow_step_type.rb', line 135

def children
  # Handle both WorkflowStep objects and Hash objects from mutations
  child_ids = child_step_ids
  return [] if child_ids.empty?

  # For Hash objects from mutations, we need to fetch the actual WorkflowStep objects
  if object.is_a?(Hash)
    # Use task_id from the hash to scope the query
    task_id = object[:task_id]
    return [] unless task_id

    WorkflowStep.where(task_id: task_id, workflow_step_id: child_ids)
  else
    # Batch load all child steps at once
    WorkflowStep.where(workflow_step_id: child_ids)
  end
end

#is_leaf_stepObject



90
91
92
93
94
95
96
97
# File 'app/graphql/tasker/graph_ql_types/workflow_step_type.rb', line 90

def is_leaf_step
  # Handle both WorkflowStep objects and Hash objects from mutations
  if object.is_a?(Hash)
    child_step_ids.empty?
  else
    object.step_dag_relationship&.is_leaf_step || false
  end
end

#is_root_stepObject



81
82
83
84
85
86
87
88
# File 'app/graphql/tasker/graph_ql_types/workflow_step_type.rb', line 81

def is_root_step
  # Handle both WorkflowStep objects and Hash objects from mutations
  if object.is_a?(Hash)
    parent_step_ids.empty?
  else
    object.step_dag_relationship&.is_root_step || false
  end
end

#parent_countObject



99
100
101
102
103
104
105
106
# File 'app/graphql/tasker/graph_ql_types/workflow_step_type.rb', line 99

def parent_count
  # Handle both WorkflowStep objects and Hash objects from mutations
  if object.is_a?(Hash)
    parent_step_ids.length
  else
    object.step_dag_relationship&.parent_count || 0
  end
end

#parent_step_idsObject

Resolver methods using scenic view optimization



63
64
65
66
67
68
69
70
# File 'app/graphql/tasker/graph_ql_types/workflow_step_type.rb', line 63

def parent_step_ids
  # Handle both WorkflowStep objects and Hash objects from mutations
  if object.is_a?(Hash)
    object[:parents_ids] || []
  else
    object.step_dag_relationship&.parent_step_ids_array || []
  end
end

#parentsObject



117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
# File 'app/graphql/tasker/graph_ql_types/workflow_step_type.rb', line 117

def parents
  # Handle both WorkflowStep objects and Hash objects from mutations
  parent_ids = parent_step_ids
  return [] if parent_ids.empty?

  # For Hash objects from mutations, we need to fetch the actual WorkflowStep objects
  if object.is_a?(Hash)
    # Use task_id from the hash to scope the query
    task_id = object[:task_id]
    return [] unless task_id

    WorkflowStep.where(task_id: task_id, workflow_step_id: parent_ids)
  else
    # Batch load all parent steps at once
    WorkflowStep.where(workflow_step_id: parent_ids)
  end
end