graphiti_gql 0.2.30 → 0.2.33
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +2 -0
- data/lib/graphiti_gql/graphiti_hax.rb +9 -6
- data/lib/graphiti_gql/loaders/belongs_to.rb +10 -3
- data/lib/graphiti_gql/log_subscriber.rb +8 -2
- data/lib/graphiti_gql/schema/fields/index.rb +1 -1
- data/lib/graphiti_gql/schema/fields/to_many.rb +3 -1
- data/lib/graphiti_gql/schema/query.rb +1 -1
- data/lib/graphiti_gql/schema/registry.rb +3 -2
- data/lib/graphiti_gql/schema/resource_type.rb +43 -32
- data/lib/graphiti_gql/schema.rb +4 -0
- data/lib/graphiti_gql/version.rb +1 -1
- metadata +2 -3
- data/Gemfile.lock +0 -94
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 19b3af9f398319f335154dfffbf0eb8b13987a7ce7860bfaf273b18361715a57
|
4
|
+
data.tar.gz: e2c2e261a65e161817ed1f1a6aca5d07324dce1df984e37c2a40c18694d6fc27
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9f0cc9d62355cbf98382b1af4f0085fca190a19546be02d8d17e4bd7d93f548964f5716a13f2acc47083484ea386df604e845776bfd76dc2dbd22a44898d1605
|
7
|
+
data.tar.gz: 68f697d8c75a8787a9ee23dd0263a96df8bfd70e873015e67f43c34ec7d84e9bf1b07e51766ae550fb503d19cd810a9b014d273902ad0cce2e65dc054d87bb5e
|
data/.gitignore
CHANGED
@@ -143,12 +143,21 @@ module GraphitiGql
|
|
143
143
|
end
|
144
144
|
end
|
145
145
|
|
146
|
+
def paginatable=(val)
|
147
|
+
config[:paginatable] = val
|
148
|
+
end
|
149
|
+
|
150
|
+
def paginatable
|
151
|
+
config[:paginatable] == false ? false : true
|
152
|
+
end
|
153
|
+
|
146
154
|
def value_object?
|
147
155
|
!!config[:is_value_object]
|
148
156
|
end
|
149
157
|
|
150
158
|
def value_object!
|
151
159
|
config[:is_value_object] = true
|
160
|
+
self.graphql_entrypoint = false
|
152
161
|
self.adapter = ::Graphiti::Adapters::Null
|
153
162
|
config[:filters] = {}
|
154
163
|
config[:stats] = {}
|
@@ -581,12 +590,6 @@ class Graphiti::ValueObjectAssociation
|
|
581
590
|
@resource_class ||= Graphiti::Util::Class
|
582
591
|
.infer_resource_class(@parent_resource_class, name)
|
583
592
|
end
|
584
|
-
|
585
|
-
def build_resource(parent)
|
586
|
-
instance = resource_class.new
|
587
|
-
instance.parent = parent
|
588
|
-
instance
|
589
|
-
end
|
590
593
|
end
|
591
594
|
|
592
595
|
module Graphiti
|
@@ -20,7 +20,7 @@ module GraphitiGql
|
|
20
20
|
ids.compact!
|
21
21
|
return if ids.empty?
|
22
22
|
|
23
|
-
if @params[:simpleid]
|
23
|
+
if @params[:simpleid] && !to_polymorphic_resource?
|
24
24
|
if @sideload.type == :polymorphic_belongs_to
|
25
25
|
ids.each do |id|
|
26
26
|
child = @sideload.children.values.find { |c| c.group_name == id[:type].to_sym }
|
@@ -55,8 +55,9 @@ module GraphitiGql
|
|
55
55
|
end
|
56
56
|
values = futures.map(&:value)
|
57
57
|
ids.each do |id|
|
58
|
-
|
59
|
-
|
58
|
+
records_for_type = values.find { |v| v[:type] == id[:type] }
|
59
|
+
corresponding = records_for_type[:data].find { |r| r.id == id[:id] }
|
60
|
+
fulfill(id, corresponding)
|
60
61
|
end
|
61
62
|
else
|
62
63
|
resource = Schema.registry.get(@sideload.resource.class)[:resource]
|
@@ -74,6 +75,12 @@ module GraphitiGql
|
|
74
75
|
end
|
75
76
|
end
|
76
77
|
end
|
78
|
+
|
79
|
+
private
|
80
|
+
|
81
|
+
def to_polymorphic_resource?
|
82
|
+
@sideload.resource.polymorphic? && @sideload.type != :polymorphic_belongs_to
|
83
|
+
end
|
77
84
|
end
|
78
85
|
end
|
79
86
|
end
|
@@ -76,8 +76,14 @@ end|, :white, true)
|
|
76
76
|
if response_errors
|
77
77
|
Graphiti.info("❌🚨 Response contained errors!", :red, true)
|
78
78
|
response_errors.each do |err|
|
79
|
-
|
80
|
-
|
79
|
+
if err['extensions']
|
80
|
+
Graphiti.info("#{err['extensions']['code']} - #{err['message']}", :red, true)
|
81
|
+
else
|
82
|
+
Graphiti.info(err['message'], :red, true)
|
83
|
+
end
|
84
|
+
if err['path']
|
85
|
+
Graphiti.info("#{err['path'].join(".")}", :red, false) if err['path']
|
86
|
+
end
|
81
87
|
end
|
82
88
|
end
|
83
89
|
else
|
@@ -12,8 +12,8 @@ module GraphitiGql
|
|
12
12
|
@registered[:type].connection_type,
|
13
13
|
null: false,
|
14
14
|
connection: false,
|
15
|
-
extensions: [RelayConnectionExtension],
|
16
15
|
extras: [:lookahead]
|
16
|
+
field.extension(RelayConnectionExtension, resource: resource)
|
17
17
|
ListArguments.new(resource).apply(field)
|
18
18
|
query.define_method name do |**arguments|
|
19
19
|
params = Util.params_from_args(arguments)
|
@@ -14,11 +14,13 @@ module GraphitiGql
|
|
14
14
|
connection: false,
|
15
15
|
extras: [:lookahead]
|
16
16
|
}
|
17
|
-
opts[:extensions] = [RelayConnectionExtension] unless has_one?
|
18
17
|
field_type = has_one? ? @sideload_type : @connection_type
|
19
18
|
field = type.field @sideload.name,
|
20
19
|
field_type,
|
21
20
|
**opts
|
21
|
+
unless has_one?
|
22
|
+
field.extension(RelayConnectionExtension, resource: @sideload.resource.class)
|
23
|
+
end
|
22
24
|
ListArguments.new(@sideload.resource.class, @sideload).apply(field)
|
23
25
|
_sideload = @sideload
|
24
26
|
type.define_method(@sideload.name) do |**arguments|
|
@@ -38,7 +38,7 @@ module GraphitiGql
|
|
38
38
|
end
|
39
39
|
|
40
40
|
def add_value_objects
|
41
|
-
registry.resource_types.each do |registered|
|
41
|
+
registry.resource_types(value_objects: false).each do |registered|
|
42
42
|
resource, type = registered[:resource], registered[:type]
|
43
43
|
ResourceType.add_value_objects(resource, type)
|
44
44
|
end
|
@@ -50,10 +50,11 @@ module GraphitiGql
|
|
50
50
|
end
|
51
51
|
|
52
52
|
# When polymorphic parent, returns the Interface not the Class
|
53
|
-
def resource_types
|
53
|
+
def resource_types(value_objects: true)
|
54
54
|
values
|
55
55
|
.select { |v| v.key?(:resource) }
|
56
|
-
.reject { |v| v[:interface]
|
56
|
+
.reject { |v| v[:interface] }
|
57
|
+
.reject { |v| !value_objects && v[:resource].value_object? }
|
57
58
|
.map { |registered| get(registered[:resource]) }
|
58
59
|
end
|
59
60
|
|
@@ -6,8 +6,9 @@ module GraphitiGql
|
|
6
6
|
|
7
7
|
definition_methods do
|
8
8
|
# Optional: if this method is defined, it overrides `Schema.resolve_type`
|
9
|
-
def resolve_type(object,
|
9
|
+
def resolve_type(object, _context)
|
10
10
|
return object.type if object.is_a?(Loaders::FakeRecord)
|
11
|
+
|
11
12
|
resource = object.instance_variable_get(:@__graphiti_resource)
|
12
13
|
Registry.instance.get(resource.class)[:type]
|
13
14
|
end
|
@@ -17,9 +18,8 @@ module GraphitiGql
|
|
17
18
|
def self.add_fields(type, resource, id: true) # id: false for edges
|
18
19
|
resource.attributes.each_pair do |name, config|
|
19
20
|
next if name == :id && id == false
|
20
|
-
|
21
|
-
|
22
|
-
end
|
21
|
+
|
22
|
+
Fields::Attribute.new(resource, name, config).apply(type) if config[:readable]
|
23
23
|
end
|
24
24
|
end
|
25
25
|
|
@@ -27,31 +27,31 @@ module GraphitiGql
|
|
27
27
|
resource.config[:value_objects].each_pair do |name, vo_association|
|
28
28
|
vo_resource_class = vo_association.resource_class
|
29
29
|
value_object_type = Schema.registry.get(vo_resource_class)[:type]
|
30
|
-
if vo_association.array?
|
31
|
-
value_object_type = [value_object_type]
|
32
|
-
end
|
30
|
+
value_object_type = [value_object_type] if vo_association.array?
|
33
31
|
|
34
32
|
_array = vo_association.array?
|
35
33
|
opts = { null: vo_association.null }
|
36
34
|
opts[:deprecation_reason] = vo_association.deprecation_reason if vo_association.deprecation_reason
|
37
35
|
type.field name, value_object_type, **opts
|
38
36
|
type.define_method name do
|
39
|
-
if (method_name = vo_association.readable)
|
40
|
-
|
41
|
-
|
42
|
-
.new(vo_association.parent_resource_class, name)
|
43
|
-
end
|
37
|
+
if (method_name = vo_association.readable) && !vo_association.parent_resource_class.new.send(method_name)
|
38
|
+
raise ::Graphiti::Errors::UnreadableAttribute
|
39
|
+
.new(vo_association.parent_resource_class, name)
|
44
40
|
end
|
45
41
|
|
46
42
|
result = vo_resource_class.all({ parent: object }).to_a
|
47
43
|
default_behavior = result == [object]
|
48
|
-
result = result.first
|
44
|
+
result = result.first unless _array
|
49
45
|
if default_behavior
|
50
46
|
method_name = vo_association.alias.presence || name
|
51
47
|
result = object.send(method_name)
|
52
|
-
if _array && !result.is_a?(Array)
|
53
|
-
|
54
|
-
|
48
|
+
raise Graphiti::Errors::InvalidValueObject.new(resource, name, result) if _array && !result.is_a?(Array)
|
49
|
+
end
|
50
|
+
# For polymorphic value objects
|
51
|
+
if result.is_a?(Array)
|
52
|
+
result.each { |r| r.instance_variable_set(:@__parent, object) }
|
53
|
+
else
|
54
|
+
result.instance_variable_set(:@__parent, object) if result
|
55
55
|
end
|
56
56
|
result
|
57
57
|
end
|
@@ -59,19 +59,19 @@ module GraphitiGql
|
|
59
59
|
end
|
60
60
|
|
61
61
|
def self.add_relationships(resource, type)
|
62
|
-
resource.sideloads.each do |
|
62
|
+
resource.sideloads.each do |_name, sideload|
|
63
63
|
next unless sideload.readable?
|
64
64
|
|
65
65
|
registered_sl = if sideload.type == :polymorphic_belongs_to
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
66
|
+
PolymorphicBelongsToInterface
|
67
|
+
.new(resource, sideload)
|
68
|
+
.build
|
69
|
+
else
|
70
|
+
Schema.registry.get(sideload.resource.class)
|
71
|
+
end
|
72
72
|
sideload_type = registered_sl[:type]
|
73
73
|
|
74
|
-
if [
|
74
|
+
if %i[has_many many_to_many has_one].include?(sideload.type)
|
75
75
|
Fields::ToMany.new(sideload, sideload_type).apply(type)
|
76
76
|
else
|
77
77
|
Fields::ToOne.new(sideload, sideload_type).apply(type)
|
@@ -86,6 +86,7 @@ module GraphitiGql
|
|
86
86
|
|
87
87
|
def build
|
88
88
|
return registry.get(@resource)[:type] if registry.get(@resource)
|
89
|
+
|
89
90
|
type = build_base_type
|
90
91
|
registry_name = registry.key_for(@resource, interface: poly_parent?)
|
91
92
|
type.connection_type_class(build_connection_class)
|
@@ -108,6 +109,7 @@ module GraphitiGql
|
|
108
109
|
# Define the actual class that implements the interface
|
109
110
|
registry.set(@resource, type, interface: false)
|
110
111
|
@resource.children.each do |child|
|
112
|
+
registry.get(child)
|
111
113
|
if (registered = registry.get(child))
|
112
114
|
registered[:type].implements(interface_type)
|
113
115
|
else
|
@@ -128,12 +130,14 @@ module GraphitiGql
|
|
128
130
|
klass.send(:include, BaseInterface)
|
129
131
|
ctx = nil
|
130
132
|
klass.definition_methods { ctx = self }
|
131
|
-
|
132
|
-
|
133
|
-
registry_name = Registry.instance.key_for(
|
134
|
-
if
|
135
|
-
|
136
|
-
|
133
|
+
_resource = @resource
|
134
|
+
ctx.define_method :resolve_type do |object, _context|
|
135
|
+
registry_name = Registry.instance.key_for(_resource)
|
136
|
+
if _resource.polymorphic?
|
137
|
+
parent = object.instance_variable_get(:@__parent)
|
138
|
+
# pass parent for polymorphic value objects
|
139
|
+
_resource = _resource.resource_for_model(parent || object)
|
140
|
+
registry_name = Registry.instance.key_for(_resource)
|
137
141
|
end
|
138
142
|
Registry.instance[registry_name][:type]
|
139
143
|
end
|
@@ -141,8 +145,15 @@ module GraphitiGql
|
|
141
145
|
klass = Class.new(Schema.base_object)
|
142
146
|
end
|
143
147
|
|
148
|
+
if @resource.value_object?
|
149
|
+
klass.define_method :parent do
|
150
|
+
object.instance_variable_get(:@__parent)
|
151
|
+
end
|
152
|
+
end
|
153
|
+
|
144
154
|
klass.define_method :resource do
|
145
155
|
return @resource if @resource
|
156
|
+
|
146
157
|
resource = object.instance_variable_get(:@__graphiti_resource)
|
147
158
|
resource_class = resource.class
|
148
159
|
if resource_class.polymorphic? && !resource_class.polymorphic_child?
|
@@ -165,7 +176,7 @@ module GraphitiGql
|
|
165
176
|
|
166
177
|
def add_fields(type, resource)
|
167
178
|
self.class.add_fields(type, resource)
|
168
|
-
end
|
179
|
+
end
|
169
180
|
|
170
181
|
def build_connection_class
|
171
182
|
klass = Class.new(GraphQL::Types::Relay::BaseConnection)
|
@@ -174,4 +185,4 @@ module GraphitiGql
|
|
174
185
|
end
|
175
186
|
end
|
176
187
|
end
|
177
|
-
end
|
188
|
+
end
|
data/lib/graphiti_gql/schema.rb
CHANGED
@@ -62,6 +62,10 @@ module GraphitiGql
|
|
62
62
|
}
|
63
63
|
|
64
64
|
class RelayConnectionExtension < GraphQL::Schema::Field::ConnectionExtension
|
65
|
+
def apply
|
66
|
+
super if options[:resource].paginatable
|
67
|
+
end
|
68
|
+
|
65
69
|
def resolve(object:, arguments:, context:)
|
66
70
|
next_args = arguments.dup
|
67
71
|
yield(object, next_args, arguments)
|
data/lib/graphiti_gql/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: graphiti_gql
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.33
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Lee Richmond
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-
|
11
|
+
date: 2022-09-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: graphql
|
@@ -126,7 +126,6 @@ files:
|
|
126
126
|
- ".rspec"
|
127
127
|
- ".travis.yml"
|
128
128
|
- Gemfile
|
129
|
-
- Gemfile.lock
|
130
129
|
- LICENSE.txt
|
131
130
|
- README.md
|
132
131
|
- Rakefile
|
data/Gemfile.lock
DELETED
@@ -1,94 +0,0 @@
|
|
1
|
-
PATH
|
2
|
-
remote: .
|
3
|
-
specs:
|
4
|
-
graphiti_gql (0.2.29)
|
5
|
-
activemodel (> 6.0, < 8.0)
|
6
|
-
graphiti (~> 1.3.9)
|
7
|
-
graphql (~> 2.0)
|
8
|
-
graphql-batch (~> 0.5)
|
9
|
-
|
10
|
-
GEM
|
11
|
-
remote: https://rubygems.org/
|
12
|
-
specs:
|
13
|
-
activemodel (7.0.3)
|
14
|
-
activesupport (= 7.0.3)
|
15
|
-
activesupport (7.0.3)
|
16
|
-
concurrent-ruby (~> 1.0, >= 1.0.2)
|
17
|
-
i18n (>= 1.6, < 2)
|
18
|
-
minitest (>= 5.1)
|
19
|
-
tzinfo (~> 2.0)
|
20
|
-
byebug (11.1.3)
|
21
|
-
coderay (1.1.3)
|
22
|
-
concurrent-ruby (1.1.10)
|
23
|
-
diff-lcs (1.5.0)
|
24
|
-
dry-container (0.10.1)
|
25
|
-
concurrent-ruby (~> 1.0)
|
26
|
-
dry-core (0.8.1)
|
27
|
-
concurrent-ruby (~> 1.0)
|
28
|
-
dry-inflector (0.3.0)
|
29
|
-
dry-logic (1.2.0)
|
30
|
-
concurrent-ruby (~> 1.0)
|
31
|
-
dry-core (~> 0.5, >= 0.5)
|
32
|
-
dry-types (1.5.1)
|
33
|
-
concurrent-ruby (~> 1.0)
|
34
|
-
dry-container (~> 0.3)
|
35
|
-
dry-core (~> 0.5, >= 0.5)
|
36
|
-
dry-inflector (~> 0.1, >= 0.1.2)
|
37
|
-
dry-logic (~> 1.0, >= 1.0.2)
|
38
|
-
graphiti (1.3.9)
|
39
|
-
activesupport (>= 5.2)
|
40
|
-
concurrent-ruby (~> 1.0)
|
41
|
-
dry-types (>= 0.15.0, < 2.0)
|
42
|
-
graphiti_errors (~> 1.1.0)
|
43
|
-
jsonapi-renderer (~> 0.2, >= 0.2.2)
|
44
|
-
jsonapi-serializable (~> 0.3.0)
|
45
|
-
graphiti_errors (1.1.2)
|
46
|
-
jsonapi-serializable (~> 0.1)
|
47
|
-
graphql (2.0.12)
|
48
|
-
graphql-batch (0.5.1)
|
49
|
-
graphql (>= 1.10, < 3)
|
50
|
-
promise.rb (~> 0.7.2)
|
51
|
-
i18n (1.12.0)
|
52
|
-
concurrent-ruby (~> 1.0)
|
53
|
-
jsonapi-renderer (0.2.2)
|
54
|
-
jsonapi-serializable (0.3.1)
|
55
|
-
jsonapi-renderer (~> 0.2.0)
|
56
|
-
method_source (1.0.0)
|
57
|
-
minitest (5.16.2)
|
58
|
-
promise.rb (0.7.4)
|
59
|
-
pry (0.13.1)
|
60
|
-
coderay (~> 1.1)
|
61
|
-
method_source (~> 1.0)
|
62
|
-
pry-byebug (3.9.0)
|
63
|
-
byebug (~> 11.0)
|
64
|
-
pry (~> 0.13.0)
|
65
|
-
rake (10.5.0)
|
66
|
-
rspec (3.11.0)
|
67
|
-
rspec-core (~> 3.11.0)
|
68
|
-
rspec-expectations (~> 3.11.0)
|
69
|
-
rspec-mocks (~> 3.11.0)
|
70
|
-
rspec-core (3.11.0)
|
71
|
-
rspec-support (~> 3.11.0)
|
72
|
-
rspec-expectations (3.11.0)
|
73
|
-
diff-lcs (>= 1.2.0, < 2.0)
|
74
|
-
rspec-support (~> 3.11.0)
|
75
|
-
rspec-mocks (3.11.1)
|
76
|
-
diff-lcs (>= 1.2.0, < 2.0)
|
77
|
-
rspec-support (~> 3.11.0)
|
78
|
-
rspec-support (3.11.0)
|
79
|
-
tzinfo (2.0.5)
|
80
|
-
concurrent-ruby (~> 1.0)
|
81
|
-
|
82
|
-
PLATFORMS
|
83
|
-
arm64-darwin-21
|
84
|
-
|
85
|
-
DEPENDENCIES
|
86
|
-
bundler (~> 2.3)
|
87
|
-
graphiti_gql!
|
88
|
-
pry
|
89
|
-
pry-byebug
|
90
|
-
rake (~> 10.0)
|
91
|
-
rspec (~> 3.0)
|
92
|
-
|
93
|
-
BUNDLED WITH
|
94
|
-
2.3.12
|