graphql_rails 1.1.0 → 1.2.4
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/CHANGELOG.md +23 -0
- data/Gemfile.lock +12 -8
- data/docs/README.md +1 -1
- data/docs/components/controller.md +2 -2
- data/docs/getting_started/quick_start.md +1 -1
- data/docs/other_tools/query_runner.md +1 -1
- data/docs/other_tools/schema_dump.md +1 -1
- data/graphql_rails.gemspec +1 -1
- data/lib/graphql_rails/attributes/attributable.rb +4 -6
- data/lib/graphql_rails/attributes/attribute_name_parser.rb +3 -3
- data/lib/graphql_rails/attributes/type_parseable.rb +17 -13
- data/lib/graphql_rails/controller/log_controller_action.rb +7 -2
- data/lib/graphql_rails/decorator/relation_decorator.rb +0 -4
- data/lib/graphql_rails/model.rb +1 -1
- data/lib/graphql_rails/model/build_connection_type.rb +5 -1
- data/lib/graphql_rails/model/build_connection_type/count_items.rb +2 -2
- data/lib/graphql_rails/model/configuration.rb +18 -0
- data/lib/graphql_rails/model/find_or_build_graphql_type.rb +4 -3
- data/lib/graphql_rails/router/schema_builder.rb +4 -0
- data/lib/graphql_rails/version.rb +1 -1
- metadata +10 -10
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4fde3149c0119edc09198e27b61c428ed666ea2bb4582b428142db31a58749c4
|
4
|
+
data.tar.gz: d9faa17f35d1ac01400b829983d6a2b16230c62971bb6ed0178b9a6bf4b1c0bd
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ee735c639cf392c7a4261db07791bb953942977fd4c001fcb101fd3e4a7009db58fb27520d0227e2b3254fdbc5d2dc52043d892597e99d4526ad18fc8919de30
|
7
|
+
data.tar.gz: 80e3a427bb04a91332230460638d7f866afc843dbebfd9e9211454869154c32459e9c1d3c2dcaa97e06bd767792bc6ff742b871ded561094354bc4beab2517a1
|
data/CHANGELOG.md
CHANGED
@@ -9,8 +9,31 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
9
9
|
|
10
10
|
* Added/Changed/Deprecated/Removed/Fixed/Security: YOUR CHANGE HERE
|
11
11
|
|
12
|
+
## [1.2.4](2021-05-05)
|
13
|
+
|
14
|
+
* Fixed: Dynamic types definition where type A references type B referencing type A.
|
15
|
+
|
16
|
+
## [1.2.3](2021-04-12)
|
17
|
+
|
18
|
+
* Fixed: Total count on paginated resources
|
19
|
+
|
20
|
+
## [1.2.2](2021-02-19)
|
21
|
+
|
22
|
+
* Fixed: Incorrect type resolution for required list type fields in model declaration.
|
23
|
+
|
24
|
+
## [1.2.1](2021-02-17)
|
25
|
+
|
26
|
+
* Fixed: Incorrect scalar types resolution is fixed. No more `type mismatch between ID / ID`
|
27
|
+
|
28
|
+
## [1.2.0](2021-02-15)
|
29
|
+
|
12
30
|
* Added: `options` argument to model level attribute. Allows disabling automatic camelCase
|
13
31
|
* Fixed: methods with complex input arguments receives `Hash` instances instead of `GraphQL::Schema::InputObject`
|
32
|
+
* Fixed: Using `ActiveSupport::ParameterFilter` (Rails 6.1), if it is defined, instead of `ActionDispatch::Http::ParameterFilter`
|
33
|
+
* Changed: graphql version is now `1.12` which may require system-wide changes.
|
34
|
+
* Fixed: improved connection wrapper for pagination to work.
|
35
|
+
* Fixed: implementation of `total` field is no longer missing when using pagination.
|
36
|
+
|
14
37
|
|
15
38
|
## [1.0.0](2020-02-07)
|
16
39
|
|
data/Gemfile.lock
CHANGED
@@ -1,9 +1,9 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
graphql_rails (1.
|
4
|
+
graphql_rails (1.2.3)
|
5
5
|
activesupport (>= 4)
|
6
|
-
graphql (~> 1.
|
6
|
+
graphql (~> 1.12, >= 1.12.4)
|
7
7
|
|
8
8
|
GEM
|
9
9
|
remote: https://rubygems.org/
|
@@ -78,7 +78,7 @@ GEM
|
|
78
78
|
erubi (1.9.0)
|
79
79
|
globalid (0.4.2)
|
80
80
|
activesupport (>= 4.2.0)
|
81
|
-
graphql (1.
|
81
|
+
graphql (1.12.4)
|
82
82
|
i18n (1.8.5)
|
83
83
|
concurrent-ruby (~> 1.0)
|
84
84
|
json (2.3.1)
|
@@ -90,9 +90,11 @@ GEM
|
|
90
90
|
marcel (0.3.3)
|
91
91
|
mimemagic (~> 0.3.2)
|
92
92
|
method_source (1.0.0)
|
93
|
-
mimemagic (0.3.
|
93
|
+
mimemagic (0.3.10)
|
94
|
+
nokogiri (~> 1)
|
95
|
+
rake
|
94
96
|
mini_mime (1.0.2)
|
95
|
-
mini_portile2 (2.
|
97
|
+
mini_portile2 (2.5.0)
|
96
98
|
minitest (5.14.2)
|
97
99
|
mongo (2.13.1)
|
98
100
|
bson (>= 4.8.2, < 5.0.0)
|
@@ -100,8 +102,9 @@ GEM
|
|
100
102
|
activemodel (>= 5.1, < 6.1)
|
101
103
|
mongo (>= 2.7.0, < 3.0.0)
|
102
104
|
nio4r (2.5.4)
|
103
|
-
nokogiri (1.
|
104
|
-
mini_portile2 (~> 2.
|
105
|
+
nokogiri (1.11.1)
|
106
|
+
mini_portile2 (~> 2.5.0)
|
107
|
+
racc (~> 1.4)
|
105
108
|
parallel (1.19.2)
|
106
109
|
parser (2.7.2.0)
|
107
110
|
ast (~> 2.4.1)
|
@@ -111,6 +114,7 @@ GEM
|
|
111
114
|
pry-byebug (3.9.0)
|
112
115
|
byebug (~> 11.0)
|
113
116
|
pry (~> 0.13.0)
|
117
|
+
racc (1.5.2)
|
114
118
|
rack (2.2.3)
|
115
119
|
rack-test (1.1.0)
|
116
120
|
rack (>= 1.0, < 3)
|
@@ -143,7 +147,7 @@ GEM
|
|
143
147
|
rainbow (3.0.0)
|
144
148
|
rake (13.0.1)
|
145
149
|
regexp_parser (1.8.2)
|
146
|
-
rexml (3.2.
|
150
|
+
rexml (3.2.5)
|
147
151
|
rspec (3.10.0)
|
148
152
|
rspec-core (~> 3.10.0)
|
149
153
|
rspec-expectations (~> 3.10.0)
|
data/docs/README.md
CHANGED
@@ -37,7 +37,7 @@ This will generate code which will let you start your graphql faster
|
|
37
37
|
```ruby
|
38
38
|
# config/graphql/routes.rb
|
39
39
|
GraphqlRails::Router.draw do
|
40
|
-
# will create createUser, updateUser,
|
40
|
+
# will create createUser, updateUser, destroyUser mutations and user, users queries.
|
41
41
|
# expects that UsersController class exist
|
42
42
|
resources :users
|
43
43
|
|
@@ -78,7 +78,7 @@ Specifies input type:
|
|
78
78
|
class OrderController < GraphqlRails::Controller
|
79
79
|
action(:create)
|
80
80
|
.permit_input(:price, type: :integer!)
|
81
|
-
# Same as `.permit(
|
81
|
+
# Same as `.permit(price: :integer!)`
|
82
82
|
end
|
83
83
|
```
|
84
84
|
|
@@ -446,7 +446,7 @@ class UsersController < GraphqlRails::Controller
|
|
446
446
|
raise 'Not authenticated' unless User.where(token: params[:token]).exist?
|
447
447
|
end
|
448
448
|
|
449
|
-
def
|
449
|
+
def require_admin_token
|
450
450
|
raise 'Admin not authenticated' unless Admin.where(token: params[:admin_token]).exist?
|
451
451
|
end
|
452
452
|
end
|
@@ -11,7 +11,7 @@ bundle exec rails g graphql_rails:install
|
|
11
11
|
```ruby
|
12
12
|
# config/graphql/routes.rb
|
13
13
|
GraphqlRails::Router.draw do
|
14
|
-
# will create createUser, updateUser,
|
14
|
+
# will create createUser, updateUser, destroyUser mutations and user, users queries.
|
15
15
|
# expects that UsersController class exist
|
16
16
|
resources :users
|
17
17
|
|
@@ -16,7 +16,7 @@ end
|
|
16
16
|
|
17
17
|
## Executing grouped schema
|
18
18
|
|
19
|
-
If you have multiple schemas (read [routes section](
|
19
|
+
If you have multiple schemas (read [routes section](components/routes) on how to do that) and you want to render group specific schema, you need to provide group name, like this:
|
20
20
|
|
21
21
|
```ruby
|
22
22
|
class MyRailsClass < ApplicationController
|
@@ -8,7 +8,7 @@ rake graphql_rails:schema:dump
|
|
8
8
|
|
9
9
|
## Dumping non default schema
|
10
10
|
|
11
|
-
You can have multiple graphql schemas. Read more about this in [routes section](
|
11
|
+
You can have multiple graphql schemas. Read more about this in [routes section](components/routes). In order to generate schema for one of groups, provide optional `name` argument:
|
12
12
|
|
13
13
|
```bash
|
14
14
|
rake graphql_rails:schema:dump['your_group_name']
|
data/graphql_rails.gemspec
CHANGED
@@ -20,7 +20,7 @@ Gem::Specification.new do |spec|
|
|
20
20
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
21
21
|
spec.require_paths = ['lib']
|
22
22
|
|
23
|
-
spec.add_dependency 'graphql', '~> 1.
|
23
|
+
spec.add_dependency 'graphql', '~> 1.12', '>= 1.12.4'
|
24
24
|
spec.add_dependency 'activesupport', '>= 4'
|
25
25
|
|
26
26
|
spec.add_development_dependency 'bundler', '~> 2'
|
@@ -21,11 +21,9 @@ module GraphqlRails
|
|
21
21
|
end
|
22
22
|
|
23
23
|
def required?
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
@required
|
28
|
-
end
|
24
|
+
return @required unless @required.nil?
|
25
|
+
|
26
|
+
attribute_name_parser.required? || !initial_type.to_s[/!$/].nil? || initial_type.is_a?(GraphQL::Schema::NonNull)
|
29
27
|
end
|
30
28
|
|
31
29
|
def required
|
@@ -47,7 +45,7 @@ module GraphqlRails
|
|
47
45
|
end
|
48
46
|
|
49
47
|
def scalar_type?
|
50
|
-
type_parser.raw_graphql_type? || type_parser.
|
48
|
+
type_parser.raw_graphql_type? || type_parser.core_scalar_type?
|
51
49
|
end
|
52
50
|
|
53
51
|
private
|
@@ -27,11 +27,11 @@ module GraphqlRails
|
|
27
27
|
@graphql_type ||= \
|
28
28
|
case name
|
29
29
|
when 'id', /_id\Z/
|
30
|
-
GraphQL::
|
30
|
+
GraphQL::Types::ID
|
31
31
|
when /\?\Z/
|
32
|
-
GraphQL::
|
32
|
+
GraphQL::Types::Boolean
|
33
33
|
else
|
34
|
-
GraphQL::
|
34
|
+
GraphQL::Types::String
|
35
35
|
end
|
36
36
|
end
|
37
37
|
|
@@ -11,23 +11,23 @@ module GraphqlRails
|
|
11
11
|
class UnknownTypeError < ArgumentError; end
|
12
12
|
|
13
13
|
TYPE_MAPPING = {
|
14
|
-
'id' => GraphQL::
|
14
|
+
'id' => GraphQL::Types::ID,
|
15
15
|
|
16
|
-
'int' => GraphQL::
|
17
|
-
'integer' => GraphQL::
|
16
|
+
'int' => GraphQL::Types::Int,
|
17
|
+
'integer' => GraphQL::Types::Int,
|
18
18
|
|
19
|
-
'string' => GraphQL::
|
20
|
-
'str' => GraphQL::
|
21
|
-
'text' => GraphQL::
|
22
|
-
'time' => GraphQL::
|
23
|
-
'date' => GraphQL::
|
19
|
+
'string' => GraphQL::Types::String,
|
20
|
+
'str' => GraphQL::Types::String,
|
21
|
+
'text' => GraphQL::Types::String,
|
22
|
+
'time' => GraphQL::Types::String,
|
23
|
+
'date' => GraphQL::Types::String,
|
24
24
|
|
25
|
-
'bool' => GraphQL::
|
26
|
-
'boolean' => GraphQL::
|
25
|
+
'bool' => GraphQL::Types::Boolean,
|
26
|
+
'boolean' => GraphQL::Types::Boolean,
|
27
27
|
|
28
|
-
'float' => GraphQL::
|
29
|
-
'double' => GraphQL::
|
30
|
-
'decimal' => GraphQL::
|
28
|
+
'float' => GraphQL::Types::Float,
|
29
|
+
'double' => GraphQL::Types::Float,
|
30
|
+
'decimal' => GraphQL::Types::Float
|
31
31
|
}.freeze
|
32
32
|
|
33
33
|
WRAPPER_TYPES = [
|
@@ -57,6 +57,10 @@ module GraphqlRails
|
|
57
57
|
unparsed_type < GraphQL::Schema::Member
|
58
58
|
end
|
59
59
|
|
60
|
+
def core_scalar_type?
|
61
|
+
unwrapped_scalar_type.in?(TYPE_MAPPING.values)
|
62
|
+
end
|
63
|
+
|
60
64
|
def graphql_model
|
61
65
|
type_class = \
|
62
66
|
if unparsed_type.is_a?(Class) && unparsed_type < GraphqlRails::Model
|
@@ -51,8 +51,7 @@ module GraphqlRails
|
|
51
51
|
params
|
52
52
|
else
|
53
53
|
filter_options = Rails.configuration.filter_parameters
|
54
|
-
|
55
|
-
parametter_filter.filter(params)
|
54
|
+
parameter_filter_class.new(filter_options).filter(params)
|
56
55
|
end
|
57
56
|
end
|
58
57
|
|
@@ -61,6 +60,12 @@ module GraphqlRails
|
|
61
60
|
|
62
61
|
Rails.application.config.filter_parameters || []
|
63
62
|
end
|
63
|
+
|
64
|
+
def parameter_filter_class
|
65
|
+
return ActiveSupport::ParameterFilter if Object.const_defined?('ActiveSupport::ParameterFilter')
|
66
|
+
|
67
|
+
ActionDispatch::Http::ParameterFilter
|
68
|
+
end
|
64
69
|
end
|
65
70
|
end
|
66
71
|
end
|
@@ -71,9 +71,5 @@ module GraphqlRails
|
|
71
71
|
self.class.new(decorator: decorator, relation: new_relation, decorator_args: decorator_args)
|
72
72
|
end
|
73
73
|
end
|
74
|
-
|
75
|
-
GraphQL::Relay::BaseConnection.register_connection_implementation(
|
76
|
-
RelationDecorator, GraphQL::Relay::RelationConnection
|
77
|
-
)
|
78
74
|
end
|
79
75
|
end
|
data/lib/graphql_rails/model.rb
CHANGED
@@ -30,7 +30,11 @@ module GraphqlRails
|
|
30
30
|
graphql_name("#{type.graphql_name}Connection")
|
31
31
|
edge_type(edge_type)
|
32
32
|
|
33
|
-
field :total, Integer, null: false
|
33
|
+
field :total, Integer, null: false
|
34
|
+
|
35
|
+
def total
|
36
|
+
CountItems.call(object)
|
37
|
+
end
|
34
38
|
end
|
35
39
|
end
|
36
40
|
|
@@ -10,7 +10,7 @@ module GraphqlRails
|
|
10
10
|
|
11
11
|
include ::GraphqlRails::Service
|
12
12
|
|
13
|
-
def initialize(graphql_object
|
13
|
+
def initialize(graphql_object)
|
14
14
|
@graphql_object = graphql_object
|
15
15
|
end
|
16
16
|
|
@@ -27,7 +27,7 @@ module GraphqlRails
|
|
27
27
|
attr_reader :graphql_object
|
28
28
|
|
29
29
|
def list
|
30
|
-
graphql_object.
|
30
|
+
graphql_object.items
|
31
31
|
end
|
32
32
|
|
33
33
|
def active_record?
|
@@ -68,6 +68,14 @@ module GraphqlRails
|
|
68
68
|
@connection_type ||= BuildConnectionType.call(graphql_type)
|
69
69
|
end
|
70
70
|
|
71
|
+
def with_ensured_fields!
|
72
|
+
return self if @graphql_type.blank?
|
73
|
+
|
74
|
+
reset_graphql_type if attributes.any? && graphql_type.fields.length != attributes.length
|
75
|
+
|
76
|
+
self
|
77
|
+
end
|
78
|
+
|
71
79
|
private
|
72
80
|
|
73
81
|
attr_reader :model_class
|
@@ -75,6 +83,16 @@ module GraphqlRails
|
|
75
83
|
def default_name
|
76
84
|
@default_name ||= model_class.name.split('::').last
|
77
85
|
end
|
86
|
+
|
87
|
+
def reset_graphql_type
|
88
|
+
@graphql_type = FindOrBuildGraphqlType.call(
|
89
|
+
name: name,
|
90
|
+
description: description,
|
91
|
+
attributes: attributes,
|
92
|
+
type_name: type_name,
|
93
|
+
force_define_attributes: true
|
94
|
+
)
|
95
|
+
end
|
78
96
|
end
|
79
97
|
end
|
80
98
|
end
|
@@ -10,20 +10,21 @@ module GraphqlRails
|
|
10
10
|
|
11
11
|
include ::GraphqlRails::Service
|
12
12
|
|
13
|
-
def initialize(name:, description:, attributes:, type_name:)
|
13
|
+
def initialize(name:, description:, attributes:, type_name:, force_define_attributes: false)
|
14
14
|
@name = name
|
15
15
|
@description = description
|
16
16
|
@attributes = attributes
|
17
17
|
@type_name = type_name
|
18
|
+
@force_define_attributes = force_define_attributes
|
18
19
|
end
|
19
20
|
|
20
21
|
def call
|
21
|
-
klass.tap { add_fields_to_graphql_type if new_class? }
|
22
|
+
klass.tap { add_fields_to_graphql_type if new_class? || force_define_attributes }
|
22
23
|
end
|
23
24
|
|
24
25
|
private
|
25
26
|
|
26
|
-
attr_reader :name, :description, :attributes, :type_name
|
27
|
+
attr_reader :name, :description, :attributes, :type_name, :force_define_attributes
|
27
28
|
|
28
29
|
delegate :klass, :new_class?, to: :type_class_finder
|
29
30
|
|
@@ -21,6 +21,10 @@ module GraphqlRails
|
|
21
21
|
raw = raw_actions
|
22
22
|
|
23
23
|
Class.new(GraphQL::Schema) do
|
24
|
+
connections.add(
|
25
|
+
GraphqlRails::Decorator::RelationDecorator,
|
26
|
+
GraphQL::Pagination::ActiveRecordRelationConnection
|
27
|
+
)
|
24
28
|
cursor_encoder(Router::PlainCursorEncoder)
|
25
29
|
raw.each { |action| send(action[:name], *action[:args], &action[:block]) }
|
26
30
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: graphql_rails
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.2.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Povilas Jurčys
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2021-05-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: graphql
|
@@ -16,20 +16,20 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: '1.
|
19
|
+
version: '1.12'
|
20
20
|
- - ">="
|
21
21
|
- !ruby/object:Gem::Version
|
22
|
-
version: 1.
|
22
|
+
version: 1.12.4
|
23
23
|
type: :runtime
|
24
24
|
prerelease: false
|
25
25
|
version_requirements: !ruby/object:Gem::Requirement
|
26
26
|
requirements:
|
27
27
|
- - "~>"
|
28
28
|
- !ruby/object:Gem::Version
|
29
|
-
version: '1.
|
29
|
+
version: '1.12'
|
30
30
|
- - ">="
|
31
31
|
- !ruby/object:Gem::Version
|
32
|
-
version: 1.
|
32
|
+
version: 1.12.4
|
33
33
|
- !ruby/object:Gem::Dependency
|
34
34
|
name: activesupport
|
35
35
|
requirement: !ruby/object:Gem::Requirement
|
@@ -128,7 +128,7 @@ dependencies:
|
|
128
128
|
- - "~>"
|
129
129
|
- !ruby/object:Gem::Version
|
130
130
|
version: '6'
|
131
|
-
description:
|
131
|
+
description:
|
132
132
|
email:
|
133
133
|
- po.jurcys@gmail.com
|
134
134
|
executables: []
|
@@ -232,7 +232,7 @@ homepage: https://github.com/samesystem/graphql_rails
|
|
232
232
|
licenses:
|
233
233
|
- MIT
|
234
234
|
metadata: {}
|
235
|
-
post_install_message:
|
235
|
+
post_install_message:
|
236
236
|
rdoc_options: []
|
237
237
|
require_paths:
|
238
238
|
- lib
|
@@ -248,7 +248,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
248
248
|
version: '0'
|
249
249
|
requirements: []
|
250
250
|
rubygems_version: 3.1.2
|
251
|
-
signing_key:
|
251
|
+
signing_key:
|
252
252
|
specification_version: 4
|
253
253
|
summary: Rails style structure for GraphQL API.
|
254
254
|
test_files: []
|