graphql_rails 1.2.4 → 2.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/ruby.yml +18 -0
- data/.hound.yml +1 -1
- data/.rubocop.yml +4 -0
- data/.ruby-version +1 -1
- data/CHANGELOG.md +21 -0
- data/Gemfile +3 -3
- data/Gemfile.lock +129 -128
- data/docs/README.md +1 -1
- data/docs/components/model.md +107 -13
- data/docs/components/routes.md +4 -3
- data/docs/other_tools/schema_dump.md +8 -8
- data/lib/graphql_rails/attributes/attributable.rb +6 -14
- data/lib/graphql_rails/attributes/attribute.rb +10 -34
- data/lib/graphql_rails/attributes/attribute_configurable.rb +45 -0
- data/lib/graphql_rails/attributes/attribute_name_parser.rb +7 -7
- data/lib/graphql_rails/attributes/input_attribute.rb +20 -14
- data/lib/graphql_rails/attributes/input_type_parser.rb +5 -7
- data/lib/graphql_rails/attributes/type_parseable.rb +49 -19
- data/lib/graphql_rails/attributes/type_parser.rb +4 -9
- data/lib/graphql_rails/concerns/chainable_options.rb +49 -0
- data/lib/graphql_rails/controller/build_controller_action_resolver/controller_action_resolver.rb +3 -0
- data/lib/graphql_rails/controller/log_controller_action.rb +7 -2
- data/lib/graphql_rails/decorator/relation_decorator.rb +2 -2
- data/lib/graphql_rails/input_configurable.rb +11 -9
- data/lib/graphql_rails/model/build_graphql_input_type.rb +4 -2
- data/lib/graphql_rails/model/configurable.rb +30 -8
- data/lib/graphql_rails/model/configuration.rb +8 -12
- data/lib/graphql_rails/model/find_or_build_graphql_type.rb +16 -19
- data/lib/graphql_rails/model/find_or_build_graphql_type_class.rb +2 -1
- data/lib/graphql_rails/model/input.rb +10 -26
- data/lib/graphql_rails/query_runner.rb +9 -3
- data/lib/graphql_rails/router/mutation_route.rb +4 -0
- data/lib/graphql_rails/router/query_route.rb +4 -0
- data/lib/graphql_rails/router/resource_routes_builder.rb +8 -0
- data/lib/graphql_rails/router/route.rb +2 -2
- data/lib/graphql_rails/router/schema_builder.rb +12 -3
- data/lib/graphql_rails/router/subscription_route.rb +22 -0
- data/lib/graphql_rails/router.rb +8 -2
- data/lib/graphql_rails/tasks/dump_graphql_schema.rb +18 -27
- data/lib/graphql_rails/tasks/dump_graphql_schemas.rb +57 -0
- data/lib/graphql_rails/tasks/schema.rake +8 -5
- data/lib/graphql_rails/types/argument_type.rb +12 -0
- data/lib/graphql_rails/types/field_type.rb +14 -0
- data/lib/graphql_rails/types/hidable_by_group.rb +32 -0
- data/lib/graphql_rails/types/object_type.rb +12 -0
- data/lib/graphql_rails/version.rb +1 -1
- metadata +16 -8
- data/.travis.yml +0 -5
@@ -6,24 +6,24 @@ GraphqlRails includes rake task to allow creating schema snapshots easier:
|
|
6
6
|
rake graphql_rails:schema:dump
|
7
7
|
```
|
8
8
|
|
9
|
-
## Dumping
|
9
|
+
## Dumping only selected schema groups
|
10
10
|
|
11
|
-
You can
|
11
|
+
You can specify which schema groups you want to dump. In order to do so, provide groups list as rake task argument and separate group names by comma:
|
12
12
|
|
13
13
|
```bash
|
14
|
-
rake graphql_rails:schema:dump['your_group_name']
|
14
|
+
rake graphql_rails:schema:dump['your_group_name, your_group_name2']
|
15
15
|
```
|
16
16
|
|
17
|
-
|
17
|
+
You can do this also by using ENV variable `SCHEMA_GROUP_NAME`:
|
18
18
|
|
19
19
|
```bash
|
20
|
-
SCHEMA_GROUP_NAME=your_group_name rake graphql_rails:schema:dump
|
20
|
+
SCHEMA_GROUP_NAME="your_group_name, your_group_name2" rake graphql_rails:schema:dump
|
21
21
|
```
|
22
22
|
|
23
|
-
## Dumping schema in to non default
|
23
|
+
## Dumping schema in to non default folder
|
24
24
|
|
25
|
-
By default schema will be dumped to `spec/fixtures
|
25
|
+
By default schema will be dumped to `spec/fixtures` directory. If you want different schema path, add `GRAPHQL_SCHEMA_DUMP_DIR` env variable, like this:
|
26
26
|
|
27
27
|
```bash
|
28
|
-
|
28
|
+
GRAPHQL_SCHEMA_DUMP_DIR='path/to/graphql/dumps' rake graphql_rails:schema:dump
|
29
29
|
```
|
@@ -6,14 +6,14 @@ require 'graphql_rails/attributes/attribute_name_parser'
|
|
6
6
|
module GraphqlRails
|
7
7
|
module Attributes
|
8
8
|
# contains methods which are shared between various attribute-like classes
|
9
|
-
# expects `initial_name` and `
|
9
|
+
# expects `initial_name` and `type` to be defined
|
10
10
|
module Attributable
|
11
11
|
def field_name
|
12
12
|
attribute_name_parser.field_name
|
13
13
|
end
|
14
14
|
|
15
15
|
def type_name
|
16
|
-
|
16
|
+
type.to_s
|
17
17
|
end
|
18
18
|
|
19
19
|
def name
|
@@ -23,17 +23,9 @@ module GraphqlRails
|
|
23
23
|
def required?
|
24
24
|
return @required unless @required.nil?
|
25
25
|
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
def required
|
30
|
-
@required = true
|
31
|
-
self
|
32
|
-
end
|
33
|
-
|
34
|
-
def optional
|
35
|
-
@required = false
|
36
|
-
self
|
26
|
+
(type.nil? && attribute_name_parser.required?) ||
|
27
|
+
type.to_s[/!$/].present? ||
|
28
|
+
type.is_a?(GraphQL::Schema::NonNull)
|
37
29
|
end
|
38
30
|
|
39
31
|
def graphql_model
|
@@ -52,7 +44,7 @@ module GraphqlRails
|
|
52
44
|
|
53
45
|
def type_parser
|
54
46
|
@type_parser ||= begin
|
55
|
-
type_for_parser =
|
47
|
+
type_for_parser = type || attribute_name_parser.graphql_type
|
56
48
|
TypeParser.new(type_for_parser, paginated: paginated?)
|
57
49
|
end
|
58
50
|
end
|
@@ -2,6 +2,7 @@
|
|
2
2
|
|
3
3
|
require 'graphql'
|
4
4
|
require 'graphql_rails/attributes/attributable'
|
5
|
+
require 'graphql_rails/attributes/attribute_configurable'
|
5
6
|
require 'graphql_rails/input_configurable'
|
6
7
|
|
7
8
|
module GraphqlRails
|
@@ -9,47 +10,21 @@ module GraphqlRails
|
|
9
10
|
# contains info about single graphql attribute
|
10
11
|
class Attribute
|
11
12
|
include Attributable
|
13
|
+
include AttributeConfigurable
|
12
14
|
include InputConfigurable
|
13
15
|
|
14
16
|
attr_reader :attributes
|
15
17
|
|
16
|
-
|
17
|
-
def initialize(name, type = nil, description: nil, property: name, required: nil, options: {})
|
18
|
-
@initial_type = type
|
18
|
+
def initialize(name)
|
19
19
|
@initial_name = name
|
20
|
-
@
|
21
|
-
@description = description
|
22
|
-
@property = property.to_s
|
23
|
-
@required = required
|
20
|
+
@property = name.to_s
|
24
21
|
@attributes ||= {}
|
25
22
|
end
|
26
|
-
# rubocop:enable Metrics/ParameterLists
|
27
23
|
|
28
|
-
def
|
29
|
-
return @
|
24
|
+
def property(new_value = NOT_SET)
|
25
|
+
return @property if new_value == NOT_SET
|
30
26
|
|
31
|
-
@
|
32
|
-
self
|
33
|
-
end
|
34
|
-
|
35
|
-
def description(new_description = nil)
|
36
|
-
return @description if new_description.nil?
|
37
|
-
|
38
|
-
@description = new_description
|
39
|
-
self
|
40
|
-
end
|
41
|
-
|
42
|
-
def property(new_property = nil)
|
43
|
-
return @property if new_property.nil?
|
44
|
-
|
45
|
-
@property = new_property.to_s
|
46
|
-
self
|
47
|
-
end
|
48
|
-
|
49
|
-
def options(new_options = {})
|
50
|
-
return @options if new_options.blank?
|
51
|
-
|
52
|
-
@options = new_options
|
27
|
+
@property = new_value.to_s
|
53
28
|
self
|
54
29
|
end
|
55
30
|
|
@@ -65,7 +40,8 @@ module GraphqlRails
|
|
65
40
|
{
|
66
41
|
method: property.to_sym,
|
67
42
|
null: optional?,
|
68
|
-
camelize: camelize
|
43
|
+
camelize: camelize?,
|
44
|
+
groups: groups
|
69
45
|
}
|
70
46
|
end
|
71
47
|
|
@@ -82,7 +58,7 @@ module GraphqlRails
|
|
82
58
|
|
83
59
|
protected
|
84
60
|
|
85
|
-
attr_reader :
|
61
|
+
attr_reader :initial_name
|
86
62
|
|
87
63
|
private
|
88
64
|
|
@@ -0,0 +1,45 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'graphql_rails/attributes/type_parser'
|
4
|
+
require 'graphql_rails/attributes/attribute_name_parser'
|
5
|
+
require 'graphql_rails/model/build_enum_type'
|
6
|
+
require 'graphql_rails/concerns/chainable_options'
|
7
|
+
require 'active_support/concern'
|
8
|
+
|
9
|
+
module GraphqlRails
|
10
|
+
module Attributes
|
11
|
+
# Allows to set or get various attribute parameters
|
12
|
+
module AttributeConfigurable
|
13
|
+
extend ActiveSupport::Concern
|
14
|
+
|
15
|
+
included do
|
16
|
+
include GraphqlRails::ChainableOptions
|
17
|
+
|
18
|
+
chainable_option :description
|
19
|
+
chainable_option :options, default: {}
|
20
|
+
chainable_option :type
|
21
|
+
end
|
22
|
+
|
23
|
+
def groups(new_groups = ChainableOptions::NOT_SET)
|
24
|
+
@groups ||= []
|
25
|
+
return @groups if new_groups == ChainableOptions::NOT_SET
|
26
|
+
|
27
|
+
@groups = Array(new_groups).map(&:to_s)
|
28
|
+
self
|
29
|
+
end
|
30
|
+
|
31
|
+
def group(*args)
|
32
|
+
groups(*args)
|
33
|
+
end
|
34
|
+
|
35
|
+
def required(new_value = true) # rubocop:disable Style/OptionalBooleanParameter
|
36
|
+
@required = new_value
|
37
|
+
self
|
38
|
+
end
|
39
|
+
|
40
|
+
def optional(new_value = true) # rubocop:disable Style/OptionalBooleanParameter
|
41
|
+
required(!new_value)
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
@@ -5,12 +5,8 @@ module GraphqlRails
|
|
5
5
|
# Parses attribute name and can generates graphql scalar type,
|
6
6
|
# grapqhl name and etc. based on that
|
7
7
|
class AttributeNameParser
|
8
|
-
attr_reader :name
|
9
|
-
|
10
8
|
def initialize(original_name, options: {})
|
11
|
-
|
12
|
-
@required = !name['!'].nil?
|
13
|
-
@name = name.tr('!', '')
|
9
|
+
@original_name = original_name.to_s
|
14
10
|
@options = options
|
15
11
|
end
|
16
12
|
|
@@ -36,12 +32,16 @@ module GraphqlRails
|
|
36
32
|
end
|
37
33
|
|
38
34
|
def required?
|
39
|
-
|
35
|
+
original_name['!'].present? || original_name.end_with?('?')
|
36
|
+
end
|
37
|
+
|
38
|
+
def name
|
39
|
+
@name ||= original_name.tr('!', '')
|
40
40
|
end
|
41
41
|
|
42
42
|
private
|
43
43
|
|
44
|
-
attr_reader :options
|
44
|
+
attr_reader :options, :original_name
|
45
45
|
|
46
46
|
def original_format?
|
47
47
|
options[:input_format] == :original || options[:attribute_name_format] == :original
|
@@ -4,22 +4,19 @@ module GraphqlRails
|
|
4
4
|
module Attributes
|
5
5
|
# contains info about single graphql input attribute
|
6
6
|
class InputAttribute
|
7
|
+
require 'graphql_rails/model/build_enum_type'
|
7
8
|
require_relative './input_type_parser'
|
8
9
|
require_relative './attribute_name_parser'
|
9
10
|
include Attributable
|
11
|
+
include AttributeConfigurable
|
10
12
|
|
11
|
-
|
13
|
+
chainable_option :subtype
|
14
|
+
chainable_option :enum
|
12
15
|
|
13
|
-
|
14
|
-
|
16
|
+
def initialize(name, config:)
|
17
|
+
@config = config
|
15
18
|
@initial_name = name
|
16
|
-
@initial_type = type
|
17
|
-
@description = description
|
18
|
-
@options = options
|
19
|
-
@subtype = subtype
|
20
|
-
@required = required
|
21
19
|
end
|
22
|
-
# rubocop:enable Metrics/ParameterLists
|
23
20
|
|
24
21
|
def input_argument_args
|
25
22
|
type = raw_input_type || input_type_parser.input_type_arg
|
@@ -28,7 +25,7 @@ module GraphqlRails
|
|
28
25
|
end
|
29
26
|
|
30
27
|
def input_argument_options
|
31
|
-
{ required: required?, description: description, camelize: false }
|
28
|
+
{ required: required?, description: description, camelize: false, groups: groups }
|
32
29
|
end
|
33
30
|
|
34
31
|
def paginated?
|
@@ -37,7 +34,7 @@ module GraphqlRails
|
|
37
34
|
|
38
35
|
private
|
39
36
|
|
40
|
-
attr_reader :initial_name, :
|
37
|
+
attr_reader :initial_name, :config
|
41
38
|
|
42
39
|
def attribute_name_parser
|
43
40
|
@attribute_name_parser ||= AttributeNameParser.new(
|
@@ -51,14 +48,23 @@ module GraphqlRails
|
|
51
48
|
|
52
49
|
def input_type_parser
|
53
50
|
@input_type_parser ||= begin
|
54
|
-
initial_parseable_type =
|
51
|
+
initial_parseable_type = type || enum_type || attribute_name_parser.graphql_type
|
55
52
|
InputTypeParser.new(initial_parseable_type, subtype: subtype)
|
56
53
|
end
|
57
54
|
end
|
58
55
|
|
56
|
+
def enum_type
|
57
|
+
return if enum.blank?
|
58
|
+
|
59
|
+
::GraphqlRails::Model::BuildEnumType.call(
|
60
|
+
"#{config.name}_#{initial_name}_enum",
|
61
|
+
allowed_values: enum
|
62
|
+
)
|
63
|
+
end
|
64
|
+
|
59
65
|
def raw_input_type
|
60
|
-
return
|
61
|
-
return
|
66
|
+
return type if type.is_a?(GraphQL::InputObjectType)
|
67
|
+
return type.graphql_input_type if type.is_a?(Model::Input)
|
62
68
|
end
|
63
69
|
end
|
64
70
|
end
|
@@ -15,12 +15,6 @@ module GraphqlRails
|
|
15
15
|
@subtype = subtype
|
16
16
|
end
|
17
17
|
|
18
|
-
def graphql_type
|
19
|
-
return nil if unparsed_type.nil?
|
20
|
-
|
21
|
-
partly_parsed_type || parsed_type
|
22
|
-
end
|
23
|
-
|
24
18
|
def input_type_arg
|
25
19
|
if list?
|
26
20
|
list_type_arg
|
@@ -34,7 +28,11 @@ module GraphqlRails
|
|
34
28
|
attr_reader :unparsed_type, :subtype
|
35
29
|
|
36
30
|
def unwrapped_type
|
37
|
-
raw_unwrapped_type ||
|
31
|
+
raw_unwrapped_type ||
|
32
|
+
unwrapped_scalar_type ||
|
33
|
+
unwrapped_model_input_type ||
|
34
|
+
graphql_type_object ||
|
35
|
+
raise_not_supported_type_error
|
38
36
|
end
|
39
37
|
|
40
38
|
def raw_unwrapped_type
|
@@ -16,18 +16,27 @@ module GraphqlRails
|
|
16
16
|
'int' => GraphQL::Types::Int,
|
17
17
|
'integer' => GraphQL::Types::Int,
|
18
18
|
|
19
|
+
'big_int' => GraphQL::Types::BigInt,
|
20
|
+
'bigint' => GraphQL::Types::BigInt,
|
21
|
+
|
22
|
+
'float' => GraphQL::Types::Float,
|
23
|
+
'double' => GraphQL::Types::Float,
|
24
|
+
'decimal' => GraphQL::Types::Float,
|
25
|
+
|
26
|
+
'bool' => GraphQL::Types::Boolean,
|
27
|
+
'boolean' => GraphQL::Types::Boolean,
|
28
|
+
|
19
29
|
'string' => GraphQL::Types::String,
|
20
30
|
'str' => GraphQL::Types::String,
|
21
31
|
'text' => GraphQL::Types::String,
|
22
|
-
'time' => GraphQL::Types::String,
|
23
|
-
'date' => GraphQL::Types::String,
|
24
32
|
|
25
|
-
'
|
26
|
-
'boolean' => GraphQL::Types::Boolean,
|
33
|
+
'date' => GraphQL::Types::ISO8601Date,
|
27
34
|
|
28
|
-
'
|
29
|
-
'
|
30
|
-
'
|
35
|
+
'time' => GraphQL::Types::ISO8601DateTime,
|
36
|
+
'datetime' => GraphQL::Types::ISO8601DateTime,
|
37
|
+
'date_time' => GraphQL::Types::ISO8601DateTime,
|
38
|
+
|
39
|
+
'json' => GraphQL::Types::JSON
|
31
40
|
}.freeze
|
32
41
|
|
33
42
|
WRAPPER_TYPES = [
|
@@ -46,7 +55,7 @@ module GraphqlRails
|
|
46
55
|
RAW_GRAPHQL_TYPES = (WRAPPER_TYPES + GRAPHQL_BASE_TYPES).freeze
|
47
56
|
|
48
57
|
def unwrapped_scalar_type
|
49
|
-
TYPE_MAPPING[nullable_inner_name.downcase
|
58
|
+
TYPE_MAPPING[nullable_inner_name.downcase]
|
50
59
|
end
|
51
60
|
|
52
61
|
def raw_graphql_type?
|
@@ -58,25 +67,46 @@ module GraphqlRails
|
|
58
67
|
end
|
59
68
|
|
60
69
|
def core_scalar_type?
|
61
|
-
unwrapped_scalar_type.
|
70
|
+
unwrapped_scalar_type.present?
|
62
71
|
end
|
63
72
|
|
64
73
|
def graphql_model
|
65
|
-
|
66
|
-
|
67
|
-
unparsed_type
|
68
|
-
else
|
69
|
-
nullable_inner_name.safe_constantize
|
70
|
-
end
|
71
|
-
|
72
|
-
return if type_class.nil?
|
73
|
-
return unless type_class < GraphqlRails::Model
|
74
|
+
extract_type_class_if { |type| graphql_model?(type) }
|
75
|
+
end
|
74
76
|
|
75
|
-
|
77
|
+
def graphql_type_object
|
78
|
+
type_object = extract_type_class_if { |type| graphql_type_object?(type) }
|
79
|
+
type_object || graphql_model&.graphql&.graphql_type
|
76
80
|
end
|
77
81
|
|
78
82
|
protected
|
79
83
|
|
84
|
+
def extract_type_class_if
|
85
|
+
return unparsed_type if yield(unparsed_type)
|
86
|
+
|
87
|
+
type_class = nullable_inner_name.safe_constantize
|
88
|
+
return type_class if yield(type_class)
|
89
|
+
|
90
|
+
nil
|
91
|
+
end
|
92
|
+
|
93
|
+
def graphql_model?(type_class)
|
94
|
+
type_class.is_a?(Class) && type_class < GraphqlRails::Model
|
95
|
+
end
|
96
|
+
|
97
|
+
def graphql_type_object?(type_class)
|
98
|
+
return false unless type_class.is_a?(Class)
|
99
|
+
|
100
|
+
type_class < GraphQL::Schema::Member
|
101
|
+
end
|
102
|
+
|
103
|
+
def applicable_graphql_type?(type)
|
104
|
+
return false unless type.is_a?(Class)
|
105
|
+
return true if type < GraphqlRails::Model
|
106
|
+
|
107
|
+
false
|
108
|
+
end
|
109
|
+
|
80
110
|
def unwrap_type(type)
|
81
111
|
unwrappable = type
|
82
112
|
unwrappable = unwrappable.of_type while wrapped_type?(unwrappable)
|
@@ -51,7 +51,9 @@ module GraphqlRails
|
|
51
51
|
def paginated_type_arg
|
52
52
|
return graphql_model.graphql.connection_type if graphql_model
|
53
53
|
|
54
|
-
|
54
|
+
error_message = "Unable to paginate #{unparsed_type.inspect}. " \
|
55
|
+
'Pagination is only supported for models which include GraphqlRails::Model'
|
56
|
+
raise NotSupportedFeature, error_message
|
55
57
|
end
|
56
58
|
|
57
59
|
def list_type_arg
|
@@ -107,14 +109,7 @@ module GraphqlRails
|
|
107
109
|
end
|
108
110
|
|
109
111
|
def type_by_name
|
110
|
-
unwrapped_scalar_type ||
|
111
|
-
end
|
112
|
-
|
113
|
-
def unwrapped_model_type
|
114
|
-
type_class = graphql_model
|
115
|
-
return unless type_class
|
116
|
-
|
117
|
-
type_class.graphql.graphql_type
|
112
|
+
unwrapped_scalar_type || graphql_type_object || raise_not_supported_type_error
|
118
113
|
end
|
119
114
|
end
|
120
115
|
end
|
@@ -0,0 +1,49 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module GraphqlRails
|
4
|
+
# Allows defining methods chained way
|
5
|
+
module ChainableOptions
|
6
|
+
NOT_SET = Object.new
|
7
|
+
|
8
|
+
# nodoc
|
9
|
+
module ClassMethods
|
10
|
+
def chainable_option(option_name, default: nil)
|
11
|
+
define_method(option_name) do |value = NOT_SET|
|
12
|
+
get_or_set_chainable_option(option_name, value, default: default)
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
def self.included(base)
|
18
|
+
base.extend(ClassMethods)
|
19
|
+
end
|
20
|
+
|
21
|
+
def initialize_copy(other)
|
22
|
+
super
|
23
|
+
@chainable_option = other.instance_variable_get(:@chainable_option).dup
|
24
|
+
end
|
25
|
+
|
26
|
+
def with(**options)
|
27
|
+
options.each do |method_name, args|
|
28
|
+
send_args = [method_name]
|
29
|
+
send_args << args if method(method_name).parameters.present?
|
30
|
+
public_send(*send_args)
|
31
|
+
end
|
32
|
+
self
|
33
|
+
end
|
34
|
+
|
35
|
+
private
|
36
|
+
|
37
|
+
def fetch_chainable_option(option_name, *default, &block)
|
38
|
+
@chainable_option.fetch(option_name.to_sym, *default, &block)
|
39
|
+
end
|
40
|
+
|
41
|
+
def get_or_set_chainable_option(option_name, value = NOT_SET, default: nil)
|
42
|
+
@chainable_option ||= {}
|
43
|
+
return fetch_chainable_option(option_name, default) if value == NOT_SET
|
44
|
+
|
45
|
+
@chainable_option[option_name.to_sym] = value
|
46
|
+
self
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
data/lib/graphql_rails/controller/build_controller_action_resolver/controller_action_resolver.rb
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
require 'graphql_rails/controller/request'
|
4
|
+
require 'graphql_rails/types/argument_type'
|
4
5
|
|
5
6
|
module GraphqlRails
|
6
7
|
class Controller
|
@@ -8,6 +9,8 @@ module GraphqlRails
|
|
8
9
|
# Resolver which includes controller specific methods.
|
9
10
|
# Used to simplify resolver build for each controller action
|
10
11
|
class ControllerActionResolver < GraphQL::Schema::Resolver
|
12
|
+
argument_class(GraphqlRails::Types::ArgumentType)
|
13
|
+
|
11
14
|
def self.controller(controller_class = nil)
|
12
15
|
@controller = controller_class if controller_class
|
13
16
|
@controller
|
@@ -62,9 +62,14 @@ module GraphqlRails
|
|
62
62
|
end
|
63
63
|
|
64
64
|
def parameter_filter_class
|
65
|
-
|
65
|
+
if ActiveSupport.gem_version.segments.first < 6
|
66
|
+
return ActiveSupport::ParameterFilter if Object.const_defined?('ActiveSupport::ParameterFilter')
|
66
67
|
|
67
|
-
|
68
|
+
ActionDispatch::Http::ParameterFilter
|
69
|
+
else
|
70
|
+
require 'active_support/parameter_filter'
|
71
|
+
ActiveSupport::ParameterFilter
|
72
|
+
end
|
68
73
|
end
|
69
74
|
end
|
70
75
|
end
|
@@ -5,7 +5,7 @@ module GraphqlRails
|
|
5
5
|
# wrapps active record relation and returns decorated object instead
|
6
6
|
class RelationDecorator
|
7
7
|
delegate :map, :each, to: :to_a
|
8
|
-
delegate :limit_value, :offset_value, :count, :size, to: :relation
|
8
|
+
delegate :limit_value, :offset_value, :count, :size, :empty?, to: :relation
|
9
9
|
|
10
10
|
def self.decorates?(object)
|
11
11
|
(defined?(ActiveRecord) && object.is_a?(ActiveRecord::Relation)) ||
|
@@ -24,7 +24,7 @@ module GraphqlRails
|
|
24
24
|
end
|
25
25
|
end
|
26
26
|
|
27
|
-
%i[first second last].each do |method_name|
|
27
|
+
%i[first second last find find_by].each do |method_name|
|
28
28
|
define_method method_name do |*args, &block|
|
29
29
|
decoratable_object_method(method_name, *args, &block)
|
30
30
|
end
|
@@ -3,9 +3,14 @@
|
|
3
3
|
module GraphqlRails
|
4
4
|
# contains configuration options related with inputs
|
5
5
|
module InputConfigurable
|
6
|
-
def permit(*
|
7
|
-
|
8
|
-
|
6
|
+
def permit(*args)
|
7
|
+
args.each do |arg|
|
8
|
+
if arg.is_a? Hash
|
9
|
+
arg.each { |attribute, type| permit_input(attribute, type: type) }
|
10
|
+
else
|
11
|
+
permit_input(arg)
|
12
|
+
end
|
13
|
+
end
|
9
14
|
self
|
10
15
|
end
|
11
16
|
|
@@ -21,7 +26,7 @@ module GraphqlRails
|
|
21
26
|
pagination_options = nil if pagination_options == false
|
22
27
|
|
23
28
|
@pagination_options = pagination_options
|
24
|
-
|
29
|
+
self
|
25
30
|
end
|
26
31
|
|
27
32
|
def paginated?
|
@@ -37,11 +42,8 @@ module GraphqlRails
|
|
37
42
|
end
|
38
43
|
|
39
44
|
def build_input_attribute(name, options: {}, **other_options)
|
40
|
-
|
41
|
-
|
42
|
-
options: input_attribute_options.merge(options),
|
43
|
-
**other_options
|
44
|
-
)
|
45
|
+
input_options = input_attribute_options.merge(options)
|
46
|
+
Attributes::InputAttribute.new(name.to_s, config: self).with(options: input_options, **other_options)
|
45
47
|
end
|
46
48
|
end
|
47
49
|
end
|
@@ -1,11 +1,12 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
require 'graphql_rails/types/argument_type'
|
4
|
+
require 'graphql_rails/concerns/service'
|
5
|
+
|
3
6
|
module GraphqlRails
|
4
7
|
module Model
|
5
8
|
# stores information about model specific config, like attributes and types
|
6
9
|
class BuildGraphqlInputType
|
7
|
-
require 'graphql_rails/concerns/service'
|
8
|
-
|
9
10
|
include ::GraphqlRails::Service
|
10
11
|
|
11
12
|
def initialize(name:, description: nil, attributes:)
|
@@ -20,6 +21,7 @@ module GraphqlRails
|
|
20
21
|
type_attributes = attributes
|
21
22
|
|
22
23
|
Class.new(GraphQL::Schema::InputObject) do
|
24
|
+
argument_class(GraphqlRails::Types::ArgumentType)
|
23
25
|
graphql_name(type_name)
|
24
26
|
description(type_description)
|
25
27
|
|