diff --git a/app/graphql/types/input/node_function_input_type.rb b/app/graphql/types/input/node_function_input_type.rb index 071ae0b8..7fa4a85c 100644 --- a/app/graphql/types/input/node_function_input_type.rb +++ b/app/graphql/types/input/node_function_input_type.rb @@ -8,8 +8,8 @@ class NodeFunctionInputType < Types::BaseInputObject argument :id, Types::GlobalIdType[::NodeFunction], required: true, description: 'The identifier of the Node Function used to create/update the flow' - argument :runtime_function_id, Types::GlobalIdType[::RuntimeFunctionDefinition], - required: true, description: 'The identifier of the Runtime Function Definition' + argument :function_definition_id, Types::GlobalIdType[::FunctionDefinition], + required: true, description: 'The identifier of the Function Definition' argument :next_node_id, Types::GlobalIdType[::NodeFunction], required: false, description: 'The next Node Function in the flow' diff --git a/app/graphql/types/input/node_parameter_input_type.rb b/app/graphql/types/input/node_parameter_input_type.rb index 16d5f3a3..a89a5aa6 100644 --- a/app/graphql/types/input/node_parameter_input_type.rb +++ b/app/graphql/types/input/node_parameter_input_type.rb @@ -5,8 +5,8 @@ module Input class NodeParameterInputType < Types::BaseInputObject description 'Input type for Node parameter' - argument :runtime_parameter_definition_id, Types::GlobalIdType[::RuntimeParameterDefinition], - required: true, description: 'The identifier of the Runtime Parameter Definition' + argument :parameter_definition_id, Types::GlobalIdType[::ParameterDefinition], + required: true, description: 'The identifier of the Parameter Definition' argument :value, Types::Input::NodeParameterValueInputType, required: false, description: 'The value of the parameter' diff --git a/app/graphql/types/literal_value_type.rb b/app/graphql/types/literal_value_type.rb index 0744e854..a88f1994 100644 --- a/app/graphql/types/literal_value_type.rb +++ b/app/graphql/types/literal_value_type.rb @@ -4,9 +4,10 @@ module Types class LiteralValueType < Types::BaseObject description 'Represents a literal value, such as a string or number.' - authorize :read_datatype - - field :value, GraphQL::Types::JSON, null: false, description: 'The literal value itself as JSON.' + field :value, GraphQL::Types::JSON, + null: false, + description: 'The literal value itself as JSON.', + method: :itself timestamps end diff --git a/app/graphql/types/node_function_id_wrapper_type.rb b/app/graphql/types/node_function_id_wrapper_type.rb index 32664ce6..5db7a54a 100644 --- a/app/graphql/types/node_function_id_wrapper_type.rb +++ b/app/graphql/types/node_function_id_wrapper_type.rb @@ -4,7 +4,6 @@ module Types class NodeFunctionIdWrapperType < Types::BaseObject description 'Represents a Node Function id wrapper.' - authorize :read_flow id_field NodeFunction end end diff --git a/app/graphql/types/node_parameter_type.rb b/app/graphql/types/node_parameter_type.rb index 6798f460..5b89947c 100644 --- a/app/graphql/types/node_parameter_type.rb +++ b/app/graphql/types/node_parameter_type.rb @@ -6,8 +6,8 @@ class NodeParameterType < Types::BaseObject authorize :read_flow - field :runtime_parameter, Types::RuntimeParameterDefinitionType, null: false, - description: 'The definition of 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 diff --git a/app/graphql/types/reference_path_type.rb b/app/graphql/types/reference_path_type.rb index 15730ac1..aea4629e 100644 --- a/app/graphql/types/reference_path_type.rb +++ b/app/graphql/types/reference_path_type.rb @@ -4,8 +4,6 @@ module Types class ReferencePathType < Types::BaseObject description 'Represents a reference path in a flow' - authorize :read_flow - field :array_index, Integer, null: true, description: 'The array index of the referenced data by the path' field :path, String, null: true, description: 'The path to the reference in the flow' diff --git a/app/graphql/types/reference_value_type.rb b/app/graphql/types/reference_value_type.rb index 96a94622..719487cf 100644 --- a/app/graphql/types/reference_value_type.rb +++ b/app/graphql/types/reference_value_type.rb @@ -4,8 +4,6 @@ module Types class ReferenceValueType < Types::BaseObject description 'Represents a reference value in the system.' - authorize :read_flow - field :node_function_id, GlobalIdType[::NodeFunction], null: false, description: 'The referenced value.' field :data_type_identifier, Types::DataTypeIdentifierType, @@ -15,10 +13,16 @@ class ReferenceValueType < Types::BaseObject field :node, Int, null: false, description: 'The node of the reference value.' field :scope, [Int], null: false, description: 'The scope of the reference value.' - field :reference_path, [Types::ReferencePathType], null: false, - description: 'The paths associated with this reference value.' + field :reference_path, [Types::ReferencePathType], + null: false, + description: 'The paths associated with this reference value.', + method: :reference_paths id_field ReferenceValue timestamps + + def node_function_id + object.node_function.to_global_id + end end end diff --git a/app/models/function_definition.rb b/app/models/function_definition.rb index 70d169cd..15ec160b 100644 --- a/app/models/function_definition.rb +++ b/app/models/function_definition.rb @@ -4,6 +4,7 @@ class FunctionDefinition < ApplicationRecord belongs_to :runtime_function_definition belongs_to :return_type, class_name: 'DataTypeIdentifier', optional: true + has_many :node_functions, inverse_of: :function_definition has_many :parameter_definitions, inverse_of: :function_definition has_many :names, -> { by_purpose(:name) }, class_name: 'Translation', as: :owner, inverse_of: :owner diff --git a/app/models/node_function.rb b/app/models/node_function.rb index 6c06b318..e783768d 100644 --- a/app/models/node_function.rb +++ b/app/models/node_function.rb @@ -1,7 +1,7 @@ # frozen_string_literal: true class NodeFunction < ApplicationRecord - belongs_to :runtime_function, class_name: 'RuntimeFunctionDefinition' + belongs_to :function_definition, inverse_of: :node_functions belongs_to :next_node, class_name: 'NodeFunction', optional: true belongs_to :flow, class_name: 'Flow' @@ -16,7 +16,9 @@ class NodeFunction < ApplicationRecord has_many :node_parameters, class_name: 'NodeParameter', - inverse_of: :node_function + inverse_of: :node_function, + dependent: :destroy, + autosave: true validate :validate_recursion, if: :next_node_changed? @@ -35,7 +37,7 @@ def validate_recursion def to_grpc Tucana::Shared::NodeFunction.new( database_id: id, - runtime_function_id: runtime_function.runtime_name, + runtime_function_id: function_definition.runtime_function_definition.runtime_name, parameters: node_parameters.map(&:to_grpc), next_node_id: next_node&.id ) diff --git a/app/models/node_parameter.rb b/app/models/node_parameter.rb index 6a935b83..694c04dc 100644 --- a/app/models/node_parameter.rb +++ b/app/models/node_parameter.rb @@ -1,8 +1,8 @@ # frozen_string_literal: true class NodeParameter < ApplicationRecord - belongs_to :runtime_parameter, class_name: 'RuntimeParameterDefinition' - belongs_to :reference_value, optional: true + belongs_to :parameter_definition, inverse_of: :node_parameters + belongs_to :reference_value, optional: true, autosave: true belongs_to :function_value, class_name: 'NodeFunction', optional: true, inverse_of: :node_parameter_values belongs_to :node_function, class_name: 'NodeFunction', inverse_of: :node_parameters @@ -11,7 +11,7 @@ class NodeParameter < ApplicationRecord def to_grpc param = Tucana::Shared::NodeParameter.new( database_id: id, - runtime_parameter_id: runtime_parameter.runtime_name + runtime_parameter_id: parameter_definition.runtime_parameter_definition.runtime_name ) param.value = Tucana::Shared::NodeValue.new(literal_value: Tucana::Shared::Value.from_ruby({})) diff --git a/app/models/parameter_definition.rb b/app/models/parameter_definition.rb index 7eb011fc..ff543fc3 100644 --- a/app/models/parameter_definition.rb +++ b/app/models/parameter_definition.rb @@ -6,6 +6,8 @@ class ParameterDefinition < ApplicationRecord belongs_to :function_definition, inverse_of: :parameter_definitions + has_many :node_parameters, inverse_of: :parameter_definition + has_many :names, -> { by_purpose(:name) }, class_name: 'Translation', as: :owner, inverse_of: :owner has_many :descriptions, -> { by_purpose(:description) }, class_name: 'Translation', as: :owner, inverse_of: :owner has_many :documentations, -> { by_purpose(:documentation) }, class_name: 'Translation', as: :owner, inverse_of: :owner diff --git a/app/models/reference_value.rb b/app/models/reference_value.rb index 2e7fc732..7b1da807 100644 --- a/app/models/reference_value.rb +++ b/app/models/reference_value.rb @@ -3,7 +3,7 @@ class ReferenceValue < ApplicationRecord belongs_to :node_function # real value association belongs_to :data_type_identifier - has_many :reference_paths, inverse_of: :reference_value + has_many :reference_paths, inverse_of: :reference_value, autosave: true has_many :node_parameters, inverse_of: :reference_value def to_grpc diff --git a/app/services/error_code.rb b/app/services/error_code.rb index 595f2046..4ba007a1 100644 --- a/app/services/error_code.rb +++ b/app/services/error_code.rb @@ -70,8 +70,9 @@ def self.error_codes license_not_found: { description: 'The namespace license with the given identifier was not found' }, flow_type_not_found: { description: 'The flow type with the given identifier was not found' }, organization_not_found: { description: 'The organization with the given identifier was not found' }, - invalid_runtime_function_id: { description: 'The runtime function ID is invalid' }, - invalid_runtime_parameter_id: { description: 'The runtime parameter ID is invalid' }, + invalid_function_id: { description: 'The function ID is invalid' }, + invalid_parameter_id: { description: 'The parameter ID is invalid' }, + invalid_reference_value: { description: 'The reference value is invalid' }, referenced_value_not_found: { description: 'A referenced value could not be found' }, invalid_runtime_parameter_definition: { description: 'The runtime parameter definition is invalid' }, invalid_runtime_function_definition: { description: 'The runtime function definition is invalid' }, diff --git a/app/services/namespaces/projects/flows/update_service.rb b/app/services/namespaces/projects/flows/update_service.rb index 328d82cc..e75b2621 100644 --- a/app/services/namespaces/projects/flows/update_service.rb +++ b/app/services/namespaces/projects/flows/update_service.rb @@ -90,7 +90,11 @@ def update_nodes(t) updated_nodes.each do |node| update_node_parameters(t, node[:node], node[:input], updated_nodes) update_next_node(t, node[:node], node[:input], updated_nodes) + end + # rubocop:disable Style/CombinableLoops -- this loop has to be separate + # A node can be invalid during the loop, but be valid again after all nodes have been processed + updated_nodes.each do |node| next if node[:node].save t.rollback_and_return! ServiceResponse.error( @@ -99,6 +103,7 @@ def update_nodes(t) details: node[:node].errors ) end + # rubocop:enable Style/CombinableLoops update_starting_node(t, updated_nodes) @@ -133,17 +138,17 @@ def delete_old_nodes(t, remaining_nodes) end def update_node(t, current_node, current_node_input) - runtime_function_definition = flow.project.primary_runtime.runtime_function_definitions.find_by( - id: current_node_input.runtime_function_id.model_id + function_definition = flow.project.primary_runtime.function_definitions.find_by( + id: current_node_input.function_definition_id.model_id ) - if runtime_function_definition.nil? + if function_definition.nil? t.rollback_and_return! ServiceResponse.error( - message: 'Invalid runtime function id', - error_code: :invalid_runtime_function_id + message: 'Invalid function id', + error_code: :invalid_function_id ) end - current_node.runtime_function = runtime_function_definition + current_node.function_definition = function_definition end def update_next_node(t, current_node, current_node_input, all_nodes) @@ -164,17 +169,17 @@ def update_node_parameters(t, current_node, current_node_input, all_nodes) current_node_input.parameters.each_with_index do |parameter, index| db_parameters[index] ||= current_node.node_parameters.build - runtime_parameter = current_node.runtime_function.parameters.find_by( - id: parameter.runtime_parameter_definition_id.model_id + parameter_definition = current_node.function_definition.parameter_definitions.find_by( + id: parameter.parameter_definition_id.model_id ) - if runtime_parameter.nil? + if parameter_definition.nil? t.rollback_and_return! ServiceResponse.error( - message: 'Invalid runtime parameter id', - error_code: :invalid_runtime_parameter_id + message: 'Invalid parameter id', + error_code: :invalid_parameter_id ) end - db_parameters[index].runtime_parameter = runtime_parameter + db_parameters[index].parameter_definition = parameter_definition db_parameters[index].literal_value = parameter.value.literal_value diff --git a/app/services/namespaces/projects/flows/validation/data_type/data_type_identifier_validation_service.rb b/app/services/namespaces/projects/flows/validation/data_type/data_type_identifier_validation_service.rb index 5e9d0ff8..c3447b76 100644 --- a/app/services/namespaces/projects/flows/validation/data_type/data_type_identifier_validation_service.rb +++ b/app/services/namespaces/projects/flows/validation/data_type/data_type_identifier_validation_service.rb @@ -47,7 +47,8 @@ def execute end if data_type_identifier.generic_key.present? - unless node.runtime_function.generic_keys.include?(data_type_identifier.generic_key) + runtime_function_definition = node.function_definition.runtime_function_definition + unless runtime_function_definition.generic_keys.include?(data_type_identifier.generic_key) errors << ValidationResult.error( :data_type_identifier_generic_key_not_found, location: data_type_identifier diff --git a/app/services/namespaces/projects/flows/validation/node_function/generic_mapper_validation_service.rb b/app/services/namespaces/projects/flows/validation/node_function/generic_mapper_validation_service.rb index 42d7d23c..53dc529b 100644 --- a/app/services/namespaces/projects/flows/validation/node_function/generic_mapper_validation_service.rb +++ b/app/services/namespaces/projects/flows/validation/node_function/generic_mapper_validation_service.rb @@ -25,7 +25,8 @@ def execute target = generic_mapper.target # Validate the target the identifier gets validated later - unless parameter.node_function.runtime_function.generic_keys.include?(target) + runtime_function_definition = parameter.node_function.function_definition.runtime_function_definition + unless runtime_function_definition.generic_keys.include?(target) errors << ValidationResult.error( :generic_key_not_found, location: generic_mapper diff --git a/app/services/namespaces/projects/flows/validation/node_function/node_function_parameter_validation_service.rb b/app/services/namespaces/projects/flows/validation/node_function/node_function_parameter_validation_service.rb index 6d397e95..cfa74716 100644 --- a/app/services/namespaces/projects/flows/validation/node_function/node_function_parameter_validation_service.rb +++ b/app/services/namespaces/projects/flows/validation/node_function/node_function_parameter_validation_service.rb @@ -31,7 +31,8 @@ def execute location: parameter ) end - if parameter.runtime_parameter.runtime_function_definition.runtime != flow.project.primary_runtime + runtime_parameter_definition = parameter.parameter_definition.runtime_parameter_definition + if runtime_parameter_definition.runtime_function_definition.runtime != flow.project.primary_runtime errors << ValidationResult.error( :node_parameter_runtime_mismatch, location: parameter diff --git a/app/services/namespaces/projects/flows/validation/node_function/node_function_validation_service.rb b/app/services/namespaces/projects/flows/validation/node_function/node_function_validation_service.rb index 69d31d2c..a4ef66da 100644 --- a/app/services/namespaces/projects/flows/validation/node_function/node_function_validation_service.rb +++ b/app/services/namespaces/projects/flows/validation/node_function/node_function_validation_service.rb @@ -30,14 +30,14 @@ def execute location: node_function ) end - if node_function.runtime_function.runtime != flow.project.primary_runtime + if node_function.function_definition.runtime_function_definition.runtime != flow.project.primary_runtime errors << ValidationResult.error( :node_function_runtime_mismatch, location: node_function ) end - node_function.runtime_function.tap do |runtime_function| + node_function.function_definition.runtime_function_definition.tap do |runtime_function| logger .debug("Validating runtime function: #{runtime_function.id} for node function: #{node_function.id}") if runtime_function.runtime != flow.project.primary_runtime @@ -50,8 +50,9 @@ def execute node_function.node_parameters.each do |parameter| logger.debug("Validating node parameter: #{parameter.id} for function: #{node_function.id}") + parameter_function_definition = parameter.parameter_definition.function_definition - if parameter.runtime_parameter.runtime_function_definition != node_function.runtime_function + if parameter_function_definition != node_function.function_definition logger.debug(message: 'Node parameter does not match its function', node_function: node_function.id, runtime_parameter: parameter.runtime_parameter.id, diff --git a/db/migrate/20260115182425_link_node_functions_to_function_definitions.rb b/db/migrate/20260115182425_link_node_functions_to_function_definitions.rb new file mode 100644 index 00000000..b59056db --- /dev/null +++ b/db/migrate/20260115182425_link_node_functions_to_function_definitions.rb @@ -0,0 +1,13 @@ +# frozen_string_literal: true + +class LinkNodeFunctionsToFunctionDefinitions < Code0::ZeroTrack::Database::Migration[1.0] + def change + # rubocop:disable Rails/NotNullColumn -- backwards compatibility intentionally ignored + add_reference :node_functions, :function_definition, null: false, foreign_key: { on_delete: :restrict } + # rubocop:enable Rails/NotNullColumn + remove_reference :node_functions, :runtime_function, null: false, foreign_key: { + on_delete: :restrict, + to_table: :runtime_function_definitions, + } + end +end diff --git a/db/migrate/20260115184937_link_node_parameters_to_parameter_definitions.rb b/db/migrate/20260115184937_link_node_parameters_to_parameter_definitions.rb new file mode 100644 index 00000000..2873def3 --- /dev/null +++ b/db/migrate/20260115184937_link_node_parameters_to_parameter_definitions.rb @@ -0,0 +1,13 @@ +# frozen_string_literal: true + +class LinkNodeParametersToParameterDefinitions < Code0::ZeroTrack::Database::Migration[1.0] + def change + # rubocop:disable Rails/NotNullColumn -- backwards compatibility intentionally ignored + add_reference :node_parameters, :parameter_definition, null: false, foreign_key: { on_delete: :restrict } + # rubocop:enable Rails/NotNullColumn + remove_reference :node_parameters, :runtime_parameter, null: false, foreign_key: { + on_delete: :cascade, + to_table: :runtime_parameter_definitions, + } + end +end diff --git a/db/schema_migrations/20260115182425 b/db/schema_migrations/20260115182425 new file mode 100644 index 00000000..86d74250 --- /dev/null +++ b/db/schema_migrations/20260115182425 @@ -0,0 +1 @@ +5b7050d1dd0f20888ecf4287f04de346d9d4e37a3dccc796d7d6682d9a2dfef4 \ No newline at end of file diff --git a/db/schema_migrations/20260115184937 b/db/schema_migrations/20260115184937 new file mode 100644 index 00000000..c539a78d --- /dev/null +++ b/db/schema_migrations/20260115184937 @@ -0,0 +1 @@ +481a244e97396174f7937edda0e1d20d17c95b85f51f051daa0e1bcc590cf853 \ No newline at end of file diff --git a/db/structure.sql b/db/structure.sql index 219d2880..3868476f 100644 --- a/db/structure.sql +++ b/db/structure.sql @@ -571,11 +571,11 @@ ALTER SEQUENCE namespaces_id_seq OWNED BY namespaces.id; CREATE TABLE node_functions ( id bigint NOT NULL, - runtime_function_id bigint NOT NULL, next_node_id bigint, created_at timestamp with time zone NOT NULL, updated_at timestamp with time zone NOT NULL, - flow_id bigint NOT NULL + flow_id bigint NOT NULL, + function_definition_id bigint NOT NULL ); CREATE SEQUENCE node_functions_id_seq @@ -589,13 +589,13 @@ ALTER SEQUENCE node_functions_id_seq OWNED BY node_functions.id; CREATE TABLE node_parameters ( id bigint NOT NULL, - runtime_parameter_id bigint NOT NULL, node_function_id bigint NOT NULL, literal_value jsonb, reference_value_id bigint, function_value_id bigint, created_at timestamp with time zone NOT NULL, updated_at timestamp with time zone NOT NULL, + parameter_definition_id bigint NOT NULL, CONSTRAINT check_fdac0ea550 CHECK ((num_nonnulls(literal_value, reference_value_id, function_value_id) = 1)) ); @@ -1187,17 +1187,17 @@ CREATE UNIQUE INDEX index_namespaces_on_parent_id_and_parent_type ON namespaces CREATE INDEX index_node_functions_on_flow_id ON node_functions USING btree (flow_id); -CREATE INDEX index_node_functions_on_next_node_id ON node_functions USING btree (next_node_id); +CREATE INDEX index_node_functions_on_function_definition_id ON node_functions USING btree (function_definition_id); -CREATE INDEX index_node_functions_on_runtime_function_id ON node_functions USING btree (runtime_function_id); +CREATE INDEX index_node_functions_on_next_node_id ON node_functions USING btree (next_node_id); CREATE INDEX index_node_parameters_on_function_value_id ON node_parameters USING btree (function_value_id); CREATE INDEX index_node_parameters_on_node_function_id ON node_parameters USING btree (node_function_id); -CREATE INDEX index_node_parameters_on_reference_value_id ON node_parameters USING btree (reference_value_id); +CREATE INDEX index_node_parameters_on_parameter_definition_id ON node_parameters USING btree (parameter_definition_id); -CREATE INDEX index_node_parameters_on_runtime_parameter_id ON node_parameters USING btree (runtime_parameter_id); +CREATE INDEX index_node_parameters_on_reference_value_id ON node_parameters USING btree (reference_value_id); CREATE UNIQUE INDEX "index_organizations_on_LOWER_name" ON organizations USING btree (lower(name)); @@ -1251,9 +1251,6 @@ ALTER TABLE ONLY function_definitions ALTER TABLE ONLY node_parameters ADD CONSTRAINT fk_rails_0d79310cfa FOREIGN KEY (node_function_id) REFERENCES node_functions(id) ON DELETE CASCADE; -ALTER TABLE ONLY node_parameters - ADD CONSTRAINT fk_rails_0ff4fd0049 FOREIGN KEY (runtime_parameter_id) REFERENCES runtime_parameter_definitions(id) ON DELETE CASCADE; - ALTER TABLE ONLY data_types ADD CONSTRAINT fk_rails_118c914ed0 FOREIGN KEY (runtime_id) REFERENCES runtimes(id) ON DELETE CASCADE; @@ -1272,6 +1269,9 @@ ALTER TABLE ONLY runtime_parameter_definitions ALTER TABLE ONLY generic_types ADD CONSTRAINT fk_rails_275446d9e6 FOREIGN KEY (data_type_id) REFERENCES data_types(id) ON DELETE CASCADE; +ALTER TABLE ONLY node_parameters + ADD CONSTRAINT fk_rails_2ed7c53167 FOREIGN KEY (parameter_definition_id) REFERENCES parameter_definitions(id) ON DELETE RESTRICT; + ALTER TABLE ONLY namespace_licenses ADD CONSTRAINT fk_rails_38f693332d FOREIGN KEY (namespace_id) REFERENCES namespaces(id) ON DELETE CASCADE; @@ -1290,6 +1290,9 @@ ALTER TABLE ONLY function_definitions ALTER TABLE ONLY runtime_function_definitions ADD CONSTRAINT fk_rails_5161ff47e6 FOREIGN KEY (runtime_id) REFERENCES runtimes(id) ON DELETE CASCADE; +ALTER TABLE ONLY node_functions + ADD CONSTRAINT fk_rails_53cf3476d6 FOREIGN KEY (function_definition_id) REFERENCES function_definitions(id) ON DELETE RESTRICT; + ALTER TABLE ONLY backup_codes ADD CONSTRAINT fk_rails_556c1feac3 FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE; @@ -1341,9 +1344,6 @@ ALTER TABLE ONLY flows ALTER TABLE ONLY node_functions ADD CONSTRAINT fk_rails_8615bd0635 FOREIGN KEY (flow_id) REFERENCES flows(id) ON DELETE CASCADE; -ALTER TABLE ONLY node_functions - ADD CONSTRAINT fk_rails_8953e1d86a FOREIGN KEY (runtime_function_id) REFERENCES runtime_function_definitions(id) ON DELETE RESTRICT; - ALTER TABLE ONLY reference_values ADD CONSTRAINT fk_rails_8b9d8f68cc FOREIGN KEY (node_function_id) REFERENCES node_functions(id) ON DELETE RESTRICT; diff --git a/docs/graphql/enum/errorcodeenum.md b/docs/graphql/enum/errorcodeenum.md index 060cb8e6..80a3cdcc 100644 --- a/docs/graphql/enum/errorcodeenum.md +++ b/docs/graphql/enum/errorcodeenum.md @@ -33,6 +33,7 @@ Represents the available error responses | `INVALID_FLOW_SETTING` | The flow setting is invalid because of active model errors | | `INVALID_FLOW_TYPE` | The flow type is invalid because of active model errors | | `INVALID_FLOW_TYPE_SETTING` | The flow type setting is invalid because of active model errors | +| `INVALID_FUNCTION_ID` | The function ID is invalid | | `INVALID_GENERIC_MAPPER` | The generic mapper is invalid because of active model errors | | `INVALID_LOGIN_DATA` | Invalid login data provided | | `INVALID_NAMESPACE_LICENSE` | The namespace license is invalid because of active model errors | @@ -42,12 +43,12 @@ Represents the available error responses | `INVALID_NODE_FUNCTION` | The node function is invalid | | `INVALID_NODE_PARAMETER` | The node parameter is invalid | | `INVALID_ORGANIZATION` | The organization is invalid because of active model errors | +| `INVALID_PARAMETER_ID` | The parameter ID is invalid | | `INVALID_PASSWORD_REPEAT` | The provided password repeat does not match the password | +| `INVALID_REFERENCE_VALUE` | The reference value is invalid | | `INVALID_RUNTIME` | The runtime is invalid because of active model errors | | `INVALID_RUNTIME_FUNCTION_DEFINITION` | The runtime function definition is invalid | -| `INVALID_RUNTIME_FUNCTION_ID` | The runtime function ID is invalid | | `INVALID_RUNTIME_PARAMETER_DEFINITION` | The runtime parameter definition is invalid | -| `INVALID_RUNTIME_PARAMETER_ID` | The runtime parameter ID is invalid | | `INVALID_SETTING` | Invalid setting provided | | `INVALID_TOTP_SECRET` | The TOTP secret is invalid or cannot be verified | | `INVALID_USER` | The user is invalid because of active model errors | diff --git a/docs/graphql/input_object/nodefunctioninput.md b/docs/graphql/input_object/nodefunctioninput.md index 240a9707..353ad5b7 100644 --- a/docs/graphql/input_object/nodefunctioninput.md +++ b/docs/graphql/input_object/nodefunctioninput.md @@ -8,7 +8,7 @@ Input type for a Node Function | Name | Type | Description | |------|------|-------------| +| `functionDefinitionId` | [`FunctionDefinitionID!`](../scalar/functiondefinitionid.md) | The identifier of the Function Definition | | `id` | [`NodeFunctionID!`](../scalar/nodefunctionid.md) | The identifier of the Node Function used to create/update the flow | | `nextNodeId` | [`NodeFunctionID`](../scalar/nodefunctionid.md) | The next Node Function in the flow | | `parameters` | [`[NodeParameterInput!]!`](../input_object/nodeparameterinput.md) | The parameters of the Node Function | -| `runtimeFunctionId` | [`RuntimeFunctionDefinitionID!`](../scalar/runtimefunctiondefinitionid.md) | The identifier of the Runtime Function Definition | diff --git a/docs/graphql/input_object/nodeparameterinput.md b/docs/graphql/input_object/nodeparameterinput.md index e44021ac..d9b8a072 100644 --- a/docs/graphql/input_object/nodeparameterinput.md +++ b/docs/graphql/input_object/nodeparameterinput.md @@ -8,5 +8,5 @@ Input type for Node parameter | Name | Type | Description | |------|------|-------------| -| `runtimeParameterDefinitionId` | [`RuntimeParameterDefinitionID!`](../scalar/runtimeparameterdefinitionid.md) | The identifier of the Runtime Parameter Definition | +| `parameterDefinitionId` | [`ParameterDefinitionID!`](../scalar/parameterdefinitionid.md) | The identifier of the Parameter Definition | | `value` | [`NodeParameterValueInput`](../input_object/nodeparametervalueinput.md) | The value of the parameter | diff --git a/docs/graphql/object/nodeparameter.md b/docs/graphql/object/nodeparameter.md index c9258d44..c72e3c17 100644 --- a/docs/graphql/object/nodeparameter.md +++ b/docs/graphql/object/nodeparameter.md @@ -10,7 +10,7 @@ Represents a Node parameter |------|------|-------------| | `createdAt` | [`Time!`](../scalar/time.md) | Time when this NodeParameter was created | | `id` | [`NodeParameterID!`](../scalar/nodeparameterid.md) | Global ID of this NodeParameter | -| `runtimeParameter` | [`RuntimeParameterDefinition!`](../object/runtimeparameterdefinition.md) | The definition of the parameter | +| `parameterDefinition` | [`ParameterDefinition!`](../object/parameterdefinition.md) | The definition of the parameter | | `updatedAt` | [`Time!`](../scalar/time.md) | Time when this NodeParameter was last updated | | `value` | [`NodeParameterValue`](../union/nodeparametervalue.md) | The value of the parameter | diff --git a/spec/factories/node_functions.rb b/spec/factories/node_functions.rb index 9110998f..f12be9f1 100644 --- a/spec/factories/node_functions.rb +++ b/spec/factories/node_functions.rb @@ -2,7 +2,7 @@ FactoryBot.define do factory :node_function do - runtime_function factory: :runtime_function_definition + function_definition next_node { nil } node_parameters { [] } flow diff --git a/spec/factories/node_parameters.rb b/spec/factories/node_parameters.rb index 213c71c7..8d0c86df 100644 --- a/spec/factories/node_parameters.rb +++ b/spec/factories/node_parameters.rb @@ -2,7 +2,7 @@ FactoryBot.define do factory :node_parameter do - runtime_parameter factory: %i[runtime_parameter_definition] + parameter_definition node_function literal_value { 'value' } reference_value { nil } diff --git a/spec/factories/parameter_definitions.rb b/spec/factories/parameter_definitions.rb index 8f41d2d1..dbcc7857 100644 --- a/spec/factories/parameter_definitions.rb +++ b/spec/factories/parameter_definitions.rb @@ -2,8 +2,11 @@ FactoryBot.define do factory :parameter_definition do - runtime_parameter_definition - data_type + data_type factory: :data_type_identifier + + runtime_parameter_definition do + association :runtime_parameter_definition, data_type: data_type + end function_definition do association :function_definition, diff --git a/spec/models/flow_spec.rb b/spec/models/flow_spec.rb index 3bbd2765..b54294d6 100644 --- a/spec/models/flow_spec.rb +++ b/spec/models/flow_spec.rb @@ -41,11 +41,11 @@ :node_function, flow: flow, node_parameters: [ - build( + create( :node_parameter, - runtime_parameter: build( - :runtime_parameter_definition, - data_type: build( + parameter_definition: create( + :parameter_definition, + data_type: create( :data_type_identifier, generic_key: 'T' ) @@ -60,6 +60,9 @@ it 'matches the model' do grpc_object = flow.to_grpc + starting_node = flow.starting_node + parameter_definition = starting_node.node_parameters.first.parameter_definition + expect(grpc_object.to_h).to eq( { flow_id: flow.id, @@ -68,23 +71,22 @@ type: flow.flow_type.identifier, node_functions: [ { - database_id: flow.starting_node.id, - runtime_function_id: flow.starting_node.runtime_function.runtime_name, + database_id: starting_node.id, + runtime_function_id: starting_node.function_definition.runtime_function_definition.runtime_name, parameters: [ { - database_id: flow.starting_node.node_parameters.first.id, - runtime_parameter_id: - flow.starting_node.node_parameters.first.runtime_parameter.runtime_name, + database_id: starting_node.node_parameters.first.id, + runtime_parameter_id: parameter_definition.runtime_parameter_definition.runtime_name, value: { literal_value: { - string_value: flow.starting_node.node_parameters.first.literal_value, + string_value: starting_node.node_parameters.first.literal_value, }, }, } ], } ], - starting_node_id: flow.starting_node.id, + starting_node_id: starting_node.id, settings: [ database_id: flow.flow_settings.first.id, flow_setting_id: flow.flow_settings.first.flow_setting_id, diff --git a/spec/models/node_function_spec.rb b/spec/models/node_function_spec.rb index 301e30ef..c63b04ac 100644 --- a/spec/models/node_function_spec.rb +++ b/spec/models/node_function_spec.rb @@ -6,7 +6,7 @@ subject { create(:node_function) } describe 'associations' do - it { is_expected.to belong_to(:runtime_function).class_name('RuntimeFunctionDefinition') } + it { is_expected.to belong_to(:function_definition).class_name('FunctionDefinition') } it { is_expected.to belong_to(:next_node).class_name('NodeFunction').optional } it { is_expected.to belong_to(:flow).class_name('Flow') } diff --git a/spec/models/node_parameter_spec.rb b/spec/models/node_parameter_spec.rb index 3635fc3e..9ebcc716 100644 --- a/spec/models/node_parameter_spec.rb +++ b/spec/models/node_parameter_spec.rb @@ -4,13 +4,17 @@ RSpec.describe NodeParameter do subject do - create(:node_parameter, - runtime_parameter: create(:runtime_parameter_definition, - data_type: create(:data_type_identifier, data_type: create(:data_type)))) + create( + :node_parameter, + parameter_definition: create( + :parameter_definition, + data_type: create(:data_type_identifier, data_type: create(:data_type)) + ) + ) end describe 'associations' do - it { is_expected.to belong_to(:runtime_parameter).class_name('RuntimeParameterDefinition') } + it { is_expected.to belong_to(:parameter_definition).class_name('ParameterDefinition') } it { is_expected.to belong_to(:reference_value).optional } it { @@ -22,10 +26,19 @@ describe 'validations' do it 'validates only one of the value fields is present' do - param = build(:node_parameter, literal_value: nil, reference_value: nil, function_value: nil, - runtime_parameter: create(:runtime_parameter_definition, - data_type: create(:data_type_identifier, - data_type: create(:data_type)))) + param = build( + :node_parameter, + literal_value: nil, + reference_value: nil, + function_value: nil, + parameter_definition: create( + :parameter_definition, + data_type: create( + :data_type_identifier, + data_type: create(:data_type) + ) + ) + ) expect(param).not_to be_valid expect(param.errors[:value]) .to include('Exactly one of literal_value, reference_value, or function_value must be present') diff --git a/spec/requests/graphql/mutation/namespace/projects/flows/create_mutation_spec.rb b/spec/requests/graphql/mutation/namespace/projects/flows/create_mutation_spec.rb index c2e1de9a..f79e6701 100644 --- a/spec/requests/graphql/mutation/namespace/projects/flows/create_mutation_spec.rb +++ b/spec/requests/graphql/mutation/namespace/projects/flows/create_mutation_spec.rb @@ -23,6 +23,27 @@ count nodes { id + value { + __typename + ...on LiteralValue { + value + } + ...on ReferenceValue { + createdAt + dataTypeIdentifier { id } + depth + id + node + nodeFunctionId + referencePath { + arrayIndex + id + path + } + scope + updatedAt + } + } } } } @@ -43,15 +64,25 @@ let(:runtime) { create(:runtime) } let(:project) { create(:namespace_project, primary_runtime: runtime) } let(:flow_type) { create(:flow_type, runtime: runtime) } - let(:runtime_function) do - create(:runtime_function_definition, runtime: runtime, - parameters: [ - - create(:runtime_parameter_definition, - data_type: create(:data_type_identifier, - data_type: create(:data_type))) - - ]) + let(:function_definition) do + rfd = create(:runtime_function_definition, runtime: runtime) + rpd = create( + :runtime_parameter_definition, + runtime_function_definition: rfd, + data_type: create( + :data_type_identifier, + data_type: create(:data_type) + ) + ) + + create(:function_definition, runtime_function_definition: rfd).tap do |fd| + create( + :parameter_definition, + runtime_parameter_definition: rpd, + function_definition: fd, + data_type: rpd.data_type + ) + end end let(:input) do { @@ -67,22 +98,24 @@ }, }, nodes: [ - { id: 'gid://sagittarius/NodeFunction/2000', - runtimeFunctionId: runtime_function.to_global_id.to_s, + { + id: 'gid://sagittarius/NodeFunction/2000', + functionDefinitionId: function_definition.to_global_id.to_s, nextNodeId: nil, parameters: [ { - runtimeParameterDefinitionId: runtime_function.parameters.first.to_global_id.to_s, + parameterDefinitionId: function_definition.parameter_definitions.first.to_global_id.to_s, value: { literalValue: 100, }, } - ] }, + ], + }, { id: 'gid://sagittarius/NodeFunction/1000', - runtimeFunctionId: runtime_function.to_global_id.to_s, + functionDefinitionId: function_definition.to_global_id.to_s, parameters: [ - runtimeParameterDefinitionId: runtime_function.parameters.first.to_global_id.to_s, + parameterDefinitionId: function_definition.parameter_definitions.first.to_global_id.to_s, value: { nodeFunctionId: 'gid://sagittarius/NodeFunction/2000', } @@ -91,9 +124,9 @@ }, { id: 'gid://sagittarius/NodeFunction/1001', - runtimeFunctionId: runtime_function.to_global_id.to_s, + functionDefinitionId: function_definition.to_global_id.to_s, parameters: [ - runtimeParameterDefinitionId: runtime_function.parameters.first.to_global_id.to_s, + parameterDefinitionId: function_definition.parameter_definitions.first.to_global_id.to_s, value: { referenceValue: { depth: 1, @@ -165,6 +198,20 @@ expect(project.flows).to include(flow) expect(flow.node_functions.count).to eq(3) + parameter_values = graphql_data_at( + :namespaces_projects_flows_create, + :flow, + :nodes, + :nodes, + :parameters, + :nodes, + :value + ) + expect(parameter_values).to include(a_hash_including('value' => 100)) + expect(parameter_values).to include( + a_hash_including('referencePath' => [a_hash_including('arrayIndex' => 0, 'path' => 'some.path')]) + ) + is_expected.to create_audit_event( :flow_created, author_id: current_user.id, diff --git a/spec/requests/graphql/mutation/namespace/projects/flows/update_mutation_spec.rb b/spec/requests/graphql/mutation/namespace/projects/flows/update_mutation_spec.rb index a705f03e..9997c7ee 100644 --- a/spec/requests/graphql/mutation/namespace/projects/flows/update_mutation_spec.rb +++ b/spec/requests/graphql/mutation/namespace/projects/flows/update_mutation_spec.rb @@ -23,6 +23,27 @@ count nodes { id + value { + __typename + ...on LiteralValue { + value + } + ...on ReferenceValue { + createdAt + dataTypeIdentifier { id } + depth + id + node + nodeFunctionId + referencePath { + arrayIndex + id + path + } + scope + updatedAt + } + } } } } @@ -44,15 +65,25 @@ let(:project) { create(:namespace_project, primary_runtime: runtime) } let(:flow_type) { create(:flow_type, runtime: runtime) } let(:flow) { create(:flow, project: project, flow_type: flow_type) } - let(:runtime_function) do - create(:runtime_function_definition, runtime: runtime, - parameters: [ - - create(:runtime_parameter_definition, - data_type: create(:data_type_identifier, - data_type: create(:data_type))) + let(:function_definition) do + rfd = create(:runtime_function_definition, runtime: runtime) + rpd = create( + :runtime_parameter_definition, + runtime_function_definition: rfd, + data_type: create( + :data_type_identifier, + data_type: create(:data_type) + ) + ) - ]) + create(:function_definition, runtime_function_definition: rfd).tap do |fd| + create( + :parameter_definition, + runtime_parameter_definition: rpd, + function_definition: fd, + data_type: rpd.data_type + ) + end end let(:input) do @@ -69,22 +100,24 @@ }, }, nodes: [ - { id: 'gid://sagittarius/NodeFunction/2000', - runtimeFunctionId: runtime_function.to_global_id.to_s, + { + id: 'gid://sagittarius/NodeFunction/2000', + functionDefinitionId: function_definition.to_global_id.to_s, nextNodeId: nil, parameters: [ { - runtimeParameterDefinitionId: runtime_function.parameters.first.to_global_id.to_s, + parameterDefinitionId: function_definition.parameter_definitions.first.to_global_id.to_s, value: { - literalValue: [], + literalValue: 100, }, } - ] }, + ], + }, { id: 'gid://sagittarius/NodeFunction/1000', - runtimeFunctionId: runtime_function.to_global_id.to_s, + functionDefinitionId: function_definition.to_global_id.to_s, parameters: [ - runtimeParameterDefinitionId: runtime_function.parameters.first.to_global_id.to_s, + parameterDefinitionId: function_definition.parameter_definitions.first.to_global_id.to_s, value: { nodeFunctionId: 'gid://sagittarius/NodeFunction/2000', } @@ -93,15 +126,20 @@ }, { id: 'gid://sagittarius/NodeFunction/1001', - runtimeFunctionId: runtime_function.to_global_id.to_s, + functionDefinitionId: function_definition.to_global_id.to_s, parameters: [ - runtimeParameterDefinitionId: runtime_function.parameters.first.to_global_id.to_s, + parameterDefinitionId: function_definition.parameter_definitions.first.to_global_id.to_s, value: { referenceValue: { depth: 1, node: 1, scope: [], - referencePath: [], + referencePath: [ + { + arrayIndex: 0, + path: 'some.path', + } + ], nodeFunctionId: 'gid://sagittarius/NodeFunction/2000', dataTypeIdentifier: { genericKey: 'K', @@ -143,6 +181,20 @@ expect(project.flows).to include(flow) expect(flow.node_functions.count).to eq(3) + parameter_values = graphql_data_at( + :namespaces_projects_flows_update, + :flow, + :nodes, + :nodes, + :parameters, + :nodes, + :value + ) + expect(parameter_values).to include(a_hash_including('value' => 100)) + expect(parameter_values).to include( + a_hash_including('referencePath' => [a_hash_including('arrayIndex' => 0, 'path' => 'some.path')]) + ) + is_expected.to create_audit_event( :flow_updated, author_id: current_user.id, @@ -165,8 +217,8 @@ let(:flow) do create(:flow, project: project, flow_type: flow_type).tap do |f| - node1 = create(:node_function, flow: f, runtime_function: runtime_function) - node2 = create(:node_function, flow: f, runtime_function: runtime_function) + node1 = create(:node_function, flow: f, function_definition: function_definition) + node2 = create(:node_function, flow: f, function_definition: function_definition) f.starting_node = node1 node1.next_node = node2 node1.save! @@ -185,7 +237,7 @@ nodes: [ { id: flow.starting_node.to_global_id.to_s, - runtimeFunctionId: flow.starting_node.runtime_function.to_global_id.to_s, + functionDefinitionId: flow.starting_node.function_definition.to_global_id.to_s, nextNodeId: nil, parameters: [], } diff --git a/spec/requests/graphql/mutation/users/logout_spec.rb b/spec/requests/graphql/mutation/users/logout_spec.rb index 8680f4b9..59d805c7 100644 --- a/spec/requests/graphql/mutation/users/logout_spec.rb +++ b/spec/requests/graphql/mutation/users/logout_spec.rb @@ -51,18 +51,6 @@ context 'when input is invalid' do let(:current_user) { create(:user) } - context 'when session id is invalid' do - let(:user_session_id) { 'some random string' } - - it 'raises validation error' do - expect(graphql_errors).to include( - a_hash_including( - 'message' => a_string_including("\"#{user_session_id}\" is not a valid Global ID") - ) - ) - end - end - context 'when session id is does not exist' do let(:user_session_id) { 'gid://sagittarius/UserSession/0' } diff --git a/spec/requests/graphql/query/organization_query_spec.rb b/spec/requests/graphql/query/organization_query_spec.rb index e18e48ca..05d54109 100644 --- a/spec/requests/graphql/query/organization_query_spec.rb +++ b/spec/requests/graphql/query/organization_query_spec.rb @@ -22,22 +22,6 @@ before { post_graphql query, variables: variables, current_user: current_user } - context 'without an id' do - it 'returns an error' do - expect(graphql_data_at(:organization)).to be_nil - expect(graphql_errors).not_to be_empty - end - end - - context 'with an invalid id' do - let(:organization_id) { 'gid://sagittarius/Organizations/1' } - - it 'returns an error' do - expect(graphql_data_at(:organization)).to be_nil - expect(graphql_errors).not_to be_empty - end - end - context 'with a valid id but out of range' do let(:organization_id) { 'gid://sagittarius/Organization/0' } diff --git a/spec/services/namespaces/projects/flows/create_service_spec.rb b/spec/services/namespaces/projects/flows/create_service_spec.rb index 0f5da28d..9234a07d 100644 --- a/spec/services/namespaces/projects/flows/create_service_spec.rb +++ b/spec/services/namespaces/projects/flows/create_service_spec.rb @@ -17,9 +17,15 @@ create(:flow_type, runtime: runtime).to_global_id, 'gid://sagittarius/NodeFunction/12345', [ - Struct.new(:id, :runtime_function_id, :next_node_id, :parameters).new( + Struct.new(:id, :function_definition_id, :next_node_id, :parameters).new( 'gid://sagittarius/NodeFunction/12345', - create(:runtime_function_definition, runtime: runtime).to_global_id, + create( + :function_definition, + runtime_function_definition: create( + :runtime_function_definition, + runtime: runtime + ) + ).to_global_id, nil, [] ) @@ -52,9 +58,15 @@ create(:flow_type, runtime: runtime).to_global_id, nil, [ - Struct.new(:id, :runtime_function_id, :next_node_id, :parameters).new( + Struct.new(:id, :function_definition_id, :next_node_id, :parameters).new( 'gid://sagittarius/NodeFunction/12345', - create(:runtime_function_definition, runtime: runtime).to_global_id, + create( + :function_definition, + runtime_function_definition: create( + :runtime_function_definition, + runtime: runtime + ) + ).to_global_id, nil, [] ) diff --git a/spec/services/namespaces/projects/flows/update_service_spec.rb b/spec/services/namespaces/projects/flows/update_service_spec.rb index e335f232..462ac98b 100644 --- a/spec/services/namespaces/projects/flows/update_service_spec.rb +++ b/spec/services/namespaces/projects/flows/update_service_spec.rb @@ -10,7 +10,16 @@ let(:runtime) { create(:runtime) } let(:namespace_project) { create(:namespace_project, primary_runtime: runtime) } let(:starting_node) do - create(:node_function, runtime_function: create(:runtime_function_definition, runtime: runtime)) + create( + :node_function, + function_definition: create( + :function_definition, + runtime_function_definition: create( + :runtime_function_definition, + runtime: runtime + ) + ) + ) end let(:flow) { create(:flow, project: namespace_project, flow_type: create(:flow_type, runtime: runtime)) } let(:flow_input) do @@ -18,9 +27,9 @@ [], starting_node.to_global_id, [ - Struct.new(:id, :runtime_function_id, :next_node_id, :parameters).new( + Struct.new(:id, :function_definition_id, :next_node_id, :parameters).new( starting_node.to_global_id, - starting_node.runtime_function.to_global_id, + starting_node.function_definition.to_global_id, nil, [] ) diff --git a/spec/services/namespaces/projects/flows/validation/data_type/data_type_identifier_validation_service_spec.rb b/spec/services/namespaces/projects/flows/validation/data_type/data_type_identifier_validation_service_spec.rb index e1921ca9..8c083d7d 100644 --- a/spec/services/namespaces/projects/flows/validation/data_type/data_type_identifier_validation_service_spec.rb +++ b/spec/services/namespaces/projects/flows/validation/data_type/data_type_identifier_validation_service_spec.rb @@ -11,13 +11,28 @@ let(:runtime) { create(:runtime) } let(:namespace_project) { create(:namespace_project, primary_runtime: runtime) } let(:node) do - create(:node_function, - runtime_function: create(:runtime_function_definition, generic_keys: ['T'], runtime: runtime)) + create( + :node_function, + function_definition: create( + :function_definition, + runtime_function_definition: create( + :runtime_function_definition, + generic_keys: ['T'], + runtime: runtime + ) + ) + ) end let(:parameter) do create( :node_parameter, - runtime_parameter: create(:runtime_parameter_definition, data_type: data_type_identifier), + parameter_definition: create( + :parameter_definition, + runtime_parameter_definition: create( + :runtime_parameter_definition, + data_type: data_type_identifier + ) + ), node_function: node ) end @@ -51,8 +66,17 @@ context 'when T is contained in the function definition' do let(:node) do - create(:node_function, - runtime_function: create(:runtime_function_definition, generic_keys: ['T'], runtime: runtime)) + create( + :node_function, + function_definition: create( + :function_definition, + runtime_function_definition: create( + :runtime_function_definition, + generic_keys: ['T'], + runtime: runtime + ) + ) + ) end it { expect(service_response).to be_empty } @@ -60,8 +84,17 @@ context 'when T is not contained in the function definition' do let(:node) do - create(:node_function, - runtime_function: create(:runtime_function_definition, generic_keys: [], runtime: runtime)) + create( + :node_function, + function_definition: create( + :function_definition, + runtime_function_definition: create( + :runtime_function_definition, + generic_keys: [], + runtime: runtime + ) + ) + ) end it { expect(service_response).to include(have_attributes(error_code: :data_type_identifier_generic_key_not_found)) } diff --git a/spec/services/namespaces/projects/flows/validation/node_function/generic_mapper_validation_service_spec.rb b/spec/services/namespaces/projects/flows/validation/node_function/generic_mapper_validation_service_spec.rb index 607f2545..43d3c3bb 100644 --- a/spec/services/namespaces/projects/flows/validation/node_function/generic_mapper_validation_service_spec.rb +++ b/spec/services/namespaces/projects/flows/validation/node_function/generic_mapper_validation_service_spec.rb @@ -13,24 +13,39 @@ let(:flow) { create(:flow, project: namespace_project, starting_node: node) } let(:parameter) do - create(:node_parameter, - runtime_parameter: - create(:runtime_parameter_definition, - data_type: create(:data_type_identifier, - generic_type: create(:generic_type, - data_type: create(:data_type), - generic_mappers: [generic_mapper]))), - literal_value: nil, - function_value: create(:node_function)) + data_type_identifier = create( + :data_type_identifier, + generic_type: create( + :generic_type, + data_type: create(:data_type), + generic_mappers: [generic_mapper] + ) + ) + create( + :node_parameter, + parameter_definition: create( + :parameter_definition, + data_type: data_type_identifier + ), + literal_value: nil, + function_value: create(:node_function) + ) end let(:node) do - create(:node_function, - runtime_function: create(:runtime_function_definition, - generic_keys: ['T'], - runtime: runtime), - node_parameters: [ - parameter - ]) + create( + :node_function, + function_definition: create( + :function_definition, + runtime_function_definition: create( + :runtime_function_definition, + generic_keys: ['T'], + runtime: runtime + ) + ), + node_parameters: [ + parameter + ] + ) end let(:data_type_identifier) do create(:data_type_identifier, generic_key: 'T', runtime: runtime) diff --git a/spec/services/namespaces/projects/flows/validation/node_function/reference_value_validation_service_spec.rb b/spec/services/namespaces/projects/flows/validation/node_function/reference_value_validation_service_spec.rb index 95323c1e..d13f0ac5 100644 --- a/spec/services/namespaces/projects/flows/validation/node_function/reference_value_validation_service_spec.rb +++ b/spec/services/namespaces/projects/flows/validation/node_function/reference_value_validation_service_spec.rb @@ -13,33 +13,65 @@ let(:flow) { create(:flow, project: namespace_project, starting_node: first_node) } let(:first_node) do - create(:node_function, - runtime_function: create(:runtime_function_definition, runtime: runtime), - node_parameters: [ - create(:node_parameter, - runtime_parameter: create(:runtime_parameter_definition, data_type: data_type_identifier), - literal_value: nil, - function_value: create(:node_function)) - ], - next_node: second_node) + create( + :node_function, + function_definition: create( + :function_definition, + runtime_function_definition: create(:runtime_function_definition, runtime: runtime) + ), + node_parameters: [ + create( + :node_parameter, + parameter_definition: create( + :parameter_definition, + data_type: data_type_identifier + ), + literal_value: nil, + function_value: create(:node_function) + ) + ], + next_node: second_node + ) end let(:second_node) do - create(:node_function, - runtime_function: create(:runtime_function_definition, runtime: runtime), - node_parameters: [ - create(:node_parameter, - runtime_parameter: create(:runtime_parameter_definition, data_type: data_type_identifier), - literal_value: nil, - function_value: create(:node_function, node_parameters: [ - create(:node_parameter, - runtime_parameter: create(:runtime_parameter_definition, - data_type: data_type_identifier)) - ])), - create(:node_parameter, - runtime_parameter: create(:runtime_parameter_definition, data_type: data_type_identifier), - literal_value: nil, - function_value: create(:node_function)) - ]) + create( + :node_function, + function_definition: create( + :function_definition, + runtime_function_definition: create(:runtime_function_definition, runtime: runtime) + ), + node_parameters: [ + create( + :node_parameter, + parameter_definition: create( + :parameter_definition, + data_type: data_type_identifier + ), + literal_value: nil, + function_value: create( + :node_function, + node_parameters: [ + create( + :node_parameter, + parameter_definition: create( + :parameter_definition, + data_type: data_type_identifier + ) + ) + ] + ) + ), + create( + :node_parameter, + parameter_definition: create( + :parameter_definition, + data_type: data_type_identifier + ), + literal_value: nil, + function_value: create(:node_function) + ) + ] + ) end let(:data_type_identifier) do create(:data_type_identifier, data_type: create(:data_type, runtime: runtime), runtime: runtime) diff --git a/spec/support/helpers/graphql_helpers.rb b/spec/support/helpers/graphql_helpers.rb index 08a33d74..9b3fea08 100644 --- a/spec/support/helpers/graphql_helpers.rb +++ b/spec/support/helpers/graphql_helpers.rb @@ -35,6 +35,9 @@ def post_graphql(query, variables: {}, current_user: nil, headers: {}) expect(graphql_errors).not_to include( a_hash_including('message' => a_string_including("isn't a defined input type")) ) + expect(graphql_errors).not_to include( + a_hash_including('message' => a_string_including('was provided invalid value')) + ) expect(graphql_errors).not_to include(a_hash_including('backtrace')) end @@ -57,7 +60,7 @@ def graphql_dig_at(data, *path) if acc.is_a?(Array) && cur.is_a?(Integer) acc[cur] elsif acc.is_a?(Array) - acc.compact.pluck(cur) + acc.flatten.compact.pluck(cur) else acc&.dig(cur) end