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
12 changes: 11 additions & 1 deletion app/graphql/types/data_type_rule_type.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ module Types
class DataTypeRuleType < Types::BaseObject
description 'Represents a rule that can be applied to a data type.'

authorize :read_datatype

field :variant, Types::DataTypeRules::VariantEnum, null: false, description: 'The type of the rule'

field :config, Types::DataTypeRules::ConfigType, null: false,
Expand All @@ -12,8 +14,16 @@ class DataTypeRuleType < Types::BaseObject
id_field ::DataTypeRule
timestamps

def variant
object.variant.to_sym
end

def config
object.config.merge(variant: object.variant)
if object.variant_parent_type?
object
else
object.config.merge(variant: object.variant)
end
end
end
end
6 changes: 4 additions & 2 deletions app/graphql/types/data_type_rules/config_type.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ class ConfigType < Types::BaseUnion
description 'Represents a rule that can be applied to a data type.'

possible_types ContainsKeyConfigType, ContainsTypeConfigType, NumberRangeConfigType, ItemOfCollectionConfigType,
RegexConfigType, InputTypesConfigType, ReturnTypeConfigType
RegexConfigType, InputTypesConfigType, ReturnTypeConfigType, ParentTypeConfigType

def self.resolve_type(object, _context)
case object[:variant]
case object[:variant].to_sym
when :contains_key
Types::DataTypeRules::ContainsKeyConfigType
when :contains_type
Expand All @@ -24,6 +24,8 @@ def self.resolve_type(object, _context)
Types::DataTypeRules::InputTypesConfigType
when :return_type
Types::DataTypeRules::ReturnTypeConfigType
when :parent_type
Types::DataTypeRules::ParentTypeConfigType
else
raise GraphQL::ExecutionError, "Unknown data type rule variant: #{object[:variant]}"
end
Expand Down
2 changes: 0 additions & 2 deletions app/graphql/types/data_type_rules/contains_key_config_type.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ module DataTypeRules
class ContainsKeyConfigType < Types::BaseObject
description 'Represents a rule that can be applied to a data type.'

authorize :read_datatype

field :data_type_identifier, Types::DataTypeIdentifierType,
null: false, description: 'The identifier of the data type this rule belongs to'
field :key, String, null: false, description: 'The key of the rule'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ module DataTypeRules
class ContainsTypeConfigType < Types::BaseObject
description 'Represents a rule that can be applied to a data type.'

authorize :read_datatype

field :data_type_identifier, Types::DataTypeIdentifierType,
null: false, description: 'The identifier of the data type this rule belongs to'
end
Expand Down
2 changes: 0 additions & 2 deletions app/graphql/types/data_type_rules/input_type_config_type.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ module DataTypeRules
class InputTypeConfigType < Types::BaseObject
description 'Represents a subtype of input type configuration for a input data type.'

authorize :read_datatype

field :data_type_identifier, Types::DataTypeIdentifierType,
null: false, description: 'The identifier of the data type this input type belongs to'

Expand Down
2 changes: 0 additions & 2 deletions app/graphql/types/data_type_rules/input_types_config_type.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ module DataTypeRules
class InputTypesConfigType < Types::BaseObject
description 'Represents a rule that can be applied to a data type.'

authorize :read_datatype

field :input_types, [Types::DataTypeRules::InputTypeConfigType],
null: false, description: 'The input types that can be used in this data type rule'
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ module DataTypeRules
class ItemOfCollectionConfigType < Types::BaseObject
description 'Represents a rule that can be applied to a data type.'

authorize :read_datatype

field :items, [GraphQL::Types::JSON], null: true,
description: 'The items that can be configured for this rule.'
end
Expand Down
2 changes: 0 additions & 2 deletions app/graphql/types/data_type_rules/number_range_config_type.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ module DataTypeRules
class NumberRangeConfigType < Types::BaseObject
description 'Represents a rule that can be applied to a data type.'

authorize :read_datatype

field :from, Integer, null: false,
description: 'The minimum value of the range'
field :steps, Integer, null: true,
Expand Down
16 changes: 16 additions & 0 deletions app/graphql/types/data_type_rules/parent_type_config_type.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# frozen_string_literal: true

module Types
module DataTypeRules
class ParentTypeConfigType < Types::BaseObject
description 'Represents a rule that can be applied to a data type.'

field :data_type_identifier, Types::DataTypeIdentifierType,
null: false, description: 'The data type identifier for the parent type.'

def data_type_identifier
object.data_type.parent_type
end
end
end
end
2 changes: 0 additions & 2 deletions app/graphql/types/data_type_rules/regex_config_type.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ module DataTypeRules
class RegexConfigType < Types::BaseObject
description 'Represents a rule that can be applied to a data type.'

authorize :read_datatype

field :pattern, String, null: false,
description: 'The regex pattern to match against the data type value.'
end
Expand Down
2 changes: 0 additions & 2 deletions app/graphql/types/data_type_rules/return_type_config_type.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ module DataTypeRules
class ReturnTypeConfigType < Types::BaseObject
description 'Represents a rule that can be applied to a data type.'

authorize :read_datatype

field :data_type_identifier, Types::DataTypeIdentifierType,
null: false, description: 'The data type identifier for the return type.'
end
Expand Down
2 changes: 2 additions & 0 deletions app/graphql/types/data_type_rules/variant_enum.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ class VariantEnum < Types::BaseEnum
value: :input_type
value :RETURN_TYPE, 'The rule checks if the data type matches a specific return type.',
value: :return_type
value :PARENT_TYPE, 'The rule checks if the data type is a child of a specific parent type.',
value: :parent_type
end
end
end
5 changes: 5 additions & 0 deletions app/policies/data_type_rule_policy.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# frozen_string_literal: true

class DataTypeRulePolicy < BasePolicy
delegate { subject.data_type }
end
1 change: 1 addition & 0 deletions docs/graphql/enum/datatyperulesvariant.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,6 @@ The type of rule that can be applied to a data type.
| `INPUT_TYPE` | The rule checks if the data type matches a specific input type. |
| `ITEM_OF_COLLECTION` | The rule checks if an item is part of a collection in the data type. |
| `NUMBER_RANGE` | The rule checks if a number falls within a specified range. |
| `PARENT_TYPE` | The rule checks if the data type is a child of a specific parent type. |
| `REGEX` | The rule checks if a string matches a specified regular expression. |
| `RETURN_TYPE` | The rule checks if the data type matches a specific return type. |
12 changes: 12 additions & 0 deletions docs/graphql/object/datatyperulesparenttypeconfig.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
---
title: DataTypeRulesParentTypeConfig
---

Represents a rule that can be applied to a data type.

## Fields without arguments

| Name | Type | Description |
|------|------|-------------|
| `dataTypeIdentifier` | [`DataTypeIdentifier!`](../object/datatypeidentifier.md) | The data type identifier for the parent type. |

1 change: 1 addition & 0 deletions docs/graphql/union/datatyperulesconfig.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,6 @@ Represents a rule that can be applied to a data type.
- [`DataTypeRulesInputTypesConfig`](../object/datatyperulesinputtypesconfig.md)
- [`DataTypeRulesItemOfCollectionConfig`](../object/datatyperulesitemofcollectionconfig.md)
- [`DataTypeRulesNumberRangeConfig`](../object/datatyperulesnumberrangeconfig.md)
- [`DataTypeRulesParentTypeConfig`](../object/datatyperulesparenttypeconfig.md)
- [`DataTypeRulesRegexConfig`](../object/datatyperulesregexconfig.md)
- [`DataTypeRulesReturnTypeConfig`](../object/datatyperulesreturntypeconfig.md)