Skip to content

Commit 967667e

Browse files
authored
Merge pull request #611 from code0-tech/add-parent-type-rule-to-graphql
Add parent type rule to GraphQL schema
2 parents 268a2bd + b011dc1 commit 967667e

16 files changed

+52
-19
lines changed

app/graphql/types/data_type_rule_type.rb

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ module Types
44
class DataTypeRuleType < Types::BaseObject
55
description 'Represents a rule that can be applied to a data type.'
66

7+
authorize :read_datatype
8+
79
field :variant, Types::DataTypeRules::VariantEnum, null: false, description: 'The type of the rule'
810

911
field :config, Types::DataTypeRules::ConfigType, null: false,
@@ -12,8 +14,16 @@ class DataTypeRuleType < Types::BaseObject
1214
id_field ::DataTypeRule
1315
timestamps
1416

17+
def variant
18+
object.variant.to_sym
19+
end
20+
1521
def config
16-
object.config.merge(variant: object.variant)
22+
if object.variant_parent_type?
23+
object
24+
else
25+
object.config.merge(variant: object.variant)
26+
end
1727
end
1828
end
1929
end

app/graphql/types/data_type_rules/config_type.rb

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@ class ConfigType < Types::BaseUnion
66
description 'Represents a rule that can be applied to a data type.'
77

88
possible_types ContainsKeyConfigType, ContainsTypeConfigType, NumberRangeConfigType, ItemOfCollectionConfigType,
9-
RegexConfigType, InputTypesConfigType, ReturnTypeConfigType
9+
RegexConfigType, InputTypesConfigType, ReturnTypeConfigType, ParentTypeConfigType
1010

1111
def self.resolve_type(object, _context)
12-
case object[:variant]
12+
case object[:variant].to_sym
1313
when :contains_key
1414
Types::DataTypeRules::ContainsKeyConfigType
1515
when :contains_type
@@ -24,6 +24,8 @@ def self.resolve_type(object, _context)
2424
Types::DataTypeRules::InputTypesConfigType
2525
when :return_type
2626
Types::DataTypeRules::ReturnTypeConfigType
27+
when :parent_type
28+
Types::DataTypeRules::ParentTypeConfigType
2729
else
2830
raise GraphQL::ExecutionError, "Unknown data type rule variant: #{object[:variant]}"
2931
end

app/graphql/types/data_type_rules/contains_key_config_type.rb

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@ module DataTypeRules
55
class ContainsKeyConfigType < Types::BaseObject
66
description 'Represents a rule that can be applied to a data type.'
77

8-
authorize :read_datatype
9-
108
field :data_type_identifier, Types::DataTypeIdentifierType,
119
null: false, description: 'The identifier of the data type this rule belongs to'
1210
field :key, String, null: false, description: 'The key of the rule'

app/graphql/types/data_type_rules/contains_type_config_type.rb

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@ module DataTypeRules
55
class ContainsTypeConfigType < Types::BaseObject
66
description 'Represents a rule that can be applied to a data type.'
77

8-
authorize :read_datatype
9-
108
field :data_type_identifier, Types::DataTypeIdentifierType,
119
null: false, description: 'The identifier of the data type this rule belongs to'
1210
end

app/graphql/types/data_type_rules/input_type_config_type.rb

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@ module DataTypeRules
55
class InputTypeConfigType < Types::BaseObject
66
description 'Represents a subtype of input type configuration for a input data type.'
77

8-
authorize :read_datatype
9-
108
field :data_type_identifier, Types::DataTypeIdentifierType,
119
null: false, description: 'The identifier of the data type this input type belongs to'
1210

app/graphql/types/data_type_rules/input_types_config_type.rb

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@ module DataTypeRules
55
class InputTypesConfigType < Types::BaseObject
66
description 'Represents a rule that can be applied to a data type.'
77

8-
authorize :read_datatype
9-
108
field :input_types, [Types::DataTypeRules::InputTypeConfigType],
119
null: false, description: 'The input types that can be used in this data type rule'
1210
end

app/graphql/types/data_type_rules/item_of_collection_config_type.rb

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@ module DataTypeRules
55
class ItemOfCollectionConfigType < Types::BaseObject
66
description 'Represents a rule that can be applied to a data type.'
77

8-
authorize :read_datatype
9-
108
field :items, [GraphQL::Types::JSON], null: true,
119
description: 'The items that can be configured for this rule.'
1210
end

app/graphql/types/data_type_rules/number_range_config_type.rb

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@ module DataTypeRules
55
class NumberRangeConfigType < Types::BaseObject
66
description 'Represents a rule that can be applied to a data type.'
77

8-
authorize :read_datatype
9-
108
field :from, Integer, null: false,
119
description: 'The minimum value of the range'
1210
field :steps, Integer, null: true,
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# frozen_string_literal: true
2+
3+
module Types
4+
module DataTypeRules
5+
class ParentTypeConfigType < Types::BaseObject
6+
description 'Represents a rule that can be applied to a data type.'
7+
8+
field :data_type_identifier, Types::DataTypeIdentifierType,
9+
null: false, description: 'The data type identifier for the parent type.'
10+
11+
def data_type_identifier
12+
object.data_type.parent_type
13+
end
14+
end
15+
end
16+
end

app/graphql/types/data_type_rules/regex_config_type.rb

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@ module DataTypeRules
55
class RegexConfigType < Types::BaseObject
66
description 'Represents a rule that can be applied to a data type.'
77

8-
authorize :read_datatype
9-
108
field :pattern, String, null: false,
119
description: 'The regex pattern to match against the data type value.'
1210
end

0 commit comments

Comments
 (0)