Skip to content

Commit ef27264

Browse files
KnerioCopilot
andcommitted
Remove graphql layer calls from service layer
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> Signed-off-by: Dario Pranjic <96529060+Knerio@users.noreply.github.com>
1 parent 1027be5 commit ef27264

File tree

4 files changed

+47
-10
lines changed

4 files changed

+47
-10
lines changed

app/models/runtime.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ class Runtime < ApplicationRecord
2727
has_many :data_type_identifiers, inverse_of: :runtime
2828
has_many :generic_mappers, inverse_of: :runtime
2929

30+
has_many :runtime_function_definitions, inverse_of: :runtime
31+
3032
has_many :flow_types, inverse_of: :runtime
3133

3234
validates :name, presence: true,

app/services/error_code.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,8 @@ def self.error_codes
8080
no_datatype_identifier_for_generic_key: { description: 'No data type identifier could be found for the given generic key' },
8181
invalid_generic_mapper: { description: 'The generic mapper is invalid because of active model errors' },
8282
invalid_data_type: { description: 'The data type is invalid because of active model errors' },
83+
data_type_identifier_not_found: { description: 'The data type identifier with the given identifier was not found' },
84+
data_type_not_found: { description: 'The data type with the given identifier was not found' },
8385
invalid_flow_type: { description: 'The flow type is invalid because of active model errors' },
8486

8587
primary_level_not_found: { description: '', deprecation_reason: 'Outdated concept' },

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

Lines changed: 41 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,13 @@ def execute
1919
return ServiceResponse.error(message: 'Missing permission', error_code: :missing_permission)
2020
end
2121

22+
if namespace_project.primary_runtime.nil?
23+
return ServiceResponse.error(
24+
message: 'Project has no primary runtime',
25+
error_code: :no_primary_runtime
26+
)
27+
end
28+
2229
transactional do |t|
2330
settings = []
2431
if params.key?(:flow_settings)
@@ -83,7 +90,9 @@ def execute
8390
def create_node_function(node_function_id, input_nodes, t)
8491
node_function = input_nodes.find { |n| n.id == node_function_id }
8592

86-
runtime_function_definition = SagittariusSchema.object_from_id(node_function.runtime_function_id)
93+
runtime_function_definition = namespace_project.primary_runtime.runtime_function_definitions.find_by(
94+
id: node_function.runtime_function_id.model_id
95+
)
8796
if runtime_function_definition.nil?
8897
t.rollback_and_return! ServiceResponse.error(
8998
message: 'Invalid runtime function id',
@@ -93,7 +102,9 @@ def create_node_function(node_function_id, input_nodes, t)
93102

94103
params = []
95104
node_function.parameters.each do |parameter|
96-
runtime_parameter = SagittariusSchema.object_from_id(parameter.runtime_parameter_definition_id)
105+
runtime_parameter = runtime_function_definition.parameters.find_by(
106+
id: parameter.runtime_parameter_definition_id.model_id
107+
)
97108
if runtime_parameter.nil?
98109
t.rollback_and_return! ServiceResponse.error(
99110
message: 'Invalid runtime parameter id',
@@ -116,11 +127,12 @@ def create_node_function(node_function_id, input_nodes, t)
116127
next
117128
end
118129

119-
reference_value = SagittariusSchema.object_from_id(
120-
parameter.value.reference_value.node_function_id
130+
referenced_node = NodeFunction.joins(:runtime_function).find_by(
131+
id: parameter.value.reference_value.node_function_id.model_id,
132+
runtime_function_definitions: { runtime_id: namespace_project.primary_runtime.id }
121133
)
122134

123-
if reference_value.nil?
135+
if referenced_node.nil?
124136
t.rollback_and_return! ServiceResponse.error(
125137
message: 'Referenced node function not found',
126138
error_code: :referenced_value_not_found
@@ -130,8 +142,8 @@ def create_node_function(node_function_id, input_nodes, t)
130142
params << NodeParameter.create(
131143
runtime_parameter: runtime_parameter,
132144
reference_value: ReferenceValue.create(
133-
node_function: reference_value,
134-
data_type_identifier: get_data_type_identifier(parameter.value.reference_value.data_type_identifier),
145+
node_function: referenced_node,
146+
data_type_identifier: get_data_type_identifier(parameter.value.reference_value.data_type_identifier, t),
135147
depth: parameter.value.reference_value.depth,
136148
node: parameter.value.reference_value.node,
137149
scope: parameter.value.reference_value.scope,
@@ -158,11 +170,21 @@ def create_node_function(node_function_id, input_nodes, t)
158170

159171
private
160172

161-
def get_data_type_identifier(identifier)
173+
def get_data_type_identifier(identifier, t)
162174
return DataTypeIdentifier.create(generic_key: identifier.generic_key) if identifier.generic_key.present?
163175

164176
if identifier.generic_type.present?
165-
data_type = SagittariusSchema.object_from_id(identifier.generic_type.data_type_id)
177+
data_type = namespace_project.primary_runtime.data_types.find_by(
178+
id: identifier.generic_type.data_type_id.model_id
179+
)
180+
181+
if data_type.nil?
182+
t.rollback_and_return! ServiceResponse.error(
183+
message: 'Data type not found',
184+
error_code: :data_type_not_found
185+
)
186+
end
187+
166188
mappers = identifier.generic_type.mappers.map do |mapper|
167189
GenericMapper.create(
168190
generic_mapper_id: mapper.generic_mapper_id,
@@ -175,7 +197,16 @@ def get_data_type_identifier(identifier)
175197

176198
return if identifier.data_type_id.blank?
177199

178-
DataTypeIdentifier.create(data_type: SagittariusSchema.object_from_id(identifier.data_type_id))
200+
data_type = namespace_project.primary_runtime.data_types.find_by(id: identifier.data_type_id.model_id)
201+
202+
if data_type.nil?
203+
t.rollback_and_return! ServiceResponse.error(
204+
message: 'Data type not found',
205+
error_code: :data_type_not_found
206+
)
207+
end
208+
209+
DataTypeIdentifier.create(data_type: data_type)
179210
end
180211
end
181212
end

docs/graphql/enum/errorcodeenum.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ Represents the available error responses
1111
| `CANNOT_MODIFY_OWN_ADMIN` | Users cannot modify their own admin status |
1212
| `CANNOT_REMOVE_LAST_ADMINISTRATOR` | This action would remove the last administrator |
1313
| `CANNOT_REMOVE_LAST_ADMIN_ABILITY` | This action would remove the last administrative ability |
14+
| `DATA_TYPE_IDENTIFIER_NOT_FOUND` | The data type identifier with the given identifier was not found |
15+
| `DATA_TYPE_NOT_FOUND` | The data type with the given identifier was not found |
1416
| `EMAIL_VERIFICATION_SEND_FAILED` | Failed to send the email verification |
1517
| `EXTERNAL_IDENTITY_DOES_NOT_EXIST` | This external identity does not exist |
1618
| `FAILED_TO_INVALIDATE_OLD_BACKUP_CODES` | The old backup codes could not be deleted |

0 commit comments

Comments
 (0)