From 65a41bab207955a34e29e023c783778cf5065a2a Mon Sep 17 00:00:00 2001 From: Dario Pranjic Date: Tue, 18 Nov 2025 17:48:19 +0100 Subject: [PATCH 1/2] NodeFunctionInput contains nextNodeId instead of the whole node --- .../namespaces/projects/flows/create.rb | 3 +- app/graphql/types/input/flow_input_type.rb | 8 +++-- .../types/input/node_function_input_type.rb | 7 ++-- .../projects/flows/create_service.rb | 17 ++++++---- docs/graphql/input_object/flowinput.md | 3 +- .../graphql/input_object/nodefunctioninput.md | 3 +- .../projects/flows/create_mutation_spec.rb | 34 ++++++++++++++----- 7 files changed, 53 insertions(+), 22 deletions(-) diff --git a/app/graphql/mutations/namespaces/projects/flows/create.rb b/app/graphql/mutations/namespaces/projects/flows/create.rb index 44396e38..5b438fcd 100644 --- a/app/graphql/mutations/namespaces/projects/flows/create.rb +++ b/app/graphql/mutations/namespaces/projects/flows/create.rb @@ -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) diff --git a/app/graphql/types/input/flow_input_type.rb b/app/graphql/types/input/flow_input_type.rb index dda11ef3..2828cb66 100644 --- a/app/graphql/types/input/flow_input_type.rb +++ b/app/graphql/types/input/flow_input_type.rb @@ -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 diff --git a/app/graphql/types/input/node_function_input_type.rb b/app/graphql/types/input/node_function_input_type.rb index 1c9c51df..071ae0b8 100644 --- a/app/graphql/types/input/node_function_input_type.rb +++ b/app/graphql/types/input/node_function_input_type.rb @@ -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 diff --git a/app/services/namespaces/projects/flows/create_service.rb b/app/services/namespaces/projects/flows/create_service.rb index f5a177bd..255e6284 100644 --- a/app/services/namespaces/projects/flows/create_service.rb +++ b/app/services/namespaces/projects/flows/create_service.rb @@ -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] = p 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) @@ -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( @@ -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, diff --git a/docs/graphql/input_object/flowinput.md b/docs/graphql/input_object/flowinput.md index c31f3398..98c8ae41 100644 --- a/docs/graphql/input_object/flowinput.md +++ b/docs/graphql/input_object/flowinput.md @@ -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 | diff --git a/docs/graphql/input_object/nodefunctioninput.md b/docs/graphql/input_object/nodefunctioninput.md index 4c499591..240a9707 100644 --- a/docs/graphql/input_object/nodefunctioninput.md +++ b/docs/graphql/input_object/nodefunctioninput.md @@ -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 | diff --git a/spec/requests/graphql/mutation/namespace/projects/flows/create_mutation_spec.rb b/spec/requests/graphql/mutation/namespace/projects/flows/create_mutation_spec.rb index b350520b..5b60c2cc 100644 --- a/spec/requests/graphql/mutation/namespace/projects/flows/create_mutation_spec.rb +++ b/spec/requests/graphql/mutation/namespace/projects/flows/create_mutation_spec.rb @@ -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 @@ -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, From 4d5564cbb93cf588c191e973920fb7d666aa1c1d Mon Sep 17 00:00:00 2001 From: Dario Pranjic <96529060+Knerio@users.noreply.github.com> Date: Tue, 18 Nov 2025 20:42:12 +0100 Subject: [PATCH 2/2] Update app/services/namespaces/projects/flows/create_service.rb Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> Signed-off-by: Dario Pranjic <96529060+Knerio@users.noreply.github.com> --- app/services/namespaces/projects/flows/create_service.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/services/namespaces/projects/flows/create_service.rb b/app/services/namespaces/projects/flows/create_service.rb index 255e6284..3cfdec17 100644 --- a/app/services/namespaces/projects/flows/create_service.rb +++ b/app/services/namespaces/projects/flows/create_service.rb @@ -39,7 +39,7 @@ def execute end if params.key?(:starting_node_id) - params[:starting_node] = p create_node_function(params[:starting_node_id], params[:nodes], t) + params[:starting_node] = create_node_function(params[:starting_node_id], params[:nodes], t) params.delete(:starting_node_id) params.delete(:nodes)