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
25 changes: 25 additions & 0 deletions app/graphql/types/function_definition_type.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# frozen_string_literal: true

module Types
class FunctionDefinitionType < Types::BaseObject
description 'Represents a function definition'

authorize :read_function_definition

field :return_type, Types::DataTypeIdentifierType, null: true, description: 'Return type of the function'

field :parameter_definitions, Types::ParameterDefinitionType.connection_type,
null: true,
description: 'Parameters of the function'

field :descriptions, Types::TranslationType.connection_type, null: true, description: 'Description of the function'
field :names, Types::TranslationType.connection_type, null: true, description: 'Name of the function'

field :documentations, Types::TranslationType.connection_type,
null: true,
description: 'Documentation of the function'

id_field FunctionDefinition
timestamps
end
end
21 changes: 21 additions & 0 deletions app/graphql/types/parameter_definition_type.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# frozen_string_literal: true

module Types
class ParameterDefinitionType < Types::BaseObject
description 'Represents a parameter definition'

authorize :read_parameter_definition

field :data_type, Types::DataTypeIdentifierType, null: true, description: 'Data type of the parameter'

field :descriptions, Types::TranslationType.connection_type, null: true, description: 'Description of the parameter'
field :names, Types::TranslationType.connection_type, null: true, description: 'Name of the parameter'

field :documentations, Types::TranslationType.connection_type,
null: true,
description: 'Documentation of the parameter'

id_field ParameterDefinition
timestamps
end
end
4 changes: 4 additions & 0 deletions app/graphql/types/runtime_function_definition_type.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ class RuntimeFunctionDefinitionType < Types::BaseObject

authorize :read_flow

field :function_definitions, Types::FunctionDefinitionType.connection_type,
null: true,
description: 'Function definitions of the Node Function'

id_field RuntimeParameterDefinition
timestamps
end
Expand Down
2 changes: 2 additions & 0 deletions app/models/function_definition.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ class FunctionDefinition < ApplicationRecord
belongs_to :runtime_function_definition
belongs_to :return_type, class_name: 'DataTypeIdentifier', optional: true

has_many :parameter_definitions, inverse_of: :function_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
Expand Down
12 changes: 12 additions & 0 deletions app/models/parameter_definition.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,19 @@ class ParameterDefinition < ApplicationRecord
belongs_to :runtime_parameter_definition
belongs_to :data_type, class_name: 'DataTypeIdentifier'

belongs_to :function_definition, inverse_of: :parameter_definitions

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

validate :function_definition_matches_definition

def function_definition_matches_definition
parameter_function_definition_id = runtime_parameter_definition&.runtime_function_definition_id
function_definition_id = function_definition&.runtime_function_definition_id
return if parameter_function_definition_id == function_definition_id

errors.add(:function_definition, :runtime_function_definition_mismatch)
end
end
5 changes: 5 additions & 0 deletions app/policies/function_definition_policy.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# frozen_string_literal: true

class FunctionDefinitionPolicy < BasePolicy
delegate { subject.runtime_function_definition }
end
5 changes: 5 additions & 0 deletions app/policies/parameter_definition_policy.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# frozen_string_literal: true

class ParameterDefinitionPolicy < BasePolicy
delegate { subject.runtime_parameter_definition }
end
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,6 @@ def update_runtime_function_definition(runtime_function_definition, t)
runtime_name: runtime_function_definition.runtime_name
)
db_object.removed_at = nil
db_object.parameters = update_parameters(db_object, runtime_function_definition.runtime_parameter_definitions,
db_object.parameters, t)
db_object.return_type = if runtime_function_definition.return_type_identifier.present?
find_data_type_identifier(runtime_function_definition.return_type_identifier,
runtime_function_definition.generic_mappers, t)
Expand All @@ -51,7 +49,6 @@ def update_runtime_function_definition(runtime_function_definition, t)
db_object.deprecation_messages)

db_object.error_types = update_error_types(runtime_function_definition.error_type_identifiers, db_object, t)
db_object.generic_mappers = update_mappers(runtime_function_definition.generic_mappers, db_object, t)

if db_object.function_definitions.empty?
definition = FunctionDefinition.new
Expand All @@ -64,6 +61,11 @@ def update_runtime_function_definition(runtime_function_definition, t)

db_object.function_definitions << definition
end

db_object.parameters = update_parameters(db_object, runtime_function_definition.runtime_parameter_definitions,
db_object.parameters, t)
db_object.generic_mappers = update_mappers(runtime_function_definition.generic_mappers, db_object, t)

db_object.save
db_object
end
Expand Down Expand Up @@ -199,6 +201,7 @@ def update_parameters(runtime_function_definition, parameters, db_parameters, t)
definition.documentations = update_translations(real_param.documentation, definition.documentations)
definition.data_type = db_param.data_type
definition.default_value = db_param.default_value
definition.function_definition = runtime_function_definition.function_definitions.first

db_param.parameter_definitions << definition
end
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# frozen_string_literal: true

class AddFunctionDefinitionToParameterDefinition < Code0::ZeroTrack::Database::Migration[1.0]
def change
# rubocop:disable Rails/NotNullColumn -- backwards compatibility intentionally ignored
add_reference :parameter_definitions, :function_definition, null: false, foreign_key: { on_delete: :cascade }
# rubocop:enable Rails/NotNullColumn
end
end
1 change: 1 addition & 0 deletions db/schema_migrations/20250808184711
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
d3649d3eb21c55852c948235ae16319daf78f7260be8393a2718b63c27fb4dd4
8 changes: 7 additions & 1 deletion db/structure.sql
Original file line number Diff line number Diff line change
Expand Up @@ -645,7 +645,8 @@ CREATE TABLE parameter_definitions (
default_value jsonb,
created_at timestamp with time zone NOT NULL,
updated_at timestamp with time zone NOT NULL,
data_type_id bigint
data_type_id bigint,
function_definition_id bigint NOT NULL
);

CREATE SEQUENCE parameter_definitions_id_seq
Expand Down Expand Up @@ -1243,6 +1244,8 @@ CREATE UNIQUE INDEX "index_organizations_on_LOWER_name" ON organizations USING b

CREATE INDEX index_parameter_definitions_on_data_type_id ON parameter_definitions USING btree (data_type_id);

CREATE INDEX index_parameter_definitions_on_function_definition_id ON parameter_definitions USING btree (function_definition_id);

CREATE INDEX index_parameter_definitions_on_runtime_parameter_definition_id ON parameter_definitions USING btree (runtime_parameter_definition_id);

CREATE INDEX index_reference_paths_on_reference_value_id ON reference_paths USING btree (reference_value_id);
Expand Down Expand Up @@ -1296,6 +1299,9 @@ ALTER TABLE ONLY node_parameters
ALTER TABLE ONLY data_types
ADD CONSTRAINT fk_rails_118c914ed0 FOREIGN KEY (runtime_id) REFERENCES runtimes(id) ON DELETE CASCADE;

ALTER TABLE ONLY parameter_definitions
ADD CONSTRAINT fk_rails_18c14268dd FOREIGN KEY (function_definition_id) REFERENCES function_definitions(id) ON DELETE CASCADE;

ALTER TABLE ONLY generic_combination_strategies
ADD CONSTRAINT fk_rails_1f88a2577e FOREIGN KEY (generic_mapper_id) REFERENCES generic_mappers(id) ON DELETE CASCADE;

Expand Down
19 changes: 19 additions & 0 deletions docs/graphql/object/functiondefinition.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
---
title: FunctionDefinition
---

Represents a function definition

## Fields without arguments

| Name | Type | Description |
|------|------|-------------|
| `createdAt` | [`Time!`](../scalar/time.md) | Time when this FunctionDefinition was created |
| `descriptions` | [`TranslationConnection`](../object/translationconnection.md) | Description of the function |
| `documentations` | [`TranslationConnection`](../object/translationconnection.md) | Documentation of the function |
| `id` | [`FunctionDefinitionID!`](../scalar/functiondefinitionid.md) | Global ID of this FunctionDefinition |
| `names` | [`TranslationConnection`](../object/translationconnection.md) | Name of the function |
| `parameterDefinitions` | [`ParameterDefinitionConnection`](../object/parameterdefinitionconnection.md) | Parameters of the function |
| `returnType` | [`DataTypeIdentifier`](../object/datatypeidentifier.md) | Return type of the function |
| `updatedAt` | [`Time!`](../scalar/time.md) | Time when this FunctionDefinition was last updated |

15 changes: 15 additions & 0 deletions docs/graphql/object/functiondefinitionconnection.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
---
title: FunctionDefinitionConnection
---

The connection type for FunctionDefinition.

## Fields without arguments

| Name | Type | Description |
|------|------|-------------|
| `count` | [`Int!`](../scalar/int.md) | Total count of collection. |
| `edges` | [`[FunctionDefinitionEdge]`](../object/functiondefinitionedge.md) | A list of edges. |
| `nodes` | [`[FunctionDefinition]`](../object/functiondefinition.md) | A list of nodes. |
| `pageInfo` | [`PageInfo!`](../object/pageinfo.md) | Information to aid in pagination. |

13 changes: 13 additions & 0 deletions docs/graphql/object/functiondefinitionedge.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
---
title: FunctionDefinitionEdge
---

An edge in a connection.

## Fields without arguments

| Name | Type | Description |
|------|------|-------------|
| `cursor` | [`String!`](../scalar/string.md) | A cursor for use in pagination. |
| `node` | [`FunctionDefinition`](../object/functiondefinition.md) | The item at the end of the edge. |

18 changes: 18 additions & 0 deletions docs/graphql/object/parameterdefinition.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
---
title: ParameterDefinition
---

Represents a parameter definition

## Fields without arguments

| Name | Type | Description |
|------|------|-------------|
| `createdAt` | [`Time!`](../scalar/time.md) | Time when this ParameterDefinition was created |
| `dataType` | [`DataTypeIdentifier`](../object/datatypeidentifier.md) | Data type of the parameter |
| `descriptions` | [`TranslationConnection`](../object/translationconnection.md) | Description of the parameter |
| `documentations` | [`TranslationConnection`](../object/translationconnection.md) | Documentation of the parameter |
| `id` | [`ParameterDefinitionID!`](../scalar/parameterdefinitionid.md) | Global ID of this ParameterDefinition |
| `names` | [`TranslationConnection`](../object/translationconnection.md) | Name of the parameter |
| `updatedAt` | [`Time!`](../scalar/time.md) | Time when this ParameterDefinition was last updated |

15 changes: 15 additions & 0 deletions docs/graphql/object/parameterdefinitionconnection.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
---
title: ParameterDefinitionConnection
---

The connection type for ParameterDefinition.

## Fields without arguments

| Name | Type | Description |
|------|------|-------------|
| `count` | [`Int!`](../scalar/int.md) | Total count of collection. |
| `edges` | [`[ParameterDefinitionEdge]`](../object/parameterdefinitionedge.md) | A list of edges. |
| `nodes` | [`[ParameterDefinition]`](../object/parameterdefinition.md) | A list of nodes. |
| `pageInfo` | [`PageInfo!`](../object/pageinfo.md) | Information to aid in pagination. |

13 changes: 13 additions & 0 deletions docs/graphql/object/parameterdefinitionedge.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
---
title: ParameterDefinitionEdge
---

An edge in a connection.

## Fields without arguments

| Name | Type | Description |
|------|------|-------------|
| `cursor` | [`String!`](../scalar/string.md) | A cursor for use in pagination. |
| `node` | [`ParameterDefinition`](../object/parameterdefinition.md) | The item at the end of the edge. |

1 change: 1 addition & 0 deletions docs/graphql/object/runtimefunctiondefinition.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ Represents a Node Function definition
| Name | Type | Description |
|------|------|-------------|
| `createdAt` | [`Time!`](../scalar/time.md) | Time when this RuntimeFunctionDefinition was created |
| `functionDefinitions` | [`FunctionDefinitionConnection`](../object/functiondefinitionconnection.md) | Function definitions of the Node Function |
| `id` | [`RuntimeParameterDefinitionID!`](../scalar/runtimeparameterdefinitionid.md) | Global ID of this RuntimeFunctionDefinition |
| `updatedAt` | [`Time!`](../scalar/time.md) | Time when this RuntimeFunctionDefinition was last updated |

5 changes: 5 additions & 0 deletions docs/graphql/scalar/functiondefinitionid.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
title: FunctionDefinitionID
---

A unique identifier for all FunctionDefinition entities of the application
5 changes: 5 additions & 0 deletions docs/graphql/scalar/parameterdefinitionid.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
title: ParameterDefinitionID
---

A unique identifier for all ParameterDefinition entities of the application
5 changes: 5 additions & 0 deletions spec/factories/parameter_definitions.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,10 @@
factory :parameter_definition do
runtime_parameter_definition
data_type

function_definition do
association :function_definition,
runtime_function_definition: runtime_parameter_definition.runtime_function_definition
end
end
end
22 changes: 22 additions & 0 deletions spec/graphql/types/function_definition_type_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# frozen_string_literal: true

require 'rails_helper'

RSpec.describe SagittariusSchema.types['FunctionDefinition'] do
let(:fields) do
%w[
id
returnType
parameterDefinitions
names
descriptions
documentations
createdAt
updatedAt
]
end

it { expect(described_class.graphql_name).to eq('FunctionDefinition') }
it { expect(described_class).to have_graphql_fields(fields) }
it { expect(described_class).to require_graphql_authorizations(:read_function_definition) }
end
21 changes: 21 additions & 0 deletions spec/graphql/types/parameter_definition_type_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# frozen_string_literal: true

require 'rails_helper'

RSpec.describe SagittariusSchema.types['ParameterDefinition'] do
let(:fields) do
%w[
id
dataType
descriptions
names
documentations
createdAt
updatedAt
]
end

it { expect(described_class.graphql_name).to eq('ParameterDefinition') }
it { expect(described_class).to have_graphql_fields(fields) }
it { expect(described_class).to require_graphql_authorizations(:read_parameter_definition) }
end
18 changes: 18 additions & 0 deletions spec/graphql/types/runtime_function_definition_type_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# frozen_string_literal: true

require 'rails_helper'

RSpec.describe SagittariusSchema.types['RuntimeFunctionDefinition'] do
let(:fields) do
%w[
id
functionDefinitions
createdAt
updatedAt
]
end

it { expect(described_class.graphql_name).to eq('RuntimeFunctionDefinition') }
it { expect(described_class).to have_graphql_fields(fields) }
it { expect(described_class).to require_graphql_authorizations(:read_flow) }
end
17 changes: 17 additions & 0 deletions spec/graphql/types/runtime_parameter_definition_type_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# frozen_string_literal: true

require 'rails_helper'

RSpec.describe SagittariusSchema.types['RuntimeParameterDefinition'] do
let(:fields) do
%w[
id
createdAt
updatedAt
]
end

it { expect(described_class.graphql_name).to eq('RuntimeParameterDefinition') }
it { expect(described_class).to have_graphql_fields(fields) }
it { expect(described_class).to require_graphql_authorizations(:read_flow) }
end