graphiti_gql 0.2.31 → 0.2.32
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/graphiti_gql/graphiti_hax.rb +1 -6
- data/lib/graphiti_gql/log_subscriber.rb +8 -2
- 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/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e8d0cda6314cfd3485283ae277bdaa56494a4b8eae9c62f9037b5b78f17b2825
|
4
|
+
data.tar.gz: 28fcbab36f65c81bb8a673aefaefe7bd54888f02ca741fcf5a889f2f858e094a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 864e7b0fbd88fb01f3aa8bc0490ce144a4d62e02c9d9ce30dc032f6209b91cf9e5766b06bf85113cbdb9d4603dd397b8b831fcbc8f76ff123ff12307e82a4815
|
7
|
+
data.tar.gz: 61304ca30da99696a76c625c3737037429182df25ca6271c9f779bbbfa96740e2d1b3c792cbaaea560a31b52edc90f342b49a8aab12d607ece04804415e3d1e1
|
@@ -149,6 +149,7 @@ module GraphitiGql
|
|
149
149
|
|
150
150
|
def value_object!
|
151
151
|
config[:is_value_object] = true
|
152
|
+
self.graphql_entrypoint = false
|
152
153
|
self.adapter = ::Graphiti::Adapters::Null
|
153
154
|
config[:filters] = {}
|
154
155
|
config[:stats] = {}
|
@@ -581,12 +582,6 @@ class Graphiti::ValueObjectAssociation
|
|
581
582
|
@resource_class ||= Graphiti::Util::Class
|
582
583
|
.infer_resource_class(@parent_resource_class, name)
|
583
584
|
end
|
584
|
-
|
585
|
-
def build_resource(parent)
|
586
|
-
instance = resource_class.new
|
587
|
-
instance.parent = parent
|
588
|
-
instance
|
589
|
-
end
|
590
585
|
end
|
591
586
|
|
592
587
|
module Graphiti
|
@@ -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
|
@@ -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/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.32
|
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-02 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: graphql
|