Skip to content
Merged
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
3 changes: 2 additions & 1 deletion app/graphql/mutations/namespaces/projects/flows/create.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ def resolve(project_id:, flow:, **_params)
namespace_project: project,
flow_type: flow_type,
starting_node: flow.starting_node,
flow_settings: flow.settings || []
flow_settings: flow.settings || [],
name: flow.name
).execute.to_mutation_response(success_key: :flow)
end

Expand Down
3 changes: 2 additions & 1 deletion app/graphql/types/flow_type.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ class FlowType < Types::BaseObject

authorize :read_flow

# field :name, String, null: false does exist in pictor but not in grpc
field :name, String, null: false, description: 'Name of the flow'

field :input_type, Types::DataTypeType,
null: true,
description: 'The input data type of the flow'
Expand Down
2 changes: 2 additions & 0 deletions app/graphql/types/input/flow_input_type.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ module Input
class FlowInputType < Types::BaseInputObject
description 'Input type for creating or updating a flow'

argument :name, String, required: true, description: 'The name of the flow'

argument :settings, [Types::Input::FlowSettingInputType], required: false,
description: 'The settings of the flow'
argument :starting_node, Types::Input::NodeFunctionInputType, required: true,
Expand Down
4 changes: 4 additions & 0 deletions app/models/flow.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ class Flow < ApplicationRecord

has_many :flow_settings, class_name: 'FlowSetting', inverse_of: :flow

validates :name, presence: true,
allow_blank: false,
uniqueness: { case_sensitive: false, scope: :project_id }

def to_grpc
Tucana::Shared::ValidationFlow.new(
flow_id: id,
Expand Down
4 changes: 4 additions & 0 deletions db/migrate/20250526124346_create_flows.rb
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,10 @@ def change

t.references :starting_node, null: false, foreign_key: { to_table: :node_functions, on_delete: :restrict }

t.text :name, null: false

t.index %i[name project_id], unique: true

t.timestamps_with_timezone
end

Expand Down
3 changes: 3 additions & 0 deletions db/structure.sql
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,7 @@ CREATE TABLE flows (
input_type_id bigint,
return_type_id bigint,
starting_node_id bigint NOT NULL,
name text NOT NULL,
created_at timestamp with time zone NOT NULL,
updated_at timestamp with time zone NOT NULL
);
Expand Down Expand Up @@ -1099,6 +1100,8 @@ CREATE INDEX index_flows_on_flow_type_id ON flows USING btree (flow_type_id);

CREATE INDEX index_flows_on_input_type_id ON flows USING btree (input_type_id);

CREATE UNIQUE INDEX index_flows_on_name_and_project_id ON flows USING btree (name, project_id);

CREATE INDEX index_flows_on_project_id ON flows USING btree (project_id);

CREATE INDEX index_flows_on_return_type_id ON flows USING btree (return_type_id);
Expand Down
1 change: 1 addition & 0 deletions docs/graphql/input_object/flowinput.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ Input type for creating or updating a flow

| Name | Type | Description |
|------|------|-------------|
| `name` | [`String!`](../scalar/string.md) | The name of the flow |
| `settings` | [`[FlowSettingInput!]`](../input_object/flowsettinginput.md) | The settings of the flow |
| `startingNode` | [`NodeFunctionInput!`](../input_object/nodefunctioninput.md) | The starting node of the flow |
| `type` | [`FlowTypeID!`](../scalar/flowtypeid.md) | The identifier of the flow type |
1 change: 1 addition & 0 deletions docs/graphql/object/flow.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ Represents a flow
| `createdAt` | [`Time!`](../scalar/time.md) | Time when this Flow was created |
| `id` | [`FlowID!`](../scalar/flowid.md) | Global ID of this Flow |
| `inputType` | [`DataType`](../object/datatype.md) | The input data type of the flow |
| `name` | [`String!`](../scalar/string.md) | Name of the flow |
| `nodes` | [`NodeFunctionConnection!`](../object/nodefunctionconnection.md) | Nodes of the flow |
| `returnType` | [`DataType`](../object/datatype.md) | The return data type of the flow |
| `settings` | [`FlowSettingConnection!`](../object/flowsettingconnection.md) | The settings of the flow |
Expand Down
3 changes: 3 additions & 0 deletions spec/factories/flows.rb
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
# frozen_string_literal: true

FactoryBot.define do
sequence(:flow_name) { |n| "Flow#{n}" }

factory :flow do
project factory: :namespace_project
flow_type
starting_node factory: :node_function
flow_settings { [] }
input_type { nil }
return_type { nil }
name { generate(:flow_name) }
end
end
5 changes: 5 additions & 0 deletions spec/models/flow_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@
it { is_expected.to have_many(:flow_settings) }
end

describe 'validations' do
it { is_expected.to validate_presence_of(:name) }
it { is_expected.to validate_uniqueness_of(:name).case_insensitive.scoped_to(:project_id) }
end

describe '#to_grpc' do
let(:flow) do
create(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@
{
projectId: project.to_global_id.to_s,
flow: {
name: generate(:flow_name),
type: flow_type.to_global_id.to_s,
settings: {
flowSettingId: 'key',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@
create(:node_function, runtime_function: create(:runtime_function_definition, runtime: runtime))
end
let(:params) do
{ project: namespace_project, flow_type: create(:flow_type, runtime: runtime), starting_node: starting_node }
{ project: namespace_project, name: generate(:flow_name), flow_type: create(:flow_type, runtime: runtime),
starting_node: starting_node }
end

shared_examples 'does not create' do
Expand Down