Skip to content
Open
Show file tree
Hide file tree
Changes from all 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
4 changes: 4 additions & 0 deletions app/graphql/types/flow_setting_type.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ class FlowSettingType < Types::BaseObject

authorize :read_flow

field :cast, String,
null: true,
description: 'The cast applied to the flow setting'

field :flow_setting_identifier, String,
null: false,
method: :flow_setting_id,
Expand Down
20 changes: 20 additions & 0 deletions app/graphql/types/flow_sub_flow_setting_type.rb
Comment thread
Taucher2003 marked this conversation as resolved.
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# frozen_string_literal: true

module Types
class FlowSubFlowSettingType < Types::BaseObject
description 'Represents a sub-flow setting.'

field :default_value, GraphQL::Types::JSON,
null: true,
description: 'The default value of the sub-flow setting.'
field :hidden, Boolean,
null: true,
description: 'Whether the sub-flow setting is hidden.'
field :identifier, String,
null: false,
description: 'The identifier of the sub-flow setting.'
field :optional, Boolean,
null: true,
description: 'Whether the sub-flow setting is optional.'
end
end
25 changes: 25 additions & 0 deletions app/graphql/types/flow_sub_flow_type.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# frozen_string_literal: true

module Types
class FlowSubFlowType < Types::BaseObject
description 'Represents a sub-flow parameter value.'

field :function_identifier, String,
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

While the input type should take the function_identifier, this should provide the resolved FunctionDefinition.

null: true,
description: 'The function identifier to execute.'
field :settings, [Types::FlowSubFlowSettingType],
method: :sub_flow_settings,
null: false,
description: 'The sub-flow settings.'
field :signature, String,
null: false,
description: 'The sub-flow signature.'
field :starting_node_id, GlobalIdType[::NodeFunction],
null: true,
description: 'The starting node to execute.'

def starting_node_id
object.starting_node&.to_global_id
end
end
end
3 changes: 3 additions & 0 deletions app/graphql/types/input/flow_setting_input_type.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ module Input
class FlowSettingInputType < Types::BaseInputObject
description 'Input type for flow settings'

argument :cast, String,
required: false,
description: 'The cast applied to the flow setting'
argument :value, GraphQL::Types::JSON, required: true,
description: 'The value of the flow setting'
end
Expand Down
24 changes: 24 additions & 0 deletions app/graphql/types/input/flow_sub_flow_input_type.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# frozen_string_literal: true

module Types
module Input
class FlowSubFlowInputType < Types::BaseInputObject
description 'Input type for sub-flow parameter values'

argument :function_identifier, String,
required: false,
description: 'The function identifier to execute'
argument :settings, [Types::Input::FlowSubFlowSettingInputType],
required: false,
description: 'The sub-flow settings'
argument :signature, String,
Comment thread
Taucher2003 marked this conversation as resolved.
required: true,
description: 'The sub-flow signature'
argument :starting_node_id, Types::GlobalIdType[::NodeFunction],
required: false,
description: 'The starting node to execute'

require_one_of %i[starting_node_id function_identifier]
end
end
end
22 changes: 22 additions & 0 deletions app/graphql/types/input/flow_sub_flow_setting_input_type.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# frozen_string_literal: true

module Types
module Input
class FlowSubFlowSettingInputType < Types::BaseInputObject
description 'Input type for sub-flow settings'

argument :default_value, GraphQL::Types::JSON,
Comment thread
Taucher2003 marked this conversation as resolved.
required: false,
description: 'The default value of the sub-flow setting'
argument :hidden, Boolean,
Comment thread
Taucher2003 marked this conversation as resolved.
required: false,
description: 'Whether the sub-flow setting is hidden'
argument :identifier, String,
required: true,
description: 'The identifier of the sub-flow setting'
argument :optional, Boolean,
Comment thread
Taucher2003 marked this conversation as resolved.
required: false,
description: 'Whether the sub-flow setting is optional'
end
end
end
3 changes: 3 additions & 0 deletions app/graphql/types/input/node_parameter_input_type.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ module Input
class NodeParameterInputType < Types::BaseInputObject
description 'Input type for Node parameter'

argument :cast, String,
required: false,
description: 'The cast applied to the parameter'
argument :value, Types::Input::NodeParameterValueInputType, required: true,
description: 'The value of the parameter'
end
Expand Down
6 changes: 3 additions & 3 deletions app/graphql/types/input/node_parameter_value_input_type.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@ class NodeParameterValueInputType < Types::BaseInputObject

argument :literal_value, GraphQL::Types::JSON,
required: false, description: 'The literal value of the parameter'
argument :node_function_id, Types::GlobalIdType[::NodeFunction],
required: false, description: 'The function value of the parameter as an id'
argument :reference_value, Types::Input::ReferenceValueInputType,
required: false, description: 'The reference value of the parameter'
argument :sub_flow, Types::Input::FlowSubFlowInputType,
required: false, description: 'The sub-flow value of the parameter'

require_one_of %i[node_function_id literal_value reference_value]
require_one_of %i[literal_value reference_value sub_flow]
end
end
end
9 changes: 0 additions & 9 deletions app/graphql/types/node_function_id_wrapper_type.rb

This file was deleted.

5 changes: 3 additions & 2 deletions app/graphql/types/node_parameter_type.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,16 @@ class NodeParameterType < Types::BaseObject

authorize :read_flow

field :cast, String, null: true, description: 'The cast applied to the parameter'
field :parameter_definition, Types::ParameterDefinitionType, null: false,
description: 'The definition of the parameter'
field :value, Types::NodeParameterValueType, null: true, description: 'The value of the parameter'

def value
if object.reference_value.present?
object.reference_value
elsif object.function_value.present?
object.function_value
elsif object.sub_flow.present?
object.sub_flow
else
object.literal_value
end
Expand Down
8 changes: 4 additions & 4 deletions app/graphql/types/node_parameter_value_type.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@ module Types
class NodeParameterValueType < Types::BaseUnion
description 'Represents a parameter value for a node.'

possible_types Types::LiteralValueType, Types::ReferenceValueType, Types::NodeFunctionIdWrapperType,
description: 'The value can be a literal, a reference, or a node function id.'
possible_types Types::FlowSubFlowType, Types::LiteralValueType, Types::ReferenceValueType,
description: 'The value can be a literal, a reference, or a sub-flow.'

def self.resolve_type(object, _context)
case object
when ReferenceValue
Types::ReferenceValueType
when NodeFunction
Types::NodeFunctionIdWrapperType
when SubFlow
Types::FlowSubFlowType
else
Types::LiteralValueType
end
Expand Down
3 changes: 2 additions & 1 deletion app/models/flow_setting.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ def to_grpc
Tucana::Shared::FlowSetting.new(
database_id: id,
flow_setting_id: flow_setting_id,
value: Tucana::Shared::Value.from_ruby(object)
value: Tucana::Shared::Value.from_ruby(object),
cast: cast
)
end
end
5 changes: 0 additions & 5 deletions app/models/node_function.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,6 @@ class NodeFunction < ApplicationRecord
belongs_to :next_node, class_name: 'NodeFunction', optional: true
belongs_to :flow, class_name: 'Flow'

belongs_to :value_of_node_parameter,
class_name: 'NodeParameter',
inverse_of: :function_value,
optional: true

has_one :previous_node,
class_name: 'NodeFunction',
foreign_key: :next_node_id,
Expand Down
13 changes: 7 additions & 6 deletions app/models/node_parameter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,23 @@ class NodeParameter < ApplicationRecord
belongs_to :node_function, class_name: 'NodeFunction', inverse_of: :node_parameters

has_one :reference_value, autosave: true
has_one :function_value, class_name: 'NodeFunction', inverse_of: :value_of_node_parameter
has_one :sub_flow, autosave: true

validate :only_one_value_present

def to_grpc
param = Tucana::Shared::NodeParameter.new(
database_id: id,
runtime_parameter_id: parameter_definition.runtime_parameter_definition.runtime_name
runtime_parameter_id: parameter_definition.runtime_parameter_definition.runtime_name,
cast: cast
)

param.value = Tucana::Shared::NodeValue.new(literal_value: Tucana::Shared::Value.from_ruby({}))

if reference_value.present?
param.value.reference_value = reference_value.to_grpc
elsif function_value.present?
param.value.node_function_id = function_value.id
elsif sub_flow.present?
param.value.sub_flow = sub_flow.to_grpc
else
param.value.literal_value = Tucana::Shared::Value.from_ruby(literal_value)
end
Expand All @@ -31,9 +32,9 @@ def to_grpc
private

def only_one_value_present
values = [!literal_value.nil?, reference_value.present?, function_value.present?]
values = [!literal_value.nil?, reference_value.present?, sub_flow.present?]
return if values.count(true) <= 1

errors.add(:value, 'Only one of literal_value, reference_value, or function_value must be present')
errors.add(:value, 'Only one of literal_value, reference_value, or sub_flow must be present')
end
end
32 changes: 32 additions & 0 deletions app/models/sub_flow.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# frozen_string_literal: true

class SubFlow < ApplicationRecord
belongs_to :node_parameter, inverse_of: :sub_flow
belongs_to :starting_node, class_name: 'NodeFunction', optional: true
belongs_to :function_definition, optional: true

has_many :sub_flow_settings, inverse_of: :sub_flow, autosave: true

validate :validate_execution_reference

def function_identifier
function_definition&.identifier
end

def to_grpc
Tucana::Shared::SubFlow.new(
starting_node_id: starting_node_id,
function_identifier: function_identifier,
signature: signature,
settings: sub_flow_settings.map(&:to_grpc)
)
end

private

def validate_execution_reference
return if [starting_node_id.present?, function_definition_id.present?].count(true) == 1

errors.add(:base, 'Exactly one of starting_node or function_definition must be present')
end
end
16 changes: 16 additions & 0 deletions app/models/sub_flow_setting.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# frozen_string_literal: true

class SubFlowSetting < ApplicationRecord
belongs_to :sub_flow, inverse_of: :sub_flow_settings

validates :identifier, presence: true

def to_grpc
Tucana::Shared::SubFlowSetting.new(
identifier: identifier,
default_value: default_value.nil? ? nil : Tucana::Shared::Value.from_ruby(default_value),
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure if that is important for you on the runtime side, but Tucana::Shared::Value.from_ruby(nil) creates a proper NULL_VALUE while using nil is basically that the field is not set.

optional: optional,
hidden: hidden
)
end
end
1 change: 0 additions & 1 deletion app/services/error_code.rb
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,6 @@ def self.error_codes
cyclic_data_type_reference: { description: 'A data type dependency cycle was detected' },
invalid_data_type_link: { description: 'The data type link is invalid because of active model errors' },
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' },
invalid_runtime_status: { description: 'The runtime status is invalid because of active model errors' },
Expand Down
Loading