Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion app/graphql/mutations/namespaces/projects/flows/create.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@ def resolve(project_id:, flow:, **_params)
current_authentication,
namespace_project: project,
flow_type: flow_type,
starting_node: flow.starting_node,
starting_node_id: flow.starting_node_id,
nodes: flow.nodes,
flow_settings: flow.settings || [],
name: flow.name
).execute.to_mutation_response(success_key: :flow)
Expand Down
8 changes: 6 additions & 2 deletions app/graphql/types/input/flow_input_type.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,12 @@ class FlowInputType < Types::BaseInputObject

argument :settings, [Types::Input::FlowSettingInputType], required: false,
description: 'The settings of the flow'
argument :starting_node, Types::Input::NodeFunctionInputType, required: true,
description: 'The starting node of the flow'
argument :starting_node_id, Types::GlobalIdType[::NodeFunction], required: true,
description: 'The starting node of the flow'

argument :nodes, [Types::Input::NodeFunctionInputType], required: true,
description: 'The node functions of the flow'

argument :type, Types::GlobalIdType[::FlowType], required: true,
description: 'The identifier of the flow type'
end
Expand Down
7 changes: 5 additions & 2 deletions app/graphql/types/input/node_function_input_type.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,14 @@ module Input
class NodeFunctionInputType < Types::BaseInputObject
description 'Input type for a Node Function'

argument :id, Types::GlobalIdType[::NodeFunction],
required: true, description: 'The identifier of the Node Function used to create/update the flow'

argument :runtime_function_id, Types::GlobalIdType[::RuntimeFunctionDefinition],
required: true, description: 'The identifier of the Runtime Function Definition'

argument :next_node, Types::Input::NodeFunctionInputType, required: false,
description: 'The next Node Function in the flow'
argument :next_node_id, Types::GlobalIdType[::NodeFunction], required: false,
description: 'The next Node Function in the flow'
argument :parameters, [Types::Input::NodeParameterInputType], required: true,
description: 'The parameters of the Node Function'
end
Expand Down
17 changes: 11 additions & 6 deletions app/services/namespaces/projects/flows/create_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,11 @@ def execute
params[:flow_settings] = settings
end

if params.key?(:starting_node) && params[:starting_node].is_a?(Types::Input::NodeFunctionInputType)
node = create_node_function(params[:starting_node], t)
params[:starting_node] = node
if params.key?(:starting_node_id)
params[:starting_node] = create_node_function(params[:starting_node_id], params[:nodes], t)

params.delete(:starting_node_id)
params.delete(:nodes)
end

flow = Flow.create(project: namespace_project, **params)
Expand Down Expand Up @@ -76,7 +78,9 @@ def execute
end
end

def create_node_function(node_function, t)
def create_node_function(node_function_id, input_nodes, t)
node_function = input_nodes.find { |n| n.id == node_function_id }

runtime_function_definition = SagittariusSchema.object_from_id(node_function.runtime_function_id)
if runtime_function_definition.nil?
t.rollback_and_return! ServiceResponse.error(
Expand Down Expand Up @@ -139,8 +143,9 @@ def create_node_function(node_function, t)
)
end

next_node = nil
next_node = create_node_function(node_function.next_node, t) if node_function.next_node.present?
next_node = if node_function.next_node_id.present?
create_node_function(node_function.next_node_id, input_nodes, t)
end

NodeFunction.create(
next_node: next_node,
Expand Down
3 changes: 2 additions & 1 deletion docs/graphql/input_object/flowinput.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ Input type for creating or updating a flow
| Name | Type | Description |
|------|------|-------------|
| `name` | [`String!`](../scalar/string.md) | The name of the flow |
| `nodes` | [`[NodeFunctionInput!]!`](../input_object/nodefunctioninput.md) | The node functions of the flow |
| `settings` | [`[FlowSettingInput!]`](../input_object/flowsettinginput.md) | The settings of the flow |
| `startingNode` | [`NodeFunctionInput!`](../input_object/nodefunctioninput.md) | The starting node of the flow |
| `startingNodeId` | [`NodeFunctionID!`](../scalar/nodefunctionid.md) | The starting node of the flow |
| `type` | [`FlowTypeID!`](../scalar/flowtypeid.md) | The identifier of the flow type |
3 changes: 2 additions & 1 deletion docs/graphql/input_object/nodefunctioninput.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ Input type for a Node Function

| Name | Type | Description |
|------|------|-------------|
| `nextNode` | [`NodeFunctionInput`](../input_object/nodefunctioninput.md) | The next Node Function in the flow |
| `id` | [`NodeFunctionID!`](../scalar/nodefunctionid.md) | The identifier of the Node Function used to create/update the flow |
| `nextNodeId` | [`NodeFunctionID`](../scalar/nodefunctionid.md) | The next Node Function in the flow |
| `parameters` | [`[NodeParameterInput!]!`](../input_object/nodeparameterinput.md) | The parameters of the Node Function |
| `runtimeFunctionId` | [`RuntimeFunctionDefinitionID!`](../scalar/runtimefunctiondefinitionid.md) | The identifier of the Runtime Function Definition |
Original file line number Diff line number Diff line change
Expand Up @@ -59,21 +59,36 @@
flow: {
name: generate(:flow_name),
type: flow_type.to_global_id.to_s,
startingNodeId: 'gid://sagittarius/NodeFunction/999',
settings: {
flowSettingId: 'key',
object: {
'key' => 'value',
},
},
startingNode: {
runtimeFunctionId: runtime_function.to_global_id.to_s,
parameters: [
runtimeParameterDefinitionId: runtime_function.parameters.first.to_global_id.to_s,
value: {
literalValue: 'test_value',
}
],
},
nodes: [
{
id: 'gid://sagittarius/NodeFunction/999',
runtimeFunctionId: runtime_function.to_global_id.to_s,
parameters: [
runtimeParameterDefinitionId: runtime_function.parameters.first.to_global_id.to_s,
value: {
literalValue: 'test_value',
}
],
nextNodeId: 'gid://sagittarius/NodeFunction/991',
},
{
id: 'gid://sagittarius/NodeFunction/991',
runtimeFunctionId: runtime_function.to_global_id.to_s,
parameters: [
runtimeParameterDefinitionId: runtime_function.parameters.first.to_global_id.to_s,
value: {
literalValue: 'test_value2',
}
],
}
],
},
}
end
Expand Down Expand Up @@ -108,6 +123,7 @@

expect(flow).to be_present
expect(project.flows).to include(flow)
expect(flow.collect_node_functions.count).to eq(2)

is_expected.to create_audit_event(
:flow_created,
Expand Down