Skip to content

Commit 4e14e2a

Browse files
authored
Merge pull request #702 from code0-tech/658-nodefunctioninput-should-contain-the-nextnodeid-instead-of-the-full-nodefunction
NodeFunctionInput contains nextNodeId instead of the whole node
2 parents cab69de + 4d5564c commit 4e14e2a

File tree

7 files changed

+53
-22
lines changed

7 files changed

+53
-22
lines changed

app/graphql/mutations/namespaces/projects/flows/create.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,8 @@ def resolve(project_id:, flow:, **_params)
3636
current_authentication,
3737
namespace_project: project,
3838
flow_type: flow_type,
39-
starting_node: flow.starting_node,
39+
starting_node_id: flow.starting_node_id,
40+
nodes: flow.nodes,
4041
flow_settings: flow.settings || [],
4142
name: flow.name
4243
).execute.to_mutation_response(success_key: :flow)

app/graphql/types/input/flow_input_type.rb

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,12 @@ class FlowInputType < Types::BaseInputObject
99

1010
argument :settings, [Types::Input::FlowSettingInputType], required: false,
1111
description: 'The settings of the flow'
12-
argument :starting_node, Types::Input::NodeFunctionInputType, required: true,
13-
description: 'The starting node of the flow'
12+
argument :starting_node_id, Types::GlobalIdType[::NodeFunction], required: true,
13+
description: 'The starting node of the flow'
14+
15+
argument :nodes, [Types::Input::NodeFunctionInputType], required: true,
16+
description: 'The node functions of the flow'
17+
1418
argument :type, Types::GlobalIdType[::FlowType], required: true,
1519
description: 'The identifier of the flow type'
1620
end

app/graphql/types/input/node_function_input_type.rb

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,14 @@ module Input
55
class NodeFunctionInputType < Types::BaseInputObject
66
description 'Input type for a Node Function'
77

8+
argument :id, Types::GlobalIdType[::NodeFunction],
9+
required: true, description: 'The identifier of the Node Function used to create/update the flow'
10+
811
argument :runtime_function_id, Types::GlobalIdType[::RuntimeFunctionDefinition],
912
required: true, description: 'The identifier of the Runtime Function Definition'
1013

11-
argument :next_node, Types::Input::NodeFunctionInputType, required: false,
12-
description: 'The next Node Function in the flow'
14+
argument :next_node_id, Types::GlobalIdType[::NodeFunction], required: false,
15+
description: 'The next Node Function in the flow'
1316
argument :parameters, [Types::Input::NodeParameterInputType], required: true,
1417
description: 'The parameters of the Node Function'
1518
end

app/services/namespaces/projects/flows/create_service.rb

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,11 @@ def execute
3838
params[:flow_settings] = settings
3939
end
4040

41-
if params.key?(:starting_node) && params[:starting_node].is_a?(Types::Input::NodeFunctionInputType)
42-
node = create_node_function(params[:starting_node], t)
43-
params[:starting_node] = node
41+
if params.key?(:starting_node_id)
42+
params[:starting_node] = create_node_function(params[:starting_node_id], params[:nodes], t)
43+
44+
params.delete(:starting_node_id)
45+
params.delete(:nodes)
4446
end
4547

4648
flow = Flow.create(project: namespace_project, **params)
@@ -76,7 +78,9 @@ def execute
7678
end
7779
end
7880

79-
def create_node_function(node_function, t)
81+
def create_node_function(node_function_id, input_nodes, t)
82+
node_function = input_nodes.find { |n| n.id == node_function_id }
83+
8084
runtime_function_definition = SagittariusSchema.object_from_id(node_function.runtime_function_id)
8185
if runtime_function_definition.nil?
8286
t.rollback_and_return! ServiceResponse.error(
@@ -139,8 +143,9 @@ def create_node_function(node_function, t)
139143
)
140144
end
141145

142-
next_node = nil
143-
next_node = create_node_function(node_function.next_node, t) if node_function.next_node.present?
146+
next_node = if node_function.next_node_id.present?
147+
create_node_function(node_function.next_node_id, input_nodes, t)
148+
end
144149

145150
NodeFunction.create(
146151
next_node: next_node,

docs/graphql/input_object/flowinput.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ Input type for creating or updating a flow
99
| Name | Type | Description |
1010
|------|------|-------------|
1111
| `name` | [`String!`](../scalar/string.md) | The name of the flow |
12+
| `nodes` | [`[NodeFunctionInput!]!`](../input_object/nodefunctioninput.md) | The node functions of the flow |
1213
| `settings` | [`[FlowSettingInput!]`](../input_object/flowsettinginput.md) | The settings of the flow |
13-
| `startingNode` | [`NodeFunctionInput!`](../input_object/nodefunctioninput.md) | The starting node of the flow |
14+
| `startingNodeId` | [`NodeFunctionID!`](../scalar/nodefunctionid.md) | The starting node of the flow |
1415
| `type` | [`FlowTypeID!`](../scalar/flowtypeid.md) | The identifier of the flow type |

docs/graphql/input_object/nodefunctioninput.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ Input type for a Node Function
88

99
| Name | Type | Description |
1010
|------|------|-------------|
11-
| `nextNode` | [`NodeFunctionInput`](../input_object/nodefunctioninput.md) | The next Node Function in the flow |
11+
| `id` | [`NodeFunctionID!`](../scalar/nodefunctionid.md) | The identifier of the Node Function used to create/update the flow |
12+
| `nextNodeId` | [`NodeFunctionID`](../scalar/nodefunctionid.md) | The next Node Function in the flow |
1213
| `parameters` | [`[NodeParameterInput!]!`](../input_object/nodeparameterinput.md) | The parameters of the Node Function |
1314
| `runtimeFunctionId` | [`RuntimeFunctionDefinitionID!`](../scalar/runtimefunctiondefinitionid.md) | The identifier of the Runtime Function Definition |

spec/requests/graphql/mutation/namespace/projects/flows/create_mutation_spec.rb

Lines changed: 25 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -59,21 +59,36 @@
5959
flow: {
6060
name: generate(:flow_name),
6161
type: flow_type.to_global_id.to_s,
62+
startingNodeId: 'gid://sagittarius/NodeFunction/999',
6263
settings: {
6364
flowSettingId: 'key',
6465
object: {
6566
'key' => 'value',
6667
},
6768
},
68-
startingNode: {
69-
runtimeFunctionId: runtime_function.to_global_id.to_s,
70-
parameters: [
71-
runtimeParameterDefinitionId: runtime_function.parameters.first.to_global_id.to_s,
72-
value: {
73-
literalValue: 'test_value',
74-
}
75-
],
76-
},
69+
nodes: [
70+
{
71+
id: 'gid://sagittarius/NodeFunction/999',
72+
runtimeFunctionId: runtime_function.to_global_id.to_s,
73+
parameters: [
74+
runtimeParameterDefinitionId: runtime_function.parameters.first.to_global_id.to_s,
75+
value: {
76+
literalValue: 'test_value',
77+
}
78+
],
79+
nextNodeId: 'gid://sagittarius/NodeFunction/991',
80+
},
81+
{
82+
id: 'gid://sagittarius/NodeFunction/991',
83+
runtimeFunctionId: runtime_function.to_global_id.to_s,
84+
parameters: [
85+
runtimeParameterDefinitionId: runtime_function.parameters.first.to_global_id.to_s,
86+
value: {
87+
literalValue: 'test_value2',
88+
}
89+
],
90+
}
91+
],
7792
},
7893
}
7994
end
@@ -108,6 +123,7 @@
108123

109124
expect(flow).to be_present
110125
expect(project.flows).to include(flow)
126+
expect(flow.collect_node_functions.count).to eq(2)
111127

112128
is_expected.to create_audit_event(
113129
:flow_created,

0 commit comments

Comments
 (0)