apiql 0.3.2 → 0.3.3
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/apiql.gemspec +1 -1
- data/lib/apiql.rb +40 -23
- 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: bdbc7a6ae370719e2cf99317eecb62b1d55cb102f5e6c139efbaf3f834af3fe9
|
4
|
+
data.tar.gz: fe6cd1969365185700487d36ea7f4daaad0c3adbb344207ea14237a7299af709
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4e88a8c04a5f968a4a3ef2ce409ed68df1791103ff04732550b88cec6e6936145ae79054d99ad8102dbc8b448f015ddda9d399d28aa48e47e9762f78d2cc7fb1
|
7
|
+
data.tar.gz: 8adb7c155531070ea9a33292d0243fe0c4007f3f3c90da09103199ba25f0a4d323316cd7d215984559fe65087022e78a98f73fdb8d0e228f698698b7f9b61bf8
|
data/apiql.gemspec
CHANGED
data/lib/apiql.rb
CHANGED
@@ -41,6 +41,28 @@ class APIQL
|
|
41
41
|
value.is_a?(Hash)
|
42
42
|
end
|
43
43
|
|
44
|
+
def eager_loads(schema)
|
45
|
+
result = []
|
46
|
+
|
47
|
+
schema&.each do |call|
|
48
|
+
if call.is_a? Hash
|
49
|
+
call.each do |function, sub_schema|
|
50
|
+
next if function.include? '('
|
51
|
+
function = function.split('.').first if function.include? '.'
|
52
|
+
|
53
|
+
sub = eager_loads(sub_schema)
|
54
|
+
if sub.present?
|
55
|
+
result.push(function => sub)
|
56
|
+
else
|
57
|
+
result.push function
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
result
|
64
|
+
end
|
65
|
+
|
44
66
|
private
|
45
67
|
|
46
68
|
def redis
|
@@ -122,7 +144,7 @@ class APIQL
|
|
122
144
|
function = reg[:name]
|
123
145
|
params = @context.parse_params(reg[:params].presence)
|
124
146
|
|
125
|
-
@eager_load = eager_loads(sub_schema)
|
147
|
+
@eager_load = APIQL::eager_loads(sub_schema)
|
126
148
|
data = public_send(function, *params)
|
127
149
|
if @eager_load.present? && !data.is_a?(::Hash) && !data.is_a?(::Array)
|
128
150
|
if data.respond_to?(:each) && data.respond_to?(:map)
|
@@ -160,28 +182,6 @@ class APIQL
|
|
160
182
|
|
161
183
|
private
|
162
184
|
|
163
|
-
def eager_loads(schema)
|
164
|
-
result = []
|
165
|
-
|
166
|
-
schema.each do |call|
|
167
|
-
if call.is_a? Hash
|
168
|
-
call.each do |function, sub_schema|
|
169
|
-
next if function.include? '('
|
170
|
-
function = function.split('.').first if function.include? '.'
|
171
|
-
|
172
|
-
sub = eager_loads(sub_schema)
|
173
|
-
if sub.present?
|
174
|
-
result.push(function => sub)
|
175
|
-
else
|
176
|
-
result.push function
|
177
|
-
end
|
178
|
-
end
|
179
|
-
end
|
180
|
-
end
|
181
|
-
|
182
|
-
result
|
183
|
-
end
|
184
|
-
|
185
185
|
class Entity
|
186
186
|
class << self
|
187
187
|
attr_reader :apiql_attributes
|
@@ -280,9 +280,26 @@ class APIQL
|
|
280
280
|
end
|
281
281
|
end
|
282
282
|
|
283
|
+
def eager_load
|
284
|
+
result = @eager_load
|
285
|
+
|
286
|
+
@eager_load = nil
|
287
|
+
|
288
|
+
result
|
289
|
+
end
|
290
|
+
|
283
291
|
def render_attribute(field, params = nil, schema = nil)
|
292
|
+
@eager_load = APIQL::eager_loads(schema)
|
284
293
|
data = get_field(field, params)
|
285
294
|
|
295
|
+
if @eager_load.present? && !data.is_a?(::Hash) && !data.is_a?(::Array)
|
296
|
+
if data.respond_to?(:each) && data.respond_to?(:map)
|
297
|
+
unless data.loaded?
|
298
|
+
data = data.eager_load(eager_load)
|
299
|
+
end
|
300
|
+
end
|
301
|
+
end
|
302
|
+
|
286
303
|
if data.is_a?(Hash) && schema.present?
|
287
304
|
respond = {}
|
288
305
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: apiql
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Dmitry Silchenko
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-07-
|
11
|
+
date: 2018-07-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|