Skip to content

Commit 6014c57

Browse files
committed
Add validation services for data types and node functions, enhance input types, and update JSON schemas
1 parent 3a2eb04 commit 6014c57

File tree

55 files changed

+1131
-106
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

55 files changed

+1131
-106
lines changed

Gemfile

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,3 +89,6 @@ gem 'pry-byebug', '~> 3.10'
8989
gem 'code0-zero_track', '0.0.4'
9090

9191
gem 'image_processing', '>= 1.2'
92+
93+
94+
gem "json-schema", "~> 5.1"

Gemfile.lock

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,8 @@ GEM
7272
securerandom (>= 0.3)
7373
tzinfo (~> 2.0, >= 2.0.5)
7474
uri (>= 0.13.1)
75+
addressable (2.8.7)
76+
public_suffix (>= 2.0.2, < 7.0)
7577
ast (2.4.3)
7678
base64 (0.2.0)
7779
bcrypt (3.1.20)
@@ -154,6 +156,9 @@ GEM
154156
rdoc (>= 4.0.0)
155157
reline (>= 0.4.2)
156158
json (2.12.0)
159+
json-schema (5.1.1)
160+
addressable (~> 2.8)
161+
bigdecimal (~> 3.1)
157162
language_server-protocol (3.17.0.5)
158163
lint_roller (1.1.0)
159164
logger (1.7.0)
@@ -212,6 +217,7 @@ GEM
212217
psych (5.2.6)
213218
date
214219
stringio
220+
public_suffix (6.0.2)
215221
puma (6.6.0)
216222
nio4r (~> 2.0)
217223
raabro (1.4.0)
@@ -389,6 +395,7 @@ DEPENDENCIES
389395
graphql (~> 2.1)
390396
grpc (~> 1.67)
391397
image_processing (>= 1.2)
398+
json-schema (~> 5.1)
392399
lograge (~> 0.14.0)
393400
pg (~> 1.1)
394401
pry (~> 0.14.2)

app/graphql/mutations/namespaces/projects/flows/create.rb

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,39 @@ class Create < BaseMutation
99

1010
field :flow, Types::FlowType, null: true, description: 'The newly created flow.'
1111

12+
argument :project_id, Types::GlobalIdType[NamespaceProject], required: true,
13+
description: 'The ID of the project to which the flow belongs to'
14+
1215
argument :flow, Types::Input::FlowInputType
1316

14-
def resolve(namespace_id:, **params)
15-
# TODO
17+
def resolve(project_id:, flow:, **params)
18+
create_params = {}
19+
20+
21+
project = SagittariusSchema.object_from_id(project_id)
22+
23+
if project.nil?
24+
return error('Invalid project id')
25+
end
26+
27+
input_type = SagittariusSchema.object_from_id(flow.input_type)
28+
29+
if input_type.nil?
30+
return error('Invalid input type id')
31+
end
32+
33+
34+
35+
36+
37+
38+
end
39+
40+
def error(message)
41+
{
42+
flow: nil,
43+
errors: [create_message_error(message)]
44+
}
1645
end
1746
end
1847
end

app/graphql/sagittarius_schema.rb

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,15 @@ def self.object_from_id(global_id, query_ctx = nil)
5151
rescue ActiveRecord::RecordNotFound
5252
nil
5353
end
54+
55+
def self.object_from_id_or_error(global_id)
56+
obj = object_from_id(global_id)
57+
if obj.nil?
58+
59+
end
60+
obj
61+
end
62+
5463
# rubocop:enable Lint/UnusedMethodArgument
5564
end
5665
# rubocop:enable GraphQL/MaxDepthSchema

app/graphql/types/base_input_object.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,9 @@
33
module Types
44
class BaseInputObject < GraphQL::Schema::InputObject
55
argument_class Types::BaseArgument
6+
7+
def self.require_one_of(arguments)
8+
validates required: { one_of: arguments, message: "Only one of #{arguments.inspect} should be provided" }
9+
end
610
end
711
end

app/graphql/types/input/flow_input_type.rb

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,16 @@ module Input
55
class FlowInputType < Types::BaseInputObject
66
description 'Input type for creating or updating a flow'
77

8-
argument :input_type_id, ID, required: false,
9-
description: 'The ID of the input data type'
10-
argument :return_type_id, ID, required: false,
11-
description: 'The ID of the return data type'
8+
argument :input_type, Types::GlobalIdType[::DataType], required: false,
9+
description: 'The ID of the input data type'
10+
argument :return_type, Types::GlobalIdType[::DataType], required: false,
11+
description: 'The ID of the return data type'
1212
argument :settings, [Types::Input::FlowSettingInputType], required: false,
13-
description: 'The settings of the flow'
13+
description: 'The settings of the flow'
1414
argument :starting_node, Types::Input::NodeFunctionInputType, required: true,
15-
description: 'The starting node of the flow'
16-
argument :type, String, required: true,
17-
description: 'The identifier of the flow type'
15+
description: 'The starting node of the flow'
16+
argument :type, Types::GlobalIdType[::FlowType], required: true,
17+
description: 'The identifier of the flow type'
1818
end
1919
end
2020
end

app/graphql/types/input/flow_setting_input_type.rb

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,10 @@ module Input
55
class FlowSettingInputType < Types::BaseInputObject
66
description 'Input type for flow settings'
77

8-
argument :value, GraphQL::Types::JSON, required: true,
8+
argument :flow_setting_id, String, required: true,
9+
description: 'The identifier of the flow setting'
10+
11+
argument :object, GraphQL::Types::JSON, required: true,
912
description: 'The value of the flow setting'
1013
end
1114
end

app/graphql/types/input/node_function_definition_input_type.rb

Lines changed: 0 additions & 14 deletions
This file was deleted.

app/graphql/types/input/node_function_input_type.rb

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,9 @@ module Input
55
class NodeFunctionInputType < Types::BaseInputObject
66
description 'Input type for a Node Function'
77

8-
argument :function, Types::Input::NodeFunctionDefinitionInputType, required: true,
9-
description: 'The definition of the Node Function'
8+
argument :runtime_function_id, Types::GlobalIdType[::RuntimeFunctionDefinition],
9+
required: true, description: 'The identifier of the Runtime Function Definition'
10+
1011
argument :next_node, Types::Input::NodeFunctionInputType, required: false,
1112
description: 'The next Node Function in the flow'
1213
argument :parameters, [Types::Input::NodeParameterInputType], required: true,

app/graphql/types/input/node_parameter_definition_input_type.rb

Lines changed: 0 additions & 14 deletions
This file was deleted.

app/graphql/types/input/node_parameter_input_type.rb

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,9 @@ module Input
55
class NodeParameterInputType < Types::BaseInputObject
66
description 'Input type for Node parameter'
77

8-
argument :definition, Types::Input::NodeParameterDefinitionInputType, required: true,
9-
description: 'The definition of the parameter'
8+
argument :runtime_parameter_definition_id, Types::GlobalIdType[::RuntimeParameterDefinition],
9+
required: true, description: 'The identifier of the Runtime Parameter Definition'
10+
1011
argument :value, Types::Input::NodeParameterValueInputType, required: false,
1112
description: 'The value of the parameter'
1213
end

app/graphql/types/input/node_parameter_value_input_type.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@ class NodeParameterValueInputType < Types::BaseInputObject
1111
description: 'The literal value of the parameter'
1212
argument :reference_value, Types::Input::ReferenceValueInputType, required: false,
1313
description: 'The reference value of the parameter'
14+
15+
require_one_of %i[function_value literal_value reference_value]
16+
17+
1418
end
1519
end
1620
end

app/models/data_type_rule.rb

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,23 @@ class DataTypeRule < ApplicationRecord
99
regex: 5,
1010
}.with_indifferent_access
1111

12-
enum :variant, VARIANTS, prefix: :types
12+
enum :variant, VARIANTS, prefix: :variant
1313

1414
belongs_to :data_type, inverse_of: :rules
1515

1616
validates :variant, presence: true,
17-
inclusion: {
18-
in: VARIANTS.keys.map(&:to_s),
19-
}
17+
inclusion: {
18+
in: VARIANTS.keys.map(&:to_s),
19+
}
20+
21+
validates :config, if: :variant_contains_key?, 'sagittarius/validators/json_schema': { filename: 'data_types/DataTypeContainsKeyRuleConfig', hash_conversion: true }
22+
23+
validates :config, if: :variant_contains_type?, 'sagittarius/validators/json_schema': { filename: 'data_types/DataTypeContainsTypeRuleConfig', hash_conversion: true }
24+
25+
validates :config, if: :variant_item_of_collection?, 'sagittarius/validators/json_schema': { filename: 'data_types/DataTypeItemOfCollectionRuleConfig', hash_conversion: true }
26+
27+
validates :config, if: :variant_number_range?, 'sagittarius/validators/json_schema': { filename: 'data_types/DataTypeNumberRangeRuleConfig', hash_conversion: true }
28+
29+
validates :config, if: :variant_regex?, 'sagittarius/validators/json_schema': { filename: 'data_types/DataTypeRegexRuleConfig', hash_conversion: true }
30+
2031
end

app/models/json_schemas/DataTypeContainsKeyRuleConfig.json:Zone.Identifier

Whitespace-only changes.

app/models/json_schemas/DataTypeContainsTypeRuleConfig.json:Zone.Identifier

Whitespace-only changes.
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
{
2+
"$schema": "http://json-schema.org/draft-04/schema#",
3+
"$id": "https://example.com/schemas/DataTypeIdentifier.json",
4+
"title": "DataTypeIdentifier",
5+
"type": "object",
6+
"oneOf": [
7+
{
8+
"required": ["data_type_identifier"],
9+
"properties": {
10+
"data_type_identifier": {
11+
"type": "string"
12+
}
13+
}
14+
},
15+
{
16+
"required": ["generic_type"],
17+
"properties": {
18+
"generic_type": {
19+
"$ref": "GenericType.json"
20+
}
21+
}
22+
},
23+
{
24+
"required": ["generic_key"],
25+
"properties": {
26+
"generic_key": {
27+
"type": "string"
28+
}
29+
}
30+
}
31+
]
32+
}

app/models/json_schemas/DataTypeIdentifier.json:Zone.Identifier

Whitespace-only changes.

app/models/json_schemas/DataTypeItemOfCollectionRuleConfig.json:Zone.Identifier

Whitespace-only changes.

app/models/json_schemas/DataTypeNumberRangeRuleConfig.json:Zone.Identifier

Whitespace-only changes.

app/models/json_schemas/DataTypeRegexRuleConfig.json:Zone.Identifier

Whitespace-only changes.
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{
2+
"$schema": "http://json-schema.org/draft-04/schema#",
3+
"$id": "https://example.com/schemas/GenericMapper.json",
4+
"title": "GenericMapper",
5+
"type": "object",
6+
"required": ["source", "target"],
7+
"properties": {
8+
"source": {
9+
"$ref": "DataTypeIdentifier.json"
10+
},
11+
"target": {
12+
"type": "string"
13+
}
14+
}
15+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
{
2+
"$schema": "http://json-schema.org/draft-04/schema#",
3+
"$id": "https://example.com/schemas/GenericType.json",
4+
"title": "GenericType",
5+
"type": "object",
6+
"required": ["data_type_identifier", "generic_mappers"],
7+
"properties": {
8+
"data_type_identifier": {
9+
"type": "string"
10+
},
11+
"generic_mappers": {
12+
"type": "array",
13+
"items": {
14+
"$ref": "GenericMapper.json"
15+
}
16+
}
17+
}
18+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{
2+
"$schema": "http://json-schema.org/draft-04/schema#",
3+
"$id": "https://example.com/schemas/DataTypeContainsKeyRuleConfig.json",
4+
"title": "DataTypeContainsKeyRuleConfig",
5+
"type": "object",
6+
"required": ["key", "data_type_identifier"],
7+
"properties": {
8+
"key": {
9+
"type": "string"
10+
},
11+
"data_type_identifier": {
12+
"$ref": "../DataTypeIdentifier.json"
13+
}
14+
}
15+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"$schema": "http://json-schema.org/draft-04/schema#",
3+
"title": "DataTypeContainsTypeRuleConfig",
4+
"type": "object",
5+
"required": ["data_type_identifier"],
6+
"properties": {
7+
"data_type_identifier": { "$ref": "../DataTypeIdentifier.json" }
8+
}
9+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{
2+
"$schema": "http://json-schema.org/draft-04/schema#",
3+
"title": "DataTypeItemOfCollectionRuleConfig",
4+
"type": "object",
5+
"required": [
6+
"items"
7+
],
8+
"properties": {
9+
"items": {
10+
"type": "array",
11+
"items": {}
12+
}
13+
}
14+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"$schema": "http://json-schema.org/draft-04/schema#",
3+
"title": "DataTypeNumberRangeRuleConfig",
4+
"type": "object",
5+
"required": ["from", "to"],
6+
"properties": {
7+
"from": { "type": "integer" },
8+
"to": { "type": "integer" },
9+
"steps": { "type": "integer" }
10+
}
11+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{
2+
"$schema": "http://json-schema.org/draft-04/schema#",
3+
"title": "DataTypeRegexRuleConfig",
4+
"type": "object",
5+
"required": [
6+
"pattern"
7+
],
8+
"properties": {
9+
"pattern": {
10+
"type": "string"
11+
}
12+
}
13+
}

app/models/node_function.rb

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,21 @@ class NodeFunction < ApplicationRecord
66

77
has_many :node_parameters, inverse_of: :function_value
88

9+
10+
validate :validate_recursion, if: :next_node_changed?
11+
12+
def validate_recursion
13+
current_node = self
14+
until current_node.next_node.nil?
15+
current_node = current_node.next_node
16+
17+
if current_node == self
18+
errors.add(:next_node, :recursion)
19+
break
20+
end
21+
end
22+
end
23+
924
def to_grpc
1025
Tucana::NodeFunction.new(
1126
data_base_id: id,

0 commit comments

Comments
 (0)