Skip to content

Commit f91466f

Browse files
authored
Merge pull request #523 from code0-tech/420-flow-type-structure-fixes
Flow type structure fixes
2 parents 5cf0132 + 97a66cb commit f91466f

Some content is hidden

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

57 files changed

+220
-128
lines changed
Lines changed: 10 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,18 @@
11
# frozen_string_literal: true
22

33
module Types
4-
class DataTypeIdentifierType < Types::BaseUnion
4+
class DataTypeIdentifierType < Types::BaseObject
55
description 'Represents a data type identifier.'
66

7-
possible_types Types::GenericTypeType, Types::DataTypeType, Types::GenericKeyType,
8-
description: 'The identifier can be a generic type, a data type, or a generic key.'
7+
field :data_type, Types::DataTypeType, null: true, description: 'The data type of the data type identifier.'
98

10-
def self.resolve_type(object, _context)
11-
case object
12-
when GenericType
13-
Types::GenericTypeType
14-
when DataType
15-
Types::DataTypeType
16-
when GenericKey
17-
Types::GenericKeyType
18-
else
19-
raise "Unexpected value type: #{object.class}"
20-
end
21-
end
9+
# rubocop:disable GraphQL/ExtractType -- generic_key and generic_type don't have anything in common
10+
field :generic_key, String, null: true, description: 'The generic key of the data type identifier.'
11+
field :generic_type, Types::GenericTypeType, null: true,
12+
description: 'The generic type of the data type identifier.'
13+
# rubocop:enable GraphQL/ExtractType
14+
15+
id_field DataTypeIdentifier
16+
timestamps
2217
end
2318
end

app/graphql/types/data_type_rule_type.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ class DataTypeRuleType < Types::BaseObject
1010
field :config, Types::DataTypeRules::ConfigType, null: false,
1111
description: 'The configuration of the rule'
1212

13+
id_field ::DataTypeRule
1314
timestamps
1415

1516
def config

app/graphql/types/data_type_rules/config_type.rb

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,22 +6,26 @@ 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
9+
RegexConfigType, InputTypesConfigType, ReturnTypeConfigType
1010

1111
def self.resolve_type(object, _context)
1212
case object[:variant]
1313
when :contains_key
14-
Types::DataTypeRuleContainsKeyType
14+
Types::DataTypeRules::ContainsKeyConfigType
1515
when :contains_type
16-
Types::DataTypeRuleContainsTypeType
16+
Types::DataTypeRules::ContainsTypeConfigType
1717
when :number_range
18-
Types::DataTypeRuleNumberRangeType
18+
Types::DataTypeRules::NumberRangeConfigType
1919
when :item_of_collection
20-
Types::DataTypeRuleItemOfCollectionType
20+
Types::DataTypeRules::ItemOfCollectionConfigType
2121
when :regex
22-
Types::DataTypeRuleRegexType
22+
Types::DataTypeRules::RegexConfigType
23+
when :input_types
24+
Types::DataTypeRules::InputTypesConfigType
25+
when :return_type
26+
Types::DataTypeRules::ReturnTypeConfigType
2327
else
24-
raise GraphQL::ExecutionError, "Unknown data type rule variant: #{object.variant}"
28+
raise GraphQL::ExecutionError, "Unknown data type rule variant: #{object[:variant]}"
2529
end
2630
end
2731
end

app/graphql/types/data_type_rules/contains_key_config_type.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ module DataTypeRules
55
class ContainsKeyConfigType < Types::BaseObject
66
description 'Represents a rule that can be applied to a data type.'
77

8-
authorize :read_flow
8+
authorize :read_datatype
99

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

app/graphql/types/data_type_rules/contains_type_config_type.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ module DataTypeRules
55
class ContainsTypeConfigType < Types::BaseObject
66
description 'Represents a rule that can be applied to a data type.'
77

8-
authorize :read_flow
8+
authorize :read_datatype
99

1010
field :data_type_identifier, Types::DataTypeIdentifierType,
1111
null: false, description: 'The identifier of the data type this rule belongs to'
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# frozen_string_literal: true
2+
3+
module Types
4+
module DataTypeRules
5+
class InputTypeConfigType < Types::BaseObject
6+
description 'Represents a subtype of input type configuration for a input data type.'
7+
8+
authorize :read_datatype
9+
10+
field :data_type_identifier, Types::DataTypeIdentifierType,
11+
null: false, description: 'The identifier of the data type this input type belongs to'
12+
13+
field :input_type, Types::DataTypeType,
14+
null: false, description: 'The input data type that this configuration applies to'
15+
end
16+
end
17+
end

app/graphql/types/data_type_rules/input_types_config_type.rb

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,10 @@ module DataTypeRules
55
class InputTypesConfigType < Types::BaseObject
66
description 'Represents a rule that can be applied to a data type.'
77

8-
authorize :read_flow
8+
authorize :read_datatype
9+
10+
field :input_types, [Types::DataTypeRules::InputTypeConfigType],
11+
null: false, description: 'The input types that can be used in this data type rule'
912
end
1013
end
1114
end

app/graphql/types/data_type_rules/item_of_collection_config_type.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ module DataTypeRules
55
class ItemOfCollectionConfigType < Types::BaseObject
66
description 'Represents a rule that can be applied to a data type.'
77

8-
authorize :read_flow
8+
authorize :read_datatype
99

1010
field :items, [GraphQL::Types::JSON], null: true,
1111
description: 'The items that can be configured for this rule.'

app/graphql/types/data_type_rules/number_range_config_type.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ module DataTypeRules
55
class NumberRangeConfigType < Types::BaseObject
66
description 'Represents a rule that can be applied to a data type.'
77

8-
authorize :read_flow
8+
authorize :read_datatype
99

1010
field :from, Integer, null: false,
1111
description: 'The minimum value of the range'

app/graphql/types/data_type_rules/regex_config_type.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ module DataTypeRules
55
class RegexConfigType < Types::BaseObject
66
description 'Represents a rule that can be applied to a data type.'
77

8-
authorize :read_flow
8+
authorize :read_datatype
99

1010
field :pattern, String, null: false,
1111
description: 'The regex pattern to match against the data type value.'

0 commit comments

Comments
 (0)