Skip to content

Commit 4038216

Browse files
authored
Merge pull request #846 from code0-tech/821-add-datatype-creation
Add DataType creation for Flow Input and Return Types
2 parents 52d0977 + ee0d678 commit 4038216

8 files changed

Lines changed: 52 additions & 7 deletions

File tree

app/graphql/types/input/flow_input_type.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,10 @@ class FlowInputType < Types::BaseInputObject
1717

1818
argument :type, Types::GlobalIdType[::FlowType], required: true,
1919
description: 'The identifier of the flow type'
20+
21+
argument :input_type, String, required: false, description: 'The input type of the flow'
22+
23+
argument :return_type, String, required: false, description: 'The return type of the flow'
2024
end
2125
end
2226
end

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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,11 +38,12 @@ def execute
3838
flow = Flow.new(
3939
project: namespace_project,
4040
name: flow_input.name,
41-
flow_type: flow_type,
42-
input_type: flow_type.input_type,
43-
return_type: flow_type.return_type
41+
flow_type: flow_type
4442
)
4543

44+
flow_input.send(:overwrite_argument, :input_type, flow_type.input_type) if flow_input.input_type.blank?
45+
flow_input.send(:overwrite_argument, :return_type, flow_type.return_type) if flow_input.return_type.blank?
46+
4647
unless flow.save
4748
t.rollback_and_return! ServiceResponse.error(
4849
message: 'Flow is invalid',

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,8 @@ def update_flow(t)
4848

4949
def update_flow_attributes
5050
flow.name = flow_input.name
51+
flow.input_type = flow_input.input_type
52+
flow.return_type = flow_input.return_type
5153
end
5254

5355
def update_settings(t)

docs/graphql/input_object/flowinput.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,10 @@ Input type for creating or updating a flow
88

99
| Name | Type | Description |
1010
|------|------|-------------|
11+
| `inputType` | [`String`](../scalar/string.md) | The input type of the flow |
1112
| `name` | [`String!`](../scalar/string.md) | The name of the flow |
1213
| `nodes` | [`[NodeFunctionInput!]!`](../input_object/nodefunctioninput.md) | The node functions of the flow |
14+
| `returnType` | [`String`](../scalar/string.md) | The return type of the flow |
1315
| `settings` | [`[FlowSettingInput!]`](../input_object/flowsettinginput.md) | The settings of the flow |
1416
| `startingNodeId` | [`NodeFunctionID`](../scalar/nodefunctionid.md) | The starting node of the flow |
1517
| `type` | [`FlowTypeID!`](../scalar/flowtypeid.md) | The identifier of the flow type |

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

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
#{error_query}
1515
flow {
1616
id
17+
inputType
18+
returnType
1719
startingNodeId
1820
nodes {
1921
count
@@ -59,7 +61,7 @@
5961

6062
let(:runtime) { create(:runtime) }
6163
let(:project) { create(:namespace_project, primary_runtime: runtime) }
62-
let(:flow_type) { create(:flow_type, runtime: runtime) }
64+
let(:flow_type) { create(:flow_type, runtime: runtime, input_type: 'input_type', return_type: 'return_type') }
6365
let(:function_definition) do
6466
rfd = create(:runtime_function_definition, runtime: runtime)
6567
rpd = create(:runtime_parameter_definition, runtime_function_definition: rfd)
@@ -164,6 +166,18 @@
164166
expect(created_flow_id).to be_present
165167
flow = SagittariusSchema.object_from_id(created_flow_id)
166168

169+
expect(
170+
graphql_data_at(:namespaces_projects_flows_create, :flow)
171+
).to match a_graphql_entity_for(
172+
flow,
173+
:input_type,
174+
:return_type,
175+
starting_node_id: flow.starting_node.to_global_id.to_s
176+
)
177+
178+
expect(flow.input_type).to eq(flow_type.input_type)
179+
expect(flow.return_type).to eq(flow_type.return_type)
180+
167181
expect(graphql_data_at(:namespaces_projects_flows_create, :flow, :settings).size).to eq(1)
168182

169183
nodes = graphql_data_at(:namespaces_projects_flows_create, :flow, :nodes, :nodes)

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

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
#{error_query}
1515
flow {
1616
id
17+
inputType
18+
returnType
1719
startingNodeId
1820
nodes {
1921
count
@@ -78,6 +80,8 @@
7880
flowInput: {
7981
name: generate(:flow_name),
8082
type: flow_type.to_global_id.to_s,
83+
inputType: 'updated_input_type',
84+
returnType: 'updated_return_type',
8185
startingNodeId: 'gid://sagittarius/NodeFunction/1000',
8286
settings: {
8387
flowSettingIdentifier: 'key',
@@ -166,6 +170,18 @@
166170
expect(updated_flow_id).to be_present
167171
flow = SagittariusSchema.object_from_id(updated_flow_id)
168172

173+
expect(
174+
graphql_data_at(:namespaces_projects_flows_update, :flow)
175+
).to match a_graphql_entity_for(
176+
flow,
177+
:input_type,
178+
:return_type,
179+
starting_node_id: flow.starting_node.to_global_id.to_s
180+
)
181+
182+
expect(flow.input_type).to eq(input[:flowInput][:inputType])
183+
expect(flow.return_type).to eq(input[:flowInput][:returnType])
184+
169185
expect(graphql_data_at(:namespaces_projects_flows_update, :flow, :settings).size).to eq(1)
170186

171187
nodes = graphql_data_at(:namespaces_projects_flows_update, :flow, :nodes, :nodes)

spec/services/namespaces/projects/flows/create_service_spec.rb

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,11 @@
1212
let(:namespace_project) { create(:namespace_project, primary_runtime: runtime) }
1313

1414
let(:flow_input) do
15-
Struct.new(:settings, :type, :starting_node_id, :nodes, :name).new(
15+
Struct.new(:settings, :type, :input_type, :return_type, :starting_node_id, :nodes, :name).new(
1616
[],
1717
create(:flow_type, runtime: runtime).to_global_id,
18+
'input_type',
19+
'return_type',
1820
'gid://sagittarius/NodeFunction/12345',
1921
[
2022
Struct.new(:id, :function_definition_id, :next_node_id, :parameters).new(
@@ -53,9 +55,11 @@
5355
context 'when starting node is nil' do
5456
let(:current_user) { create(:user) }
5557
let(:flow_input) do
56-
Struct.new(:settings, :type, :starting_node_id, :nodes, :name).new(
58+
Struct.new(:settings, :type, :input_type, :return_type, :starting_node_id, :nodes, :name).new(
5759
[],
5860
create(:flow_type, runtime: runtime).to_global_id,
61+
'input_type',
62+
'return_type',
5963
nil,
6064
[
6165
Struct.new(:id, :function_definition_id, :next_node_id, :parameters).new(

spec/services/namespaces/projects/flows/update_service_spec.rb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,10 @@
2323
end
2424
let(:flow) { create(:flow, project: namespace_project, flow_type: create(:flow_type, runtime: runtime)) }
2525
let(:flow_input) do
26-
Struct.new(:settings, :starting_node_id, :nodes, :name).new(
26+
Struct.new(:settings, :input_type, :return_type, :starting_node_id, :nodes, :name).new(
2727
[],
28+
'input_type',
29+
'return_type',
2830
starting_node.to_global_id,
2931
[
3032
Struct.new(:id, :function_definition_id, :next_node_id, :parameters).new(

0 commit comments

Comments
 (0)