Skip to content

Commit de3ee11

Browse files
committed
Refactor flow creation and validation services, enhance error handling, and update input types, add more specs
1 parent b656283 commit de3ee11

27 files changed

+440
-419
lines changed
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
# frozen_string_literal: true
2+
3+
module Mutations
4+
module Namespaces
5+
module Projects
6+
module Flows
7+
class Delete < BaseMutation
8+
description 'Deletes a namespace project.'
9+
10+
field :flow, Types::FlowType, null: true, description: 'The deleted flow.'
11+
12+
argument :flow_id, Types::GlobalIdType[::Flow],
13+
description: 'The id of the flow which will be deleted'
14+
15+
def resolve(flow_id:)
16+
flow = SagittariusSchema.object_from_id(flow_id)
17+
18+
if flow.nil?
19+
return { flow: nil,
20+
errors: [create_message_error('Invalid flow')] }
21+
end
22+
23+
::Namespaces::Projects::Flows::DeleteService.new(
24+
current_authentication,
25+
flow
26+
).execute.to_mutation_response(success_key: :flow)
27+
end
28+
end
29+
end
30+
end
31+
end
32+
end

app/graphql/types/input/data_type_identifier_input_type.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ module Input
55
class DataTypeIdentifierInputType < Types::BaseInputObject
66
description 'Input type for data type identifier'
77

8-
argument :data_type_id, Types::GlobalIdType[::DataTypeIdentifier], required: false,
8+
argument :data_type_id, Types::GlobalIdType[::DataType], required: false,
99
description: 'Data type ID'
1010
argument :generic_key, String, required: false,
1111
description: 'Generic key value'

app/graphql/types/input/data_type_type_input.rb

Lines changed: 0 additions & 21 deletions
This file was deleted.

app/graphql/types/input/rules/data_type_rule_contains_key_config_input_type.rb

Lines changed: 0 additions & 16 deletions
This file was deleted.

app/graphql/types/input/rules/data_type_rule_contains_type_config_input_type.rb

Lines changed: 0 additions & 14 deletions
This file was deleted.

app/graphql/types/input/rules/data_type_rule_input_type.rb

Lines changed: 0 additions & 17 deletions
This file was deleted.

app/grpc/concerns/grpc_stream_handler.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ def grpc_stream(method)
2727
end
2828
define_singleton_method("end_#{method}") do |runtime_id|
2929
ActiveRecord::Base.connection.raw_connection
30-
.exec("NOTIFY grpc_streams, '#{self.class},#{method},#{runtime_id},end'")
30+
.exec("NOTIFY grpc_streams, '#{self},#{method},#{runtime_id},end'")
3131
end
3232
end
3333
end

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

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -21,21 +21,25 @@ def execute
2121

2222
transactional do |t|
2323
settings = []
24-
params[:settings].each do |graphql_setting|
25-
setting = FlowSetting.new(flow_setting_id: graphql_setting.flow_setting_id,
26-
object: graphql_setting.object)
27-
next if setting.valid?
28-
29-
t.rollback_and_return! ServiceResponse.error(
30-
message: 'Invalid flow setting',
31-
payload: setting.errors
32-
)
33-
settings << setting
24+
if params.key?(:settings)
25+
params[:settings].each do |graphql_setting|
26+
setting = FlowSetting.new(flow_setting_id: graphql_setting.flow_setting_id,
27+
object: graphql_setting.object)
28+
next if setting.valid?
29+
30+
t.rollback_and_return! ServiceResponse.error(
31+
message: 'Invalid flow setting',
32+
payload: setting.errors
33+
)
34+
settings << setting
35+
end
36+
params[:settings] = settings
3437
end
35-
params[:settings] = settings
3638

37-
node = create_node_function(params[:starting_node], t)
38-
params[:starting_node] = node
39+
if params.key?(:starting_node) && params[:starting_node].is_a?(Types::Input::NodeFunctionInputType)
40+
node = create_node_function(params[:starting_node], t)
41+
params[:starting_node] = node
42+
end
3943

4044
flow = Flow.create(project: namespace_project, **params)
4145
unless flow.persisted?

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

Lines changed: 0 additions & 60 deletions
This file was deleted.
Lines changed: 32 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,20 +5,21 @@ module Projects
55
module Flows
66
module Validation
77
module DataType
8-
class GenericDataTypeIdentifierValidationService
8+
class DataTypeIdentifierValidationService
99
include Code0::ZeroTrack::Loggable
1010
include Sagittarius::Database::Transactional
1111

12-
attr_reader :current_authentication, :flow, :data_type_identifier
12+
attr_reader :current_authentication, :flow, :node, :data_type_identifier
1313

14-
def initialize(current_authentication, flow, data_type_identifier)
14+
def initialize(current_authentication, flow, node, data_type_identifier)
1515
@current_authentication = current_authentication
1616
@flow = flow
17+
@node = node
1718
@data_type_identifier = data_type_identifier
1819
end
1920

2021
def execute
21-
logger.debug("Validating flow_type: #{data_type_identifier.inspect} for flow: #{flow.id}")
22+
logger.debug("Validating data_type_identifier: #{data_type_identifier.id} for flow: #{flow.id}")
2223

2324
transactional do |t|
2425
if data_type_identifier.invalid?
@@ -33,13 +34,6 @@ def execute
3334
)
3435
)
3536
end
36-
if data_type_identifier.data_type.present?
37-
DataTypeValidationService.new(
38-
current_authentication,
39-
flow,
40-
data_type_identifier.data_type
41-
).execute
42-
end
4337
if data_type_identifier.runtime != flow.project.primary_runtime
4438
logger.debug(message: 'Data type identifier runtime mismatch',
4539
primary_runtime: flow.project.primary_runtime.id,
@@ -53,6 +47,33 @@ def execute
5347
)
5448
)
5549
end
50+
51+
if data_type_identifier.generic_key.present?
52+
unless node.runtime_function.generic_keys.include?(data_type_identifier.generic_key)
53+
t.rollback_and_return!(
54+
ServiceResponse.error(
55+
message: "Data type identifier #{data_type_identifier.id} " \
56+
'does not have a generic key which exists in the node function ' \
57+
"#{node.runtime_function.generic_keys}",
58+
payload: :generic_key_not_found
59+
)
60+
)
61+
end
62+
elsif data_type_identifier.generic_type.present?
63+
::NodeFunction::GenericTypeValidationService.new(
64+
current_authentication,
65+
flow,
66+
data_type_identifier.generic_type
67+
).execute
68+
elsif data_type_identifier.data_type.present?
69+
DataTypeValidationService.new(
70+
current_authentication,
71+
flow,
72+
data_type_identifier.data_type
73+
).execute
74+
end
75+
76+
nil
5677
end
5778
end
5879
end

app/services/namespaces/projects/flows/validation/data_type/generic_mapper_data_type_identifier_validation_service.rb

Lines changed: 0 additions & 67 deletions
This file was deleted.

app/services/namespaces/projects/flows/validation/node_function/generic_mapper_validation_service.rb

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,12 @@ def initialize(current_authentication, flow, parameter, generic_mapper)
1919
end
2020

2121
def execute
22-
logger.debug("Validating node function: #{parameter.inspect} for flow: #{flow.id}")
22+
logger.debug("Validating generic mapper: #{generic_mapper.inspect} for flow: #{flow.id}")
2323

2424
transactional do |t|
2525
target = generic_mapper.target
2626

27-
# Validate the target
27+
# Validate the target the identifier gets validated later
2828
unless parameter.generic_type.data_type.generic_keys.has?(target)
2929
t.rollback_and_return!(
3030
ServiceResponse.error(
@@ -35,11 +35,10 @@ def execute
3535
)
3636
end
3737

38-
::DataType::GenericMapperDataTypeIdentifierValidationService.new(
38+
::DataType::DataTypeIdentifierValidationService.new(
3939
current_authentication,
4040
flow,
41-
parameter,
42-
generic_mapper,
41+
parameter.node_function,
4342
generic_mapper.source
4443
).execute
4544
end

0 commit comments

Comments
 (0)