Skip to content
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions app/graphql/mutations/namespaces/projects/flows/update.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# frozen_string_literal: true

module Mutations
module Namespaces
module Projects
module Flows
class Update < BaseMutation
description 'Update an existing flow.'

field :flow, Types::FlowType, null: true, description: 'The updated flow.'

argument :flow_id, Types::GlobalIdType[Flow],
required: true, description: 'The ID of the flow to update'

argument :flow_input, Types::Input::FlowInputType, description: 'The updated flow', required: true

def resolve(flow_id:, flow_input:, **_params)
flow = SagittariusSchema.object_from_id(flow_id)

return { errors: [create_error(:flow_not_found, 'Flow does not exist')] } if flow.nil?

flow_type = SagittariusSchema.object_from_id(flow_input.type)
return { errors: [create_error(:flow_type_not_found, 'Invalid flow type id')] } if flow_type.nil?

::Namespaces::Projects::Flows::UpdateService.new(
current_authentication,
flow,
flow_input
).execute.to_mutation_response(success_key: :flow)
end
end
end
end
end
end
3 changes: 2 additions & 1 deletion app/graphql/types/mutation_type.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,11 @@ class MutationType < Types::BaseObject
mount_mutation Mutations::Namespaces::Members::Invite
mount_mutation Mutations::Namespaces::Projects::AssignRuntimes
mount_mutation Mutations::Namespaces::Projects::Create
mount_mutation Mutations::Namespaces::Projects::Update
mount_mutation Mutations::Namespaces::Projects::Delete
mount_mutation Mutations::Namespaces::Projects::Update
mount_mutation Mutations::Namespaces::Projects::Flows::Create
mount_mutation Mutations::Namespaces::Projects::Flows::Delete
mount_mutation Mutations::Namespaces::Projects::Flows::Update
mount_mutation Mutations::Namespaces::Roles::AssignAbilities
mount_mutation Mutations::Namespaces::Roles::AssignProjects
mount_mutation Mutations::Namespaces::Roles::Create
Expand Down
4 changes: 4 additions & 0 deletions app/services/error_code.rb
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,10 @@ def self.error_codes
data_type_not_found: { description: 'The data type with the given identifier was not found' },
invalid_flow_type: { description: 'The flow type is invalid because of active model errors' },
no_data_type_for_identifier: { description: 'No data type could be found for the given identifier' },
node_not_found: { description: 'The node with this id does not exist' },
function_value_not_found: { description: 'The id for the function value node does not exist' },
invalid_node_parameter: { description: 'The node parameter is invalid' },
invalid_node_function: { description: 'The node function is invalid' },

primary_level_not_found: { description: '', deprecation_reason: 'Outdated concept' },
secondary_level_not_found: { description: '', deprecation_reason: 'Outdated concept' },
Expand Down
50 changes: 7 additions & 43 deletions app/services/namespaces/projects/flows/create_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ module Projects
module Flows
class CreateService
include Sagittarius::Database::Transactional
include FlowServiceHelper

attr_reader :current_authentication, :namespace_project, :params

Expand Down Expand Up @@ -122,7 +123,7 @@ def create_node_function(node_function_id, input_nodes, t)
if parameter.value.function_value.present?
params << NodeParameter.create(
runtime_parameter: runtime_parameter,
function_value: create_node_function(parameter.value.function_value, t)
function_value: create_node_function(parameter.value.function_value, input_nodes, t)
)
next
end
Expand All @@ -143,7 +144,11 @@ def create_node_function(node_function_id, input_nodes, t)
runtime_parameter: runtime_parameter,
reference_value: ReferenceValue.create(
node_function: referenced_node,
data_type_identifier: get_data_type_identifier(parameter.value.reference_value.data_type_identifier, t),
data_type_identifier: get_data_type_identifier(
namespace_project.primary_runtime,
parameter.value.reference_value.data_type_identifier,
t
),
depth: parameter.value.reference_value.depth,
node: parameter.value.reference_value.node,
scope: parameter.value.reference_value.scope,
Expand All @@ -167,47 +172,6 @@ def create_node_function(node_function_id, input_nodes, t)
node_parameters: params
)
end

private

def get_data_type_identifier(identifier, t)
return DataTypeIdentifier.create(generic_key: identifier.generic_key) if identifier.generic_key.present?

if identifier.generic_type.present?
data_type = namespace_project.primary_runtime.data_types.find_by(
id: identifier.generic_type.data_type_id.model_id
)

if data_type.nil?
t.rollback_and_return! ServiceResponse.error(
message: 'Data type not found',
error_code: :data_type_not_found
)
end

mappers = identifier.generic_type.mappers.map do |mapper|
GenericMapper.create(
generic_mapper_id: mapper.generic_mapper_id,
source: mapper.source,
target: mapper.target
)
end
return DataTypeIdentifier.create(generic_type: GenericType.create(data_type: data_type, mappers: mappers))
end

return if identifier.data_type_id.blank?

data_type = namespace_project.primary_runtime.data_types.find_by(id: identifier.data_type_id.model_id)

if data_type.nil?
t.rollback_and_return! ServiceResponse.error(
message: 'Data type not found',
error_code: :data_type_not_found
)
end

DataTypeIdentifier.create(data_type: data_type)
end
end
end
end
Expand Down
52 changes: 52 additions & 0 deletions app/services/namespaces/projects/flows/flow_service_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
# frozen_string_literal: true

module Namespaces
module Projects
module Flows
module FlowServiceHelper
def get_data_type_identifier(runtime, identifier, t)
if identifier.generic_key.present?
return DataTypeIdentifier.find_or_create_by(runtime: runtime,
generic_key: identifier.generic_key)
end

if identifier.generic_type.present?
data_type = namespace_project.primary_runtime.data_types.find_by(
id: identifier.generic_type.data_type_id.model_id
)

if data_type.nil?
t.rollback_and_return! ServiceResponse.error(
message: 'Data type not found',
error_code: :data_type_not_found
)
end

mappers = identifier.generic_type.mappers.map do |mapper|
GenericMapper.find_or_create_by(
runtime: runtime,
generic_mapper_id: mapper.generic_mapper_id,
source: mapper.source,
target: mapper.target
)
end
generic_type = GenericType.joins(:generic_mappers).find_or_create_by(data_type: data_type,
generic_mappers: mappers)
return DataTypeIdentifier.find_or_create_by(runtime: runtime, generic_type: generic_type)
end

data_type = namespace_project.primary_runtime.data_types.find_by(id: identifier.data_type_id.model_id)

if data_type.nil?
t.rollback_and_return! ServiceResponse.error(
message: 'Data type not found',
error_code: :data_type_not_found
)
end

DataTypeIdentifier.find_or_create_by(runtime: runtime, data_type: data_type)
end
end
end
end
end
Loading