graphql_rails 1.0.0 → 1.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.hound.yml +1 -0
- data/.rubocop.yml +3 -3
- data/.ruby-version +1 -1
- data/.travis.yml +2 -2
- data/CHANGELOG.md +3 -0
- data/Gemfile +3 -2
- data/Gemfile.lock +141 -117
- data/docs/README.md +2 -2
- data/docs/components/controller.md +21 -5
- data/docs/components/model.md +43 -3
- data/docs/index.html +1 -1
- data/graphql_rails.gemspec +5 -5
- data/lib/generators/graphql_rails/templates/graphql_router_spec.erb +10 -7
- data/lib/graphql_rails/attributes/attributable.rb +2 -4
- data/lib/graphql_rails/attributes/attribute.rb +26 -6
- data/lib/graphql_rails/attributes/attribute_name_parser.rb +1 -1
- data/lib/graphql_rails/attributes/input_attribute.rb +5 -1
- data/lib/graphql_rails/concerns/service.rb +6 -2
- data/lib/graphql_rails/controller.rb +6 -6
- data/lib/graphql_rails/controller/action.rb +5 -1
- data/lib/graphql_rails/controller/build_controller_action_resolver.rb +2 -2
- data/lib/graphql_rails/controller/request.rb +1 -1
- data/lib/graphql_rails/controller/request/format_errors.rb +1 -1
- data/lib/graphql_rails/model/add_fields_to_graphql_type.rb +45 -0
- data/lib/graphql_rails/model/build_graphql_input_type.rb +1 -1
- data/lib/graphql_rails/model/call_graphql_model_method.rb +14 -1
- data/lib/graphql_rails/model/configurable.rb +6 -2
- data/lib/graphql_rails/model/configuration.rb +9 -4
- data/lib/graphql_rails/model/find_or_build_graphql_type.rb +64 -0
- data/lib/graphql_rails/model/find_or_build_graphql_type_class.rb +46 -0
- data/lib/graphql_rails/router.rb +2 -2
- data/lib/graphql_rails/router/resource_routes_builder.rb +8 -8
- data/lib/graphql_rails/router/route.rb +3 -7
- data/lib/graphql_rails/router/schema_builder.rb +1 -1
- data/lib/graphql_rails/rspec_controller_helpers.rb +2 -2
- data/lib/graphql_rails/version.rb +1 -1
- metadata +21 -14
- data/lib/graphql_rails/model/build_graphql_type.rb +0 -53
@@ -0,0 +1,64 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module GraphqlRails
|
4
|
+
module Model
|
5
|
+
# stores information about model specific config, like attributes and types
|
6
|
+
class FindOrBuildGraphqlType
|
7
|
+
require 'graphql_rails/concerns/service'
|
8
|
+
require 'graphql_rails/model/find_or_build_graphql_type_class'
|
9
|
+
require 'graphql_rails/model/add_fields_to_graphql_type'
|
10
|
+
|
11
|
+
include ::GraphqlRails::Service
|
12
|
+
|
13
|
+
def initialize(name:, description:, attributes:, type_name:)
|
14
|
+
@name = name
|
15
|
+
@description = description
|
16
|
+
@attributes = attributes
|
17
|
+
@type_name = type_name
|
18
|
+
end
|
19
|
+
|
20
|
+
def call
|
21
|
+
klass.tap { add_fields_to_graphql_type if new_class? }
|
22
|
+
end
|
23
|
+
|
24
|
+
private
|
25
|
+
|
26
|
+
attr_reader :name, :description, :attributes, :type_name
|
27
|
+
|
28
|
+
delegate :klass, :new_class?, to: :type_class_finder
|
29
|
+
|
30
|
+
def type_class_finder
|
31
|
+
@type_class_finder ||= FindOrBuildGraphqlTypeClass.new(
|
32
|
+
name: name,
|
33
|
+
type_name: type_name,
|
34
|
+
description: description
|
35
|
+
)
|
36
|
+
end
|
37
|
+
|
38
|
+
def add_fields_to_graphql_type
|
39
|
+
AddFieldsToGraphqlType.call(klass: klass, attributes: attributes.values.select(&:scalar_type?))
|
40
|
+
|
41
|
+
attributes.values.reject(&:scalar_type?).tap do |dynamic_attributes|
|
42
|
+
find_or_build_dynamic_graphql_types(dynamic_attributes) do |name, description, attributes, type_name|
|
43
|
+
self.class.call(
|
44
|
+
name: name, description: description,
|
45
|
+
attributes: attributes, type_name: type_name
|
46
|
+
)
|
47
|
+
end
|
48
|
+
AddFieldsToGraphqlType.call(klass: klass, attributes: dynamic_attributes)
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
def find_or_build_dynamic_graphql_types(dynamic_attributes)
|
53
|
+
dynamic_attributes.each do |attribute|
|
54
|
+
yield(
|
55
|
+
attribute.graphql_model.graphql.name,
|
56
|
+
attribute.graphql_model.graphql.description,
|
57
|
+
attribute.graphql_model.graphql.attributes,
|
58
|
+
attribute.graphql_model.graphql.type_name
|
59
|
+
)
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
@@ -0,0 +1,46 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module GraphqlRails
|
4
|
+
module Model
|
5
|
+
# Initializes class to define graphql type and fields.
|
6
|
+
class FindOrBuildGraphqlTypeClass
|
7
|
+
require 'graphql_rails/concerns/service'
|
8
|
+
|
9
|
+
include ::GraphqlRails::Service
|
10
|
+
|
11
|
+
def initialize(name:, type_name:, description: nil)
|
12
|
+
@name = name
|
13
|
+
@type_name = type_name
|
14
|
+
@description = description
|
15
|
+
@new_class = false
|
16
|
+
end
|
17
|
+
|
18
|
+
def klass
|
19
|
+
@klass ||= Object.const_defined?(type_name) && Object.const_get(type_name) || build_graphql_type_klass
|
20
|
+
end
|
21
|
+
|
22
|
+
def new_class?
|
23
|
+
new_class
|
24
|
+
end
|
25
|
+
|
26
|
+
private
|
27
|
+
|
28
|
+
attr_accessor :new_class
|
29
|
+
attr_reader :name, :type_name, :description
|
30
|
+
|
31
|
+
def build_graphql_type_klass
|
32
|
+
graphql_type_name = name
|
33
|
+
graphql_type_description = description
|
34
|
+
|
35
|
+
graphql_type_klass = Class.new(GraphQL::Schema::Object) do
|
36
|
+
graphql_name(graphql_type_name)
|
37
|
+
description(graphql_type_description)
|
38
|
+
end
|
39
|
+
|
40
|
+
self.new_class = true
|
41
|
+
|
42
|
+
Object.const_set(type_name, graphql_type_klass)
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
data/lib/graphql_rails/router.rb
CHANGED
@@ -85,7 +85,7 @@ module GraphqlRails
|
|
85
85
|
default_options = { module_name: module_name, group_names: group_names }
|
86
86
|
full_options = default_options.merge(new_router_options)
|
87
87
|
|
88
|
-
self.class.new(full_options)
|
88
|
+
self.class.new(**full_options)
|
89
89
|
end
|
90
90
|
|
91
91
|
def add_raw_action(name, *args, &block)
|
@@ -93,7 +93,7 @@ module GraphqlRails
|
|
93
93
|
end
|
94
94
|
|
95
95
|
def build_route(route_builder, name, **options)
|
96
|
-
route_builder.new(name, full_route_options(options))
|
96
|
+
route_builder.new(name, **full_route_options(options))
|
97
97
|
end
|
98
98
|
|
99
99
|
def full_route_options(extra_options)
|
@@ -20,12 +20,12 @@ module GraphqlRails
|
|
20
20
|
@routes ||= initial_routes
|
21
21
|
end
|
22
22
|
|
23
|
-
def query(*args)
|
24
|
-
routes << build_query(*args)
|
23
|
+
def query(*args, **kwargs)
|
24
|
+
routes << build_query(*args, **kwargs)
|
25
25
|
end
|
26
26
|
|
27
|
-
def mutation(*args)
|
28
|
-
routes << build_mutation(*args)
|
27
|
+
def mutation(*args, **kwargs)
|
28
|
+
routes << build_mutation(*args, **kwargs)
|
29
29
|
end
|
30
30
|
|
31
31
|
private
|
@@ -54,12 +54,12 @@ module GraphqlRails
|
|
54
54
|
routes
|
55
55
|
end
|
56
56
|
|
57
|
-
def build_mutation(*args)
|
58
|
-
build_route(MutationRoute, *args)
|
57
|
+
def build_mutation(*args, **kwargs)
|
58
|
+
build_route(MutationRoute, *args, **kwargs)
|
59
59
|
end
|
60
60
|
|
61
|
-
def build_query(*args)
|
62
|
-
build_route(QueryRoute, *args)
|
61
|
+
def build_query(*args, **kwargs)
|
62
|
+
build_route(QueryRoute, *args, **kwargs)
|
63
63
|
end
|
64
64
|
|
65
65
|
# rubocop:disable Metrics/ParameterLists
|
@@ -33,16 +33,12 @@ module GraphqlRails
|
|
33
33
|
groups.include?(group_name&.to_sym)
|
34
34
|
end
|
35
35
|
|
36
|
-
def
|
37
|
-
options = {}
|
38
|
-
|
36
|
+
def field_options
|
39
37
|
if function
|
40
|
-
|
38
|
+
{ function: function }
|
41
39
|
else
|
42
|
-
|
40
|
+
{ resolver: resolver }
|
43
41
|
end
|
44
|
-
|
45
|
-
[name, options]
|
46
42
|
end
|
47
43
|
|
48
44
|
private
|
metadata
CHANGED
@@ -1,29 +1,35 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: graphql_rails
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Povilas Jurčys
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-
|
11
|
+
date: 2020-11-25 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: graphql
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.11'
|
17
20
|
- - ">="
|
18
21
|
- !ruby/object:Gem::Version
|
19
|
-
version: 1.
|
22
|
+
version: 1.11.6
|
20
23
|
type: :runtime
|
21
24
|
prerelease: false
|
22
25
|
version_requirements: !ruby/object:Gem::Requirement
|
23
26
|
requirements:
|
27
|
+
- - "~>"
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '1.11'
|
24
30
|
- - ">="
|
25
31
|
- !ruby/object:Gem::Version
|
26
|
-
version: 1.
|
32
|
+
version: 1.11.6
|
27
33
|
- !ruby/object:Gem::Dependency
|
28
34
|
name: activesupport
|
29
35
|
requirement: !ruby/object:Gem::Requirement
|
@@ -44,28 +50,28 @@ dependencies:
|
|
44
50
|
requirements:
|
45
51
|
- - "~>"
|
46
52
|
- !ruby/object:Gem::Version
|
47
|
-
version: '
|
53
|
+
version: '2'
|
48
54
|
type: :development
|
49
55
|
prerelease: false
|
50
56
|
version_requirements: !ruby/object:Gem::Requirement
|
51
57
|
requirements:
|
52
58
|
- - "~>"
|
53
59
|
- !ruby/object:Gem::Version
|
54
|
-
version: '
|
60
|
+
version: '2'
|
55
61
|
- !ruby/object:Gem::Dependency
|
56
62
|
name: rake
|
57
63
|
requirement: !ruby/object:Gem::Requirement
|
58
64
|
requirements:
|
59
65
|
- - "~>"
|
60
66
|
- !ruby/object:Gem::Version
|
61
|
-
version: '
|
67
|
+
version: '13.0'
|
62
68
|
type: :development
|
63
69
|
prerelease: false
|
64
70
|
version_requirements: !ruby/object:Gem::Requirement
|
65
71
|
requirements:
|
66
72
|
- - "~>"
|
67
73
|
- !ruby/object:Gem::Version
|
68
|
-
version: '
|
74
|
+
version: '13.0'
|
69
75
|
- !ruby/object:Gem::Dependency
|
70
76
|
name: rspec
|
71
77
|
requirement: !ruby/object:Gem::Requirement
|
@@ -114,14 +120,14 @@ dependencies:
|
|
114
120
|
requirements:
|
115
121
|
- - "~>"
|
116
122
|
- !ruby/object:Gem::Version
|
117
|
-
version: '
|
123
|
+
version: '6'
|
118
124
|
type: :development
|
119
125
|
prerelease: false
|
120
126
|
version_requirements: !ruby/object:Gem::Requirement
|
121
127
|
requirements:
|
122
128
|
- - "~>"
|
123
129
|
- !ruby/object:Gem::Version
|
124
|
-
version: '
|
130
|
+
version: '6'
|
125
131
|
description:
|
126
132
|
email:
|
127
133
|
- po.jurcys@gmail.com
|
@@ -198,14 +204,16 @@ files:
|
|
198
204
|
- lib/graphql_rails/integrations/lograge.rb
|
199
205
|
- lib/graphql_rails/integrations/sentry.rb
|
200
206
|
- lib/graphql_rails/model.rb
|
207
|
+
- lib/graphql_rails/model/add_fields_to_graphql_type.rb
|
201
208
|
- lib/graphql_rails/model/build_connection_type.rb
|
202
209
|
- lib/graphql_rails/model/build_connection_type/count_items.rb
|
203
210
|
- lib/graphql_rails/model/build_enum_type.rb
|
204
211
|
- lib/graphql_rails/model/build_graphql_input_type.rb
|
205
|
-
- lib/graphql_rails/model/build_graphql_type.rb
|
206
212
|
- lib/graphql_rails/model/call_graphql_model_method.rb
|
207
213
|
- lib/graphql_rails/model/configurable.rb
|
208
214
|
- lib/graphql_rails/model/configuration.rb
|
215
|
+
- lib/graphql_rails/model/find_or_build_graphql_type.rb
|
216
|
+
- lib/graphql_rails/model/find_or_build_graphql_type_class.rb
|
209
217
|
- lib/graphql_rails/model/input.rb
|
210
218
|
- lib/graphql_rails/query_runner.rb
|
211
219
|
- lib/graphql_rails/railtie.rb
|
@@ -239,9 +247,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
239
247
|
- !ruby/object:Gem::Version
|
240
248
|
version: '0'
|
241
249
|
requirements: []
|
242
|
-
|
243
|
-
rubygems_version: 2.7.7
|
250
|
+
rubygems_version: 3.1.2
|
244
251
|
signing_key:
|
245
252
|
specification_version: 4
|
246
|
-
summary:
|
253
|
+
summary: Rails style structure for GraphQL API.
|
247
254
|
test_files: []
|
@@ -1,53 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module GraphqlRails
|
4
|
-
module Model
|
5
|
-
# stores information about model specific config, like attributes and types
|
6
|
-
class BuildGraphqlType
|
7
|
-
require 'graphql_rails/concerns/service'
|
8
|
-
require 'graphql_rails/model/call_graphql_model_method'
|
9
|
-
|
10
|
-
include ::GraphqlRails::Service
|
11
|
-
|
12
|
-
PAGINATION_KEYS = %i[before after first last].freeze
|
13
|
-
|
14
|
-
def initialize(name:, description: nil, attributes:)
|
15
|
-
@name = name
|
16
|
-
@attributes = attributes
|
17
|
-
@description = description
|
18
|
-
end
|
19
|
-
|
20
|
-
def call
|
21
|
-
type_name = name
|
22
|
-
type_description = description
|
23
|
-
type_attributes = attributes
|
24
|
-
|
25
|
-
Class.new(GraphQL::Schema::Object) do
|
26
|
-
graphql_name(type_name)
|
27
|
-
description(type_description)
|
28
|
-
|
29
|
-
type_attributes.each_value do |attribute|
|
30
|
-
field(*attribute.field_args) do
|
31
|
-
attribute.attributes.values.each do |arg_attribute|
|
32
|
-
argument(*arg_attribute.input_argument_args)
|
33
|
-
end
|
34
|
-
end
|
35
|
-
|
36
|
-
define_method attribute.property do |**kwargs|
|
37
|
-
CallGraphqlModelMethod.call(
|
38
|
-
model: object,
|
39
|
-
attribute_config: attribute,
|
40
|
-
method_keyword_arguments: kwargs,
|
41
|
-
graphql_context: context
|
42
|
-
)
|
43
|
-
end
|
44
|
-
end
|
45
|
-
end
|
46
|
-
end
|
47
|
-
|
48
|
-
private
|
49
|
-
|
50
|
-
attr_reader :attributes, :name, :description
|
51
|
-
end
|
52
|
-
end
|
53
|
-
end
|