pggraphql 0.0.11 → 0.0.12
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/lib/pggraphql/version.rb +1 -1
- data/lib/pggraphql.rb +29 -11
- data/test/test_pggraphql.rb +115 -79
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b04ff239be18d90b85971b13eb3f7722a28de47a
|
4
|
+
data.tar.gz: 360719c079f33dd65b4ddaebd4fd87bc95782b50
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 90fd83702b235304dd8c60981f7a0521e20cecb1e26b3df3b07a5b6d8ef86d56038f201f1d8b9f884975ad24e4d294f85f1c40e3286a7eaf4a675a3d5e3c247b
|
7
|
+
data.tar.gz: 32d51411460608e6a375d3e198201b43b0c211afbba68bb9c1a7b58edfb63d8ad8824138fd449804cd2755197123b4e69e2eb76031ad3bf6ddc5f15f095feab1
|
data/lib/pggraphql/version.rb
CHANGED
data/lib/pggraphql.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
require "active_support/all"
|
2
|
+
require "sequel"
|
2
3
|
require "pggraphql/version"
|
3
4
|
|
4
5
|
module PgGraphQl
|
@@ -23,7 +24,18 @@ module PgGraphQl
|
|
23
24
|
yield(type) if block_given?
|
24
25
|
end
|
25
26
|
|
26
|
-
def
|
27
|
+
def handle_sql_part(part, params)
|
28
|
+
if part.is_a?(Array)
|
29
|
+
part.slice(1..-1).each{|param| params << param}
|
30
|
+
part[0]
|
31
|
+
elsif part.is_a?(String)
|
32
|
+
part
|
33
|
+
else
|
34
|
+
raise "unsupported sql part: #{part}"
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
def to_sql(query, level=0, params=[], parent=nil, link_name=nil)
|
27
39
|
if level > 0
|
28
40
|
query.map do |e|
|
29
41
|
link = parent ? parent.links[link_name] : nil
|
@@ -49,7 +61,7 @@ module PgGraphQl
|
|
49
61
|
raise "unknown link #{field_name.inspect} on type #{type.name.inspect}" if f[1].is_a?(Hash) && !type.links.include?(field_name)
|
50
62
|
|
51
63
|
if f[1].is_a?(Hash)
|
52
|
-
"(" + to_sql([f].to_h, level + 1, type, nested_link_name) + ") as #{field_name}"
|
64
|
+
"(" + to_sql([f].to_h, level + 1, params, type, nested_link_name) + ") as #{field_name}"
|
53
65
|
else
|
54
66
|
field_def = type.fields.detect{|f| f[:name] == field_name}
|
55
67
|
|
@@ -78,13 +90,15 @@ module PgGraphQl
|
|
78
90
|
|
79
91
|
raise "missing :id for root type #{type.name.inspect}" if !ids && level == 1 && !type.null_pk
|
80
92
|
|
81
|
-
|
93
|
+
if ids && type.pk.call(ids, level)
|
94
|
+
wheres << handle_sql_part(type.pk.call(ids, level), params)
|
95
|
+
end
|
82
96
|
|
83
|
-
wheres << ("(" + type.filter + ")") if type.filter
|
97
|
+
wheres << ("(" + handle_sql_part(type.filter, params) + ")") if type.filter
|
84
98
|
|
85
99
|
if link
|
86
|
-
wheres << ("(" + link.fk + ")")
|
87
|
-
wheres << ("(" + link.filter + ")") if link.filter
|
100
|
+
wheres << ("(" + handle_sql_part(link.fk, params) + ")")
|
101
|
+
wheres << ("(" + handle_sql_part(link.filter, params) + ")") if link.filter
|
88
102
|
end
|
89
103
|
|
90
104
|
sql = "select to_json("
|
@@ -97,7 +111,7 @@ module PgGraphQl
|
|
97
111
|
unless type.subtypes.empty?
|
98
112
|
sql += "\n" + type.subtypes.map do |f|
|
99
113
|
subtype = f[1]
|
100
|
-
"left join #{subtype.table} as #{subtype.name} on (#{subtype.fk})"
|
114
|
+
"left join #{subtype.table} as #{subtype.name} on (#{handle_sql_part(subtype.fk, params)})"
|
101
115
|
end.join("\n")
|
102
116
|
end
|
103
117
|
|
@@ -109,10 +123,12 @@ module PgGraphQl
|
|
109
123
|
|
110
124
|
end.join
|
111
125
|
else
|
112
|
-
wrap_root(query.map do |e|
|
113
|
-
sql = to_sql([e].to_h, 1)
|
126
|
+
root_sql = wrap_root(query.map do |e|
|
127
|
+
sql = to_sql([e].to_h, 1, params)
|
114
128
|
"select '#{e[0]}'::text as key, (#{sql}) as value"
|
115
129
|
end.join("\nunion all\n"))
|
130
|
+
|
131
|
+
{sql: root_sql, params: params}
|
116
132
|
end
|
117
133
|
end
|
118
134
|
|
@@ -136,9 +152,11 @@ module PgGraphQl
|
|
136
152
|
@pk = ->(ids, level) do
|
137
153
|
id_column = "#{@table}.id"
|
138
154
|
if ids.is_a?(Array)
|
139
|
-
"#{id_column} in (" + ids.map{|id| id.is_a?(String) ? "'#{id}'" : id.to_s}.join(',') + ")"
|
155
|
+
# "#{id_column} in (" + ids.map{|id| id.is_a?(String) ? "'#{id}'" : id.to_s}.join(',') + ")"
|
156
|
+
["#{id_column} in ?", ids]
|
140
157
|
else
|
141
|
-
"#{id_column} = " + (ids.is_a?(String) ? "'#{ids}'" : "#{ids}")
|
158
|
+
# "#{id_column} = " + (ids.is_a?(String) ? "'#{ids}'" : "#{ids}")
|
159
|
+
["#{id_column} = ?", ids]
|
142
160
|
end
|
143
161
|
end
|
144
162
|
end
|
data/test/test_pggraphql.rb
CHANGED
@@ -15,9 +15,12 @@ module PgGraphQl
|
|
15
15
|
unwrapped_sql
|
16
16
|
end
|
17
17
|
|
18
|
-
|
18
|
+
res = s.to_sql(query)
|
19
|
+
|
20
|
+
sql, params = res.values_at(:sql, :params)
|
19
21
|
puts sql if print_sql
|
20
|
-
|
22
|
+
|
23
|
+
res
|
21
24
|
end
|
22
25
|
|
23
26
|
def test_simple
|
@@ -32,9 +35,11 @@ module PgGraphQl
|
|
32
35
|
from (select users.id,
|
33
36
|
email
|
34
37
|
from users
|
35
|
-
where users.id =
|
38
|
+
where users.id = ? limit 1) x) as value
|
36
39
|
SQL
|
37
|
-
), token(res)
|
40
|
+
), token(res[:sql])
|
41
|
+
|
42
|
+
assert_equal [1], res[:params]
|
38
43
|
|
39
44
|
# ---
|
40
45
|
|
@@ -49,9 +54,10 @@ module PgGraphQl
|
|
49
54
|
from (select users.id,
|
50
55
|
email
|
51
56
|
from users
|
52
|
-
where users.id =
|
57
|
+
where users.id = ? limit 1) x) as value
|
53
58
|
SQL
|
54
|
-
), token(res)
|
59
|
+
), token(res[:sql])
|
60
|
+
assert_equal [1], res[:params]
|
55
61
|
|
56
62
|
# ---
|
57
63
|
|
@@ -65,9 +71,11 @@ module PgGraphQl
|
|
65
71
|
(select to_json(coalesce(json_agg(x.*), '[]'::json))
|
66
72
|
from (select users.id,
|
67
73
|
email
|
68
|
-
from users) x) as value
|
74
|
+
from users) x) as value
|
69
75
|
SQL
|
70
|
-
), token(res)
|
76
|
+
), token(res[:sql])
|
77
|
+
assert_equal [], res[:params]
|
78
|
+
|
71
79
|
end
|
72
80
|
|
73
81
|
def test_simple_fail_when_accessing_non_root
|
@@ -106,7 +114,7 @@ module PgGraphQl
|
|
106
114
|
def test_simple_pk_custom
|
107
115
|
res = to_sql({user: {id: "1", email: "email"}}) do |s|
|
108
116
|
s.root :user
|
109
|
-
s.type :user, fields: [:email], pk: ->(id, level){ "access_token =
|
117
|
+
s.type :user, fields: [:email], pk: ->(id, level){ ["access_token = ?", id] }
|
110
118
|
end
|
111
119
|
|
112
120
|
assert_equal token(<<-SQL
|
@@ -114,15 +122,16 @@ module PgGraphQl
|
|
114
122
|
(select to_json(x.*)
|
115
123
|
from (select users.id,
|
116
124
|
email
|
117
|
-
from users where access_token =
|
125
|
+
from users where access_token = ? limit 1) x) as value
|
118
126
|
SQL
|
119
|
-
), token(res)
|
127
|
+
), token(res[:sql])
|
128
|
+
assert_equal ["1"], res[:params]
|
120
129
|
end
|
121
130
|
|
122
131
|
def test_simple_pk_with_level
|
123
132
|
res = to_sql({user: {id: "99", email: "email"}}) do |s|
|
124
133
|
s.root :user
|
125
|
-
s.type :user, fields: [:email], pk: ->(id, level){ "level#{level} =
|
134
|
+
s.type :user, fields: [:email], pk: ->(id, level){ ["level#{level} = ?", id] }
|
126
135
|
end
|
127
136
|
|
128
137
|
assert_equal token(<<-SQL
|
@@ -130,9 +139,10 @@ module PgGraphQl
|
|
130
139
|
(select to_json(x.*)
|
131
140
|
from (select users.id,
|
132
141
|
email
|
133
|
-
from users where level1 =
|
142
|
+
from users where level1 = ? limit 1) x) as value
|
134
143
|
SQL
|
135
|
-
), token(res)
|
144
|
+
), token(res[:sql])
|
145
|
+
assert_equal ["99"], res[:params]
|
136
146
|
end
|
137
147
|
|
138
148
|
def test_simple_pk_type_handling
|
@@ -146,9 +156,10 @@ module PgGraphQl
|
|
146
156
|
(select to_json(coalesce(json_agg(x.*), '[]'::json))
|
147
157
|
from (select users.id,
|
148
158
|
email
|
149
|
-
from users where users.id in
|
159
|
+
from users where users.id in ?) x) as value
|
150
160
|
SQL
|
151
|
-
), token(res)
|
161
|
+
), token(res[:sql])
|
162
|
+
assert_equal [["1"]], res[:params]
|
152
163
|
|
153
164
|
# ---
|
154
165
|
|
@@ -162,9 +173,10 @@ module PgGraphQl
|
|
162
173
|
(select to_json(x.*)
|
163
174
|
from (select users.id,
|
164
175
|
email
|
165
|
-
from users where users.id =
|
176
|
+
from users where users.id = ? limit 1) x) as value
|
166
177
|
SQL
|
167
|
-
), token(res)
|
178
|
+
), token(res[:sql])
|
179
|
+
assert_equal ["1"], res[:params]
|
168
180
|
end
|
169
181
|
|
170
182
|
def test_simple_pk_array_one
|
@@ -178,9 +190,10 @@ module PgGraphQl
|
|
178
190
|
(select to_json(coalesce(json_agg(x.*), '[]'::json))
|
179
191
|
from (select users.id,
|
180
192
|
email
|
181
|
-
from users where users.id in
|
193
|
+
from users where users.id in ?) x) as value
|
182
194
|
SQL
|
183
|
-
), token(res)
|
195
|
+
), token(res[:sql])
|
196
|
+
assert_equal [[1]], res[:params]
|
184
197
|
end
|
185
198
|
|
186
199
|
def test_simple_pk_array_multiple
|
@@ -194,9 +207,10 @@ module PgGraphQl
|
|
194
207
|
(select to_json(coalesce(json_agg(x.*), '[]'::json))
|
195
208
|
from (select users.id,
|
196
209
|
email
|
197
|
-
from users where users.id in
|
210
|
+
from users where users.id in ?) x) as value
|
198
211
|
SQL
|
199
|
-
), token(res)
|
212
|
+
), token(res[:sql])
|
213
|
+
assert_equal [[1,2]], res[:params]
|
200
214
|
|
201
215
|
# ---
|
202
216
|
|
@@ -210,9 +224,10 @@ module PgGraphQl
|
|
210
224
|
(select to_json(coalesce(json_agg(x.*), '[]'::json))
|
211
225
|
from (select users.id,
|
212
226
|
email
|
213
|
-
from users where users.id in
|
227
|
+
from users where users.id in ?) x) as value
|
214
228
|
SQL
|
215
|
-
), token(res)
|
229
|
+
), token(res[:sql])
|
230
|
+
assert_equal [["1","2"]], res[:params]
|
216
231
|
end
|
217
232
|
|
218
233
|
def test_simple_filter
|
@@ -227,9 +242,10 @@ module PgGraphQl
|
|
227
242
|
from (select users.id,
|
228
243
|
email
|
229
244
|
from users
|
230
|
-
where users.id =
|
245
|
+
where users.id = ? and (id > 100) limit 1) x) as value
|
231
246
|
SQL
|
232
|
-
), token(res)
|
247
|
+
), token(res[:sql])
|
248
|
+
assert_equal [1], res[:params]
|
233
249
|
end
|
234
250
|
|
235
251
|
def test_simple_multiple
|
@@ -246,14 +262,15 @@ module PgGraphQl
|
|
246
262
|
from (select users.id,
|
247
263
|
email
|
248
264
|
from users
|
249
|
-
where users.id =
|
265
|
+
where users.id = ? limit 1) x) as value
|
250
266
|
union all
|
251
267
|
select 'educator'::text as key,
|
252
268
|
(select to_json(x.*)
|
253
269
|
from (select educators.id
|
254
|
-
from educators where educators.id =
|
270
|
+
from educators where educators.id = ? limit 1) x) as value
|
255
271
|
SQL
|
256
|
-
), token(res)
|
272
|
+
), token(res[:sql])
|
273
|
+
assert_equal [1, 99], res[:params]
|
257
274
|
end
|
258
275
|
|
259
276
|
def test_simple_strange_nested_to_json_for_json_datatype_with_column_alias
|
@@ -268,9 +285,10 @@ module PgGraphQl
|
|
268
285
|
end
|
269
286
|
|
270
287
|
assert_equal token(<<-SQL
|
271
|
-
select 'flow'::text as key, (select to_json(x.*) from (select flows.id, data from flows where flows.id =
|
288
|
+
select 'flow'::text as key, (select to_json(x.*) from (select flows.id, data from flows where flows.id = ? limit 1) x) as value
|
272
289
|
SQL
|
273
|
-
), token(res)
|
290
|
+
), token(res[:sql])
|
291
|
+
assert_equal [1], res[:params]
|
274
292
|
|
275
293
|
# ------
|
276
294
|
|
@@ -282,9 +300,10 @@ module PgGraphQl
|
|
282
300
|
end
|
283
301
|
|
284
302
|
assert_equal token(<<-SQL
|
285
|
-
select 'flow'::text as key, (select to_json(x.*) from (select flows.id, data from flows where flows.id =
|
303
|
+
select 'flow'::text as key, (select to_json(x.*) from (select flows.id, data from flows where flows.id = ? limit 1) x) as value
|
286
304
|
SQL
|
287
|
-
), token(res)
|
305
|
+
), token(res[:sql])
|
306
|
+
assert_equal [1], res[:params]
|
288
307
|
|
289
308
|
# ------
|
290
309
|
|
@@ -296,9 +315,10 @@ module PgGraphQl
|
|
296
315
|
end
|
297
316
|
|
298
317
|
assert_equal token(<<-SQL
|
299
|
-
select 'flow'::text as key, (select to_json(x.*) from (select flows.id, to_json(data) as data from flows where flows.id =
|
318
|
+
select 'flow'::text as key, (select to_json(x.*) from (select flows.id, to_json(data) as data from flows where flows.id = ? limit 1) x) as value
|
300
319
|
SQL
|
301
|
-
), token(res)
|
320
|
+
), token(res[:sql])
|
321
|
+
assert_equal [1], res[:params]
|
302
322
|
|
303
323
|
# ------ positive check
|
304
324
|
|
@@ -310,9 +330,10 @@ module PgGraphQl
|
|
310
330
|
end
|
311
331
|
|
312
332
|
assert_equal token(<<-SQL
|
313
|
-
select 'flow'::text as key, (select to_json(x.*) from (select flows.id, to_json(data) from flows where flows.id =
|
333
|
+
select 'flow'::text as key, (select to_json(x.*) from (select flows.id, to_json(data) from flows where flows.id = ? limit 1) x) as value
|
314
334
|
SQL
|
315
|
-
), token(res)
|
335
|
+
), token(res[:sql])
|
336
|
+
assert_equal [1], res[:params]
|
316
337
|
|
317
338
|
end
|
318
339
|
|
@@ -370,7 +391,8 @@ module PgGraphQl
|
|
370
391
|
left join product_clickouts as clickout on (clickout.id = products.id
|
371
392
|
and products.type = 'clickout')) x) as value
|
372
393
|
SQL
|
373
|
-
), token(res)
|
394
|
+
), token(res[:sql])
|
395
|
+
assert_equal [], res[:params]
|
374
396
|
end
|
375
397
|
|
376
398
|
def test_inherit_with_pk
|
@@ -393,9 +415,10 @@ module PgGraphQl
|
|
393
415
|
clickout.destination_url as clickout__destination_url
|
394
416
|
from products
|
395
417
|
left join product_clickouts as clickout on (clickout.id = products.id
|
396
|
-
and products.type = 'clickout') where products.id =
|
418
|
+
and products.type = 'clickout') where products.id = ? limit 1) x) as value
|
397
419
|
SQL
|
398
|
-
), token(res)
|
420
|
+
), token(res[:sql])
|
421
|
+
assert_equal [1], res[:params]
|
399
422
|
|
400
423
|
end
|
401
424
|
|
@@ -421,11 +444,12 @@ module PgGraphQl
|
|
421
444
|
(select to_json(x.*)
|
422
445
|
from (select addresses.id
|
423
446
|
from addresses
|
424
|
-
where addresses.id =
|
447
|
+
where addresses.id = ? and (id = users.address_id) limit 1) x) as address
|
425
448
|
from users
|
426
|
-
where users.id =
|
449
|
+
where users.id = ? limit 1) x) as value
|
427
450
|
SQL
|
428
|
-
), token(res)
|
451
|
+
), token(res[:sql])
|
452
|
+
assert_equal ["99", 1], res[:params]
|
429
453
|
end
|
430
454
|
|
431
455
|
def test_link_one_nested_pk
|
@@ -445,11 +469,12 @@ module PgGraphQl
|
|
445
469
|
(select to_json(x.*)
|
446
470
|
from (select addresses.id
|
447
471
|
from addresses
|
448
|
-
where addresses.id =
|
472
|
+
where addresses.id = ? and (id = users.address_id) limit 1) x) as address
|
449
473
|
from users
|
450
|
-
where users.id =
|
474
|
+
where users.id = ? limit 1) x) as value
|
451
475
|
SQL
|
452
|
-
), token(res)
|
476
|
+
), token(res[:sql])
|
477
|
+
assert_equal [99, 1], res[:params]
|
453
478
|
|
454
479
|
res = to_sql({user: {id: 1, email: "email", address: {id: [99,999]}}}) do |s|
|
455
480
|
s.root :user
|
@@ -467,11 +492,12 @@ module PgGraphQl
|
|
467
492
|
(select to_json(x.*)
|
468
493
|
from (select addresses.id
|
469
494
|
from addresses
|
470
|
-
where addresses.id in
|
495
|
+
where addresses.id in ? and (id = users.address_id) limit 1) x) as address
|
471
496
|
from users
|
472
|
-
where users.id =
|
497
|
+
where users.id = ? limit 1) x) as value
|
473
498
|
SQL
|
474
|
-
), token(res)
|
499
|
+
), token(res[:sql])
|
500
|
+
assert_equal [[99,999], 1], res[:params]
|
475
501
|
end
|
476
502
|
|
477
503
|
def test_link_one_empty_fields
|
@@ -493,9 +519,10 @@ module PgGraphQl
|
|
493
519
|
from addresses
|
494
520
|
where (id = users.address_id) limit 1) x) as address
|
495
521
|
from users
|
496
|
-
where users.id =
|
522
|
+
where users.id = ? limit 1) x) as value
|
497
523
|
SQL
|
498
|
-
), token(res)
|
524
|
+
), token(res[:sql])
|
525
|
+
assert_equal [1], res[:params]
|
499
526
|
end
|
500
527
|
|
501
528
|
def test_link_one_missing_fk
|
@@ -528,11 +555,12 @@ module PgGraphQl
|
|
528
555
|
(select to_json(x.*)
|
529
556
|
from (select addresses.id
|
530
557
|
from addresses
|
531
|
-
where addresses.id =
|
558
|
+
where addresses.id = ? and (id = (select 100)) limit 1) x) as address
|
532
559
|
from users
|
533
|
-
where users.id =
|
560
|
+
where users.id = ? limit 1) x) as value
|
534
561
|
SQL
|
535
|
-
), token(res)
|
562
|
+
), token(res[:sql])
|
563
|
+
assert_equal ["99", 1], res[:params]
|
536
564
|
end
|
537
565
|
|
538
566
|
def test_link_one_filter
|
@@ -552,11 +580,12 @@ module PgGraphQl
|
|
552
580
|
(select to_json(x.*)
|
553
581
|
from (select addresses.id
|
554
582
|
from addresses
|
555
|
-
where addresses.id =
|
583
|
+
where addresses.id = ? and (user_id = users.id) and (id > 100) limit 1) x) as address
|
556
584
|
from users
|
557
|
-
where users.id =
|
585
|
+
where users.id = ? limit 1) x) as value
|
558
586
|
SQL
|
559
|
-
), token(res)
|
587
|
+
), token(res[:sql])
|
588
|
+
assert_equal ["99", 1], res[:params]
|
560
589
|
end
|
561
590
|
|
562
591
|
def test_link_one_order_by
|
@@ -576,11 +605,12 @@ module PgGraphQl
|
|
576
605
|
(select to_json(x.*)
|
577
606
|
from (select addresses.id
|
578
607
|
from addresses
|
579
|
-
where addresses.id =
|
608
|
+
where addresses.id = ? and (user_id = users.id) order by id desc limit 1) x) as address
|
580
609
|
from users
|
581
|
-
where users.id =
|
610
|
+
where users.id = ? limit 1) x) as value
|
582
611
|
SQL
|
583
|
-
), token(res)
|
612
|
+
), token(res[:sql])
|
613
|
+
assert_equal ["99", 1], res[:params]
|
584
614
|
end
|
585
615
|
|
586
616
|
#####################
|
@@ -613,14 +643,15 @@ module PgGraphQl
|
|
613
643
|
from addresses
|
614
644
|
where (user_id = users.id) limit 1) x) as address
|
615
645
|
from users
|
616
|
-
where users.id =
|
646
|
+
where users.id = ? limit 1) x) as value
|
617
647
|
SQL
|
618
|
-
), token(res)
|
648
|
+
), token(res[:sql])
|
649
|
+
assert_equal [1], res[:params]
|
619
650
|
end
|
620
651
|
|
621
|
-
|
622
|
-
#
|
623
|
-
|
652
|
+
#####################
|
653
|
+
# many
|
654
|
+
#####################
|
624
655
|
|
625
656
|
|
626
657
|
def test_link_many
|
@@ -640,11 +671,12 @@ module PgGraphQl
|
|
640
671
|
(select to_json(coalesce(json_agg(x.*), '[]'::json))
|
641
672
|
from (select addresses.id
|
642
673
|
from addresses
|
643
|
-
where addresses.id =
|
674
|
+
where addresses.id = ? and (user_id = users.id)) x) as address
|
644
675
|
from users
|
645
|
-
where users.id =
|
676
|
+
where users.id = ? limit 1) x) as value
|
646
677
|
SQL
|
647
|
-
), token(res)
|
678
|
+
), token(res[:sql])
|
679
|
+
assert_equal ["99", 1], res[:params]
|
648
680
|
end
|
649
681
|
|
650
682
|
def test_link_many_nested_pk
|
@@ -664,11 +696,12 @@ module PgGraphQl
|
|
664
696
|
(select to_json(coalesce(json_agg(x.*), '[]'::json))
|
665
697
|
from (select addresses.id
|
666
698
|
from addresses
|
667
|
-
where addresses.id in
|
699
|
+
where addresses.id in ? and (user_id = users.id)) x) as address
|
668
700
|
from users
|
669
|
-
where users.id =
|
701
|
+
where users.id = ? limit 1) x) as value
|
670
702
|
SQL
|
671
|
-
), token(res)
|
703
|
+
), token(res[:sql])
|
704
|
+
assert_equal [["99","999"], 1], res[:params]
|
672
705
|
end
|
673
706
|
|
674
707
|
def test_link_many_empty_fields
|
@@ -690,9 +723,10 @@ module PgGraphQl
|
|
690
723
|
from addresses
|
691
724
|
where (user_id = users.id)) x) as address
|
692
725
|
from users
|
693
|
-
where users.id =
|
726
|
+
where users.id = ? limit 1) x) as value
|
694
727
|
SQL
|
695
|
-
), token(res)
|
728
|
+
), token(res[:sql])
|
729
|
+
assert_equal [1], res[:params]
|
696
730
|
end
|
697
731
|
|
698
732
|
def test_link_many_filter
|
@@ -712,11 +746,12 @@ module PgGraphQl
|
|
712
746
|
(select to_json(coalesce(json_agg(x.*), '[]'::json))
|
713
747
|
from (select addresses.id
|
714
748
|
from addresses
|
715
|
-
where addresses.id =
|
749
|
+
where addresses.id = ? and (user_id = users.id) and (id % 2 = 0)) x) as address
|
716
750
|
from users
|
717
|
-
where users.id =
|
751
|
+
where users.id = ? limit 1) x) as value
|
718
752
|
SQL
|
719
|
-
), token(res)
|
753
|
+
), token(res[:sql])
|
754
|
+
assert_equal ["99", 1], res[:params]
|
720
755
|
end
|
721
756
|
|
722
757
|
def test_link_many_order_by
|
@@ -736,11 +771,12 @@ module PgGraphQl
|
|
736
771
|
(select to_json(coalesce(json_agg(x.*), '[]'::json))
|
737
772
|
from (select addresses.id
|
738
773
|
from addresses
|
739
|
-
where addresses.id =
|
774
|
+
where addresses.id = ? and (user_id = users.id) order by id desc) x) as address
|
740
775
|
from users
|
741
|
-
where users.id =
|
776
|
+
where users.id = ? limit 1) x) as value
|
742
777
|
SQL
|
743
|
-
), token(res)
|
778
|
+
), token(res[:sql])
|
779
|
+
assert_equal ["99", 1], res[:params]
|
744
780
|
end
|
745
781
|
|
746
782
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: pggraphql
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.12
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jan Zimmek
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-04-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: json
|