@platformatic/sql-graphql 0.46.1 → 0.47.0
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.
- package/package.json +4 -4
- package/test/array.test.js +0 -372
- package/test/camelcase.test.js +0 -312
- package/test/composite.test.js +0 -474
- package/test/count.test.js +0 -126
- package/test/created_updated_at.test.js +0 -517
- package/test/datatypes.test.js +0 -803
- package/test/enum.test.js +0 -225
- package/test/federation.test.js +0 -312
- package/test/fix-428.test.js +0 -172
- package/test/helper.js +0 -169
- package/test/hooks.test.js +0 -660
- package/test/ignore.test.js +0 -289
- package/test/insert.test.js +0 -181
- package/test/inserted_updated_at.test.js +0 -533
- package/test/nested.test.js +0 -1269
- package/test/no-modification-of-entity.test.js +0 -113
- package/test/or.test.js +0 -302
- package/test/order_by.test.js +0 -397
- package/test/relations.test.js +0 -785
- package/test/schema.test.js +0 -277
- package/test/simple.test.js +0 -959
- package/test/special-chars.test.js +0 -47
- package/test/sqlite.test.js +0 -274
- package/test/subscription.test.js +0 -336
- package/test/types/errors.test-d.ts +0 -15
- package/test/types/index.test-d.ts +0 -32
- package/test/where.test.js +0 -1102
package/test/where.test.js
DELETED
|
@@ -1,1102 +0,0 @@
|
|
|
1
|
-
'use strict'
|
|
2
|
-
|
|
3
|
-
const { test } = require('tap')
|
|
4
|
-
const sqlGraphQL = require('..')
|
|
5
|
-
const sqlMapper = require('@platformatic/sql-mapper')
|
|
6
|
-
const fastify = require('fastify')
|
|
7
|
-
const { clear, connInfo, isMysql, isSQLite } = require('./helper')
|
|
8
|
-
|
|
9
|
-
test('list', async ({ pass, teardown, same, equal }) => {
|
|
10
|
-
const app = fastify()
|
|
11
|
-
app.register(sqlMapper, {
|
|
12
|
-
...connInfo,
|
|
13
|
-
async onDatabaseLoad (db, sql) {
|
|
14
|
-
pass('onDatabaseLoad called')
|
|
15
|
-
|
|
16
|
-
await clear(db, sql)
|
|
17
|
-
|
|
18
|
-
if (isSQLite) {
|
|
19
|
-
await db.query(sql`CREATE TABLE posts (
|
|
20
|
-
id INTEGER PRIMARY KEY,
|
|
21
|
-
title VARCHAR(42),
|
|
22
|
-
long_text TEXT,
|
|
23
|
-
counter INTEGER
|
|
24
|
-
);`)
|
|
25
|
-
} else {
|
|
26
|
-
await db.query(sql`CREATE TABLE posts (
|
|
27
|
-
id SERIAL PRIMARY KEY,
|
|
28
|
-
title VARCHAR(42),
|
|
29
|
-
long_text TEXT,
|
|
30
|
-
counter INTEGER
|
|
31
|
-
);`)
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
})
|
|
35
|
-
app.register(sqlGraphQL)
|
|
36
|
-
teardown(app.close.bind(app))
|
|
37
|
-
|
|
38
|
-
await app.ready()
|
|
39
|
-
|
|
40
|
-
const posts = [{
|
|
41
|
-
title: 'Dog',
|
|
42
|
-
longText: 'Foo',
|
|
43
|
-
counter: 10
|
|
44
|
-
}, {
|
|
45
|
-
title: 'Cat',
|
|
46
|
-
longText: 'Bar',
|
|
47
|
-
counter: 20
|
|
48
|
-
}, {
|
|
49
|
-
title: 'Mouse',
|
|
50
|
-
longText: 'Baz',
|
|
51
|
-
counter: 30
|
|
52
|
-
}, {
|
|
53
|
-
title: 'Duck',
|
|
54
|
-
longText: 'A duck tale',
|
|
55
|
-
counter: 40
|
|
56
|
-
}]
|
|
57
|
-
|
|
58
|
-
{
|
|
59
|
-
const res = await app.inject({
|
|
60
|
-
method: 'POST',
|
|
61
|
-
url: '/graphql',
|
|
62
|
-
body: {
|
|
63
|
-
query: `
|
|
64
|
-
mutation batch($inputs : [PostInput]!) {
|
|
65
|
-
insertPosts(inputs: $inputs) {
|
|
66
|
-
id
|
|
67
|
-
title
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
`,
|
|
71
|
-
variables: {
|
|
72
|
-
inputs: posts
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
})
|
|
76
|
-
equal(res.statusCode, 200, 'posts status code')
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
{
|
|
80
|
-
const res = await app.inject({
|
|
81
|
-
method: 'POST',
|
|
82
|
-
url: '/graphql',
|
|
83
|
-
body: {
|
|
84
|
-
query: `
|
|
85
|
-
query {
|
|
86
|
-
posts(where: { title: { eq: "Dog" } }) {
|
|
87
|
-
id
|
|
88
|
-
title
|
|
89
|
-
longText
|
|
90
|
-
}
|
|
91
|
-
}
|
|
92
|
-
`
|
|
93
|
-
}
|
|
94
|
-
})
|
|
95
|
-
equal(res.statusCode, 200, 'posts status code')
|
|
96
|
-
same(res.json(), {
|
|
97
|
-
data: {
|
|
98
|
-
posts: [{
|
|
99
|
-
id: '1',
|
|
100
|
-
title: 'Dog',
|
|
101
|
-
longText: 'Foo'
|
|
102
|
-
}]
|
|
103
|
-
}
|
|
104
|
-
}, 'posts response')
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
{
|
|
108
|
-
const res = await app.inject({
|
|
109
|
-
method: 'POST',
|
|
110
|
-
url: '/graphql',
|
|
111
|
-
body: {
|
|
112
|
-
query: `
|
|
113
|
-
query {
|
|
114
|
-
posts(where: { title: { neq: "Dog" } }) {
|
|
115
|
-
id
|
|
116
|
-
title
|
|
117
|
-
longText
|
|
118
|
-
}
|
|
119
|
-
}
|
|
120
|
-
`
|
|
121
|
-
}
|
|
122
|
-
})
|
|
123
|
-
equal(res.statusCode, 200, 'posts status code')
|
|
124
|
-
same(res.json(), {
|
|
125
|
-
data: {
|
|
126
|
-
posts: [{
|
|
127
|
-
id: '2',
|
|
128
|
-
title: 'Cat',
|
|
129
|
-
longText: 'Bar'
|
|
130
|
-
}, {
|
|
131
|
-
id: '3',
|
|
132
|
-
title: 'Mouse',
|
|
133
|
-
longText: 'Baz'
|
|
134
|
-
}, {
|
|
135
|
-
id: '4',
|
|
136
|
-
title: 'Duck',
|
|
137
|
-
longText: 'A duck tale'
|
|
138
|
-
}]
|
|
139
|
-
}
|
|
140
|
-
}, 'posts response')
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
{
|
|
144
|
-
const res = await app.inject({
|
|
145
|
-
method: 'POST',
|
|
146
|
-
url: '/graphql',
|
|
147
|
-
body: {
|
|
148
|
-
query: `
|
|
149
|
-
query {
|
|
150
|
-
posts(where: { counter: { gt: 10 } }) {
|
|
151
|
-
id
|
|
152
|
-
title
|
|
153
|
-
longText
|
|
154
|
-
}
|
|
155
|
-
}
|
|
156
|
-
`
|
|
157
|
-
}
|
|
158
|
-
})
|
|
159
|
-
equal(res.statusCode, 200, 'posts status code')
|
|
160
|
-
same(res.json(), {
|
|
161
|
-
data: {
|
|
162
|
-
posts: [{
|
|
163
|
-
id: '2',
|
|
164
|
-
title: 'Cat',
|
|
165
|
-
longText: 'Bar'
|
|
166
|
-
}, {
|
|
167
|
-
id: '3',
|
|
168
|
-
title: 'Mouse',
|
|
169
|
-
longText: 'Baz'
|
|
170
|
-
}, {
|
|
171
|
-
id: '4',
|
|
172
|
-
title: 'Duck',
|
|
173
|
-
longText: 'A duck tale'
|
|
174
|
-
}]
|
|
175
|
-
}
|
|
176
|
-
}, 'posts response')
|
|
177
|
-
}
|
|
178
|
-
|
|
179
|
-
{
|
|
180
|
-
const res = await app.inject({
|
|
181
|
-
method: 'POST',
|
|
182
|
-
url: '/graphql',
|
|
183
|
-
body: {
|
|
184
|
-
query: `
|
|
185
|
-
query {
|
|
186
|
-
posts(where: { counter: { lt: 40 } }) {
|
|
187
|
-
id
|
|
188
|
-
title
|
|
189
|
-
longText
|
|
190
|
-
}
|
|
191
|
-
}
|
|
192
|
-
`
|
|
193
|
-
}
|
|
194
|
-
})
|
|
195
|
-
equal(res.statusCode, 200, 'posts status code')
|
|
196
|
-
same(res.json(), {
|
|
197
|
-
data: {
|
|
198
|
-
posts: [{
|
|
199
|
-
id: '1',
|
|
200
|
-
title: 'Dog',
|
|
201
|
-
longText: 'Foo'
|
|
202
|
-
}, {
|
|
203
|
-
id: '2',
|
|
204
|
-
title: 'Cat',
|
|
205
|
-
longText: 'Bar'
|
|
206
|
-
}, {
|
|
207
|
-
id: '3',
|
|
208
|
-
title: 'Mouse',
|
|
209
|
-
longText: 'Baz'
|
|
210
|
-
}]
|
|
211
|
-
}
|
|
212
|
-
}, 'posts response')
|
|
213
|
-
}
|
|
214
|
-
|
|
215
|
-
{
|
|
216
|
-
const res = await app.inject({
|
|
217
|
-
method: 'POST',
|
|
218
|
-
url: '/graphql',
|
|
219
|
-
body: {
|
|
220
|
-
query: `
|
|
221
|
-
query {
|
|
222
|
-
posts(where: { counter: { lte: 30 } }) {
|
|
223
|
-
id
|
|
224
|
-
title
|
|
225
|
-
longText
|
|
226
|
-
}
|
|
227
|
-
}
|
|
228
|
-
`
|
|
229
|
-
}
|
|
230
|
-
})
|
|
231
|
-
equal(res.statusCode, 200, 'posts status code')
|
|
232
|
-
same(res.json(), {
|
|
233
|
-
data: {
|
|
234
|
-
posts: [{
|
|
235
|
-
id: '1',
|
|
236
|
-
title: 'Dog',
|
|
237
|
-
longText: 'Foo'
|
|
238
|
-
}, {
|
|
239
|
-
id: '2',
|
|
240
|
-
title: 'Cat',
|
|
241
|
-
longText: 'Bar'
|
|
242
|
-
}, {
|
|
243
|
-
id: '3',
|
|
244
|
-
title: 'Mouse',
|
|
245
|
-
longText: 'Baz'
|
|
246
|
-
}]
|
|
247
|
-
}
|
|
248
|
-
}, 'posts response')
|
|
249
|
-
}
|
|
250
|
-
|
|
251
|
-
{
|
|
252
|
-
const res = await app.inject({
|
|
253
|
-
method: 'POST',
|
|
254
|
-
url: '/graphql',
|
|
255
|
-
body: {
|
|
256
|
-
query: `
|
|
257
|
-
query {
|
|
258
|
-
posts(where: { counter: { gte: 20 } }) {
|
|
259
|
-
id
|
|
260
|
-
title
|
|
261
|
-
longText
|
|
262
|
-
}
|
|
263
|
-
}
|
|
264
|
-
`
|
|
265
|
-
}
|
|
266
|
-
})
|
|
267
|
-
equal(res.statusCode, 200, 'posts status code')
|
|
268
|
-
same(res.json(), {
|
|
269
|
-
data: {
|
|
270
|
-
posts: [{
|
|
271
|
-
id: '2',
|
|
272
|
-
title: 'Cat',
|
|
273
|
-
longText: 'Bar'
|
|
274
|
-
}, {
|
|
275
|
-
id: '3',
|
|
276
|
-
title: 'Mouse',
|
|
277
|
-
longText: 'Baz'
|
|
278
|
-
}, {
|
|
279
|
-
id: '4',
|
|
280
|
-
title: 'Duck',
|
|
281
|
-
longText: 'A duck tale'
|
|
282
|
-
}]
|
|
283
|
-
}
|
|
284
|
-
}, 'posts response')
|
|
285
|
-
}
|
|
286
|
-
|
|
287
|
-
{
|
|
288
|
-
const res = await app.inject({
|
|
289
|
-
method: 'POST',
|
|
290
|
-
url: '/graphql',
|
|
291
|
-
body: {
|
|
292
|
-
query: `
|
|
293
|
-
query {
|
|
294
|
-
posts(where: { counter: { in: [20, 30] } }) {
|
|
295
|
-
id
|
|
296
|
-
title
|
|
297
|
-
longText
|
|
298
|
-
}
|
|
299
|
-
}
|
|
300
|
-
`
|
|
301
|
-
}
|
|
302
|
-
})
|
|
303
|
-
equal(res.statusCode, 200, 'posts status code')
|
|
304
|
-
same(res.json(), {
|
|
305
|
-
data: {
|
|
306
|
-
posts: [{
|
|
307
|
-
id: '2',
|
|
308
|
-
title: 'Cat',
|
|
309
|
-
longText: 'Bar'
|
|
310
|
-
}, {
|
|
311
|
-
id: '3',
|
|
312
|
-
title: 'Mouse',
|
|
313
|
-
longText: 'Baz'
|
|
314
|
-
}]
|
|
315
|
-
}
|
|
316
|
-
}, 'posts response')
|
|
317
|
-
}
|
|
318
|
-
|
|
319
|
-
{
|
|
320
|
-
const res = await app.inject({
|
|
321
|
-
method: 'POST',
|
|
322
|
-
url: '/graphql',
|
|
323
|
-
body: {
|
|
324
|
-
query: `
|
|
325
|
-
query {
|
|
326
|
-
posts(where: { counter: { nin: [10, 40] } }) {
|
|
327
|
-
id
|
|
328
|
-
title
|
|
329
|
-
longText
|
|
330
|
-
}
|
|
331
|
-
}
|
|
332
|
-
`
|
|
333
|
-
}
|
|
334
|
-
})
|
|
335
|
-
equal(res.statusCode, 200, 'posts status code')
|
|
336
|
-
same(res.json(), {
|
|
337
|
-
data: {
|
|
338
|
-
posts: [{
|
|
339
|
-
id: '2',
|
|
340
|
-
title: 'Cat',
|
|
341
|
-
longText: 'Bar'
|
|
342
|
-
}, {
|
|
343
|
-
id: '3',
|
|
344
|
-
title: 'Mouse',
|
|
345
|
-
longText: 'Baz'
|
|
346
|
-
}]
|
|
347
|
-
}
|
|
348
|
-
}, 'posts response')
|
|
349
|
-
}
|
|
350
|
-
|
|
351
|
-
{
|
|
352
|
-
const res = await app.inject({
|
|
353
|
-
method: 'POST',
|
|
354
|
-
url: '/graphql',
|
|
355
|
-
body: {
|
|
356
|
-
query: `
|
|
357
|
-
query {
|
|
358
|
-
posts(where: { counter: { gt: 10, lt: 40 } }) {
|
|
359
|
-
id
|
|
360
|
-
title
|
|
361
|
-
longText
|
|
362
|
-
}
|
|
363
|
-
}
|
|
364
|
-
`
|
|
365
|
-
}
|
|
366
|
-
})
|
|
367
|
-
equal(res.statusCode, 200, 'posts status code')
|
|
368
|
-
same(res.json(), {
|
|
369
|
-
data: {
|
|
370
|
-
posts: [{
|
|
371
|
-
id: '2',
|
|
372
|
-
title: 'Cat',
|
|
373
|
-
longText: 'Bar'
|
|
374
|
-
}, {
|
|
375
|
-
id: '3',
|
|
376
|
-
title: 'Mouse',
|
|
377
|
-
longText: 'Baz'
|
|
378
|
-
}]
|
|
379
|
-
}
|
|
380
|
-
}, 'posts response')
|
|
381
|
-
}
|
|
382
|
-
})
|
|
383
|
-
|
|
384
|
-
test('nested where', async ({ pass, teardown, same, equal }) => {
|
|
385
|
-
const app = fastify()
|
|
386
|
-
app.register(sqlMapper, {
|
|
387
|
-
...connInfo,
|
|
388
|
-
async onDatabaseLoad (db, sql) {
|
|
389
|
-
pass('onDatabaseLoad called')
|
|
390
|
-
|
|
391
|
-
await clear(db, sql)
|
|
392
|
-
|
|
393
|
-
if (isMysql) {
|
|
394
|
-
await db.query(sql`
|
|
395
|
-
CREATE TABLE owners (
|
|
396
|
-
id SERIAL PRIMARY KEY,
|
|
397
|
-
name VARCHAR(255)
|
|
398
|
-
);
|
|
399
|
-
CREATE TABLE posts (
|
|
400
|
-
id SERIAL PRIMARY KEY,
|
|
401
|
-
title VARCHAR(42),
|
|
402
|
-
long_text TEXT,
|
|
403
|
-
counter INTEGER,
|
|
404
|
-
owner_id BIGINT UNSIGNED,
|
|
405
|
-
FOREIGN KEY (owner_id) REFERENCES owners(id) ON DELETE CASCADE
|
|
406
|
-
);
|
|
407
|
-
`)
|
|
408
|
-
} else if (isSQLite) {
|
|
409
|
-
await db.query(sql`
|
|
410
|
-
CREATE TABLE owners (
|
|
411
|
-
id INTEGER PRIMARY KEY,
|
|
412
|
-
name VARCHAR(255)
|
|
413
|
-
);
|
|
414
|
-
`)
|
|
415
|
-
|
|
416
|
-
await db.query(sql`
|
|
417
|
-
CREATE TABLE posts (
|
|
418
|
-
id INTEGER PRIMARY KEY,
|
|
419
|
-
title VARCHAR(42),
|
|
420
|
-
long_text TEXT,
|
|
421
|
-
counter INTEGER,
|
|
422
|
-
owner_id BIGINT UNSIGNED,
|
|
423
|
-
FOREIGN KEY (owner_id) REFERENCES owners(id) ON DELETE CASCADE
|
|
424
|
-
);
|
|
425
|
-
`)
|
|
426
|
-
} else {
|
|
427
|
-
await db.query(sql`
|
|
428
|
-
CREATE TABLE owners (
|
|
429
|
-
id SERIAL PRIMARY KEY,
|
|
430
|
-
name VARCHAR(255)
|
|
431
|
-
);
|
|
432
|
-
CREATE TABLE posts (
|
|
433
|
-
id SERIAL PRIMARY KEY,
|
|
434
|
-
title VARCHAR(42),
|
|
435
|
-
long_text TEXT,
|
|
436
|
-
counter INTEGER,
|
|
437
|
-
owner_id INTEGER REFERENCES owners(id)
|
|
438
|
-
);`)
|
|
439
|
-
}
|
|
440
|
-
}
|
|
441
|
-
})
|
|
442
|
-
app.register(sqlGraphQL)
|
|
443
|
-
|
|
444
|
-
teardown(app.close.bind(app))
|
|
445
|
-
|
|
446
|
-
await app.ready()
|
|
447
|
-
|
|
448
|
-
const owners = [{
|
|
449
|
-
name: 'Matteo'
|
|
450
|
-
}, {
|
|
451
|
-
name: 'Luca'
|
|
452
|
-
}]
|
|
453
|
-
|
|
454
|
-
const posts = [{
|
|
455
|
-
title: 'Dog',
|
|
456
|
-
longText: 'Foo',
|
|
457
|
-
counter: 10
|
|
458
|
-
}, {
|
|
459
|
-
title: 'Cat',
|
|
460
|
-
longText: 'Bar',
|
|
461
|
-
counter: 20
|
|
462
|
-
}, {
|
|
463
|
-
title: 'Mouse',
|
|
464
|
-
longText: 'Baz',
|
|
465
|
-
counter: 30
|
|
466
|
-
}, {
|
|
467
|
-
title: 'Duck',
|
|
468
|
-
longText: 'A duck tale',
|
|
469
|
-
counter: 40
|
|
470
|
-
}]
|
|
471
|
-
|
|
472
|
-
{
|
|
473
|
-
const res = await app.inject({
|
|
474
|
-
method: 'POST',
|
|
475
|
-
url: '/graphql',
|
|
476
|
-
body: {
|
|
477
|
-
query: `
|
|
478
|
-
mutation batch($inputs : [OwnerInput]!) {
|
|
479
|
-
insertOwners(inputs: $inputs) {
|
|
480
|
-
id
|
|
481
|
-
name
|
|
482
|
-
}
|
|
483
|
-
}
|
|
484
|
-
`,
|
|
485
|
-
variables: {
|
|
486
|
-
inputs: owners
|
|
487
|
-
}
|
|
488
|
-
}
|
|
489
|
-
})
|
|
490
|
-
const toAssign = [...posts]
|
|
491
|
-
for (const owner of res.json().data.insertOwners) {
|
|
492
|
-
toAssign.shift().ownerId = owner.id
|
|
493
|
-
toAssign.shift().ownerId = owner.id
|
|
494
|
-
}
|
|
495
|
-
await app.inject({
|
|
496
|
-
method: 'POST',
|
|
497
|
-
url: '/graphql',
|
|
498
|
-
body: {
|
|
499
|
-
query: `
|
|
500
|
-
mutation batch($inputs : [PostInput]!) {
|
|
501
|
-
insertPosts(inputs: $inputs) {
|
|
502
|
-
id
|
|
503
|
-
title
|
|
504
|
-
}
|
|
505
|
-
}
|
|
506
|
-
`,
|
|
507
|
-
variables: {
|
|
508
|
-
inputs: posts
|
|
509
|
-
}
|
|
510
|
-
}
|
|
511
|
-
})
|
|
512
|
-
}
|
|
513
|
-
|
|
514
|
-
{
|
|
515
|
-
const res = await app.inject({
|
|
516
|
-
method: 'POST',
|
|
517
|
-
url: '/graphql',
|
|
518
|
-
body: {
|
|
519
|
-
query: `
|
|
520
|
-
query {
|
|
521
|
-
owners {
|
|
522
|
-
id
|
|
523
|
-
name
|
|
524
|
-
posts(where: { counter: { gte: 20 } }) {
|
|
525
|
-
id
|
|
526
|
-
title
|
|
527
|
-
longText
|
|
528
|
-
}
|
|
529
|
-
}
|
|
530
|
-
}
|
|
531
|
-
`
|
|
532
|
-
}
|
|
533
|
-
})
|
|
534
|
-
equal(res.statusCode, 200, 'owners status code')
|
|
535
|
-
same(res.json(), {
|
|
536
|
-
data: {
|
|
537
|
-
owners: [{
|
|
538
|
-
id: '1',
|
|
539
|
-
name: 'Matteo',
|
|
540
|
-
posts: [{
|
|
541
|
-
id: '2',
|
|
542
|
-
title: 'Cat',
|
|
543
|
-
longText: 'Bar'
|
|
544
|
-
}]
|
|
545
|
-
}, {
|
|
546
|
-
id: '2',
|
|
547
|
-
name: 'Luca',
|
|
548
|
-
posts: [{
|
|
549
|
-
id: '3',
|
|
550
|
-
title: 'Mouse',
|
|
551
|
-
longText: 'Baz'
|
|
552
|
-
}, {
|
|
553
|
-
id: '4',
|
|
554
|
-
title: 'Duck',
|
|
555
|
-
longText: 'A duck tale'
|
|
556
|
-
}]
|
|
557
|
-
}]
|
|
558
|
-
}
|
|
559
|
-
}, 'owners response')
|
|
560
|
-
}
|
|
561
|
-
})
|
|
562
|
-
|
|
563
|
-
test('delete', async ({ pass, teardown, same, equal }) => {
|
|
564
|
-
const app = fastify()
|
|
565
|
-
app.register(sqlMapper, {
|
|
566
|
-
...connInfo,
|
|
567
|
-
async onDatabaseLoad (db, sql) {
|
|
568
|
-
pass('onDatabaseLoad called')
|
|
569
|
-
|
|
570
|
-
await clear(db, sql)
|
|
571
|
-
|
|
572
|
-
if (isSQLite) {
|
|
573
|
-
await db.query(sql`CREATE TABLE posts (
|
|
574
|
-
id INTEGER PRIMARY KEY,
|
|
575
|
-
title VARCHAR(42),
|
|
576
|
-
long_text TEXT,
|
|
577
|
-
counter INTEGER
|
|
578
|
-
);`)
|
|
579
|
-
} else {
|
|
580
|
-
await db.query(sql`CREATE TABLE posts (
|
|
581
|
-
id SERIAL PRIMARY KEY,
|
|
582
|
-
title VARCHAR(42),
|
|
583
|
-
long_text TEXT,
|
|
584
|
-
counter INTEGER
|
|
585
|
-
);`)
|
|
586
|
-
}
|
|
587
|
-
}
|
|
588
|
-
})
|
|
589
|
-
app.register(sqlGraphQL)
|
|
590
|
-
teardown(app.close.bind(app))
|
|
591
|
-
|
|
592
|
-
await app.ready()
|
|
593
|
-
|
|
594
|
-
const posts = [{
|
|
595
|
-
title: 'Dog',
|
|
596
|
-
longText: 'Foo',
|
|
597
|
-
counter: 10
|
|
598
|
-
}, {
|
|
599
|
-
title: 'Cat',
|
|
600
|
-
longText: 'Bar',
|
|
601
|
-
counter: 20
|
|
602
|
-
}, {
|
|
603
|
-
title: 'Mouse',
|
|
604
|
-
longText: 'Baz',
|
|
605
|
-
counter: 30
|
|
606
|
-
}, {
|
|
607
|
-
title: 'Duck',
|
|
608
|
-
longText: 'A duck tale',
|
|
609
|
-
counter: 40
|
|
610
|
-
}]
|
|
611
|
-
|
|
612
|
-
await app.inject({
|
|
613
|
-
method: 'POST',
|
|
614
|
-
url: '/graphql',
|
|
615
|
-
body: {
|
|
616
|
-
query: `
|
|
617
|
-
mutation batch($inputs : [PostInput]!) {
|
|
618
|
-
insertPosts(inputs: $inputs) {
|
|
619
|
-
id
|
|
620
|
-
title
|
|
621
|
-
}
|
|
622
|
-
}
|
|
623
|
-
`,
|
|
624
|
-
variables: {
|
|
625
|
-
inputs: posts
|
|
626
|
-
}
|
|
627
|
-
}
|
|
628
|
-
})
|
|
629
|
-
|
|
630
|
-
{
|
|
631
|
-
const res = await app.inject({
|
|
632
|
-
method: 'POST',
|
|
633
|
-
url: '/graphql',
|
|
634
|
-
body: {
|
|
635
|
-
query: `
|
|
636
|
-
mutation {
|
|
637
|
-
deletePosts(where: { title: { eq: "Dog" } }) {
|
|
638
|
-
id
|
|
639
|
-
title
|
|
640
|
-
longText
|
|
641
|
-
}
|
|
642
|
-
}
|
|
643
|
-
`
|
|
644
|
-
}
|
|
645
|
-
})
|
|
646
|
-
equal(res.statusCode, 200, 'deletePosts status code')
|
|
647
|
-
same(res.json(), {
|
|
648
|
-
data: {
|
|
649
|
-
deletePosts: [{
|
|
650
|
-
id: 1,
|
|
651
|
-
title: 'Dog',
|
|
652
|
-
longText: 'Foo'
|
|
653
|
-
}]
|
|
654
|
-
}
|
|
655
|
-
}, 'deletePosts response')
|
|
656
|
-
}
|
|
657
|
-
|
|
658
|
-
{
|
|
659
|
-
const res = await app.inject({
|
|
660
|
-
method: 'POST',
|
|
661
|
-
url: '/graphql',
|
|
662
|
-
body: {
|
|
663
|
-
query: `
|
|
664
|
-
query {
|
|
665
|
-
posts(where: { title: { eq: "Dog" } }) {
|
|
666
|
-
id
|
|
667
|
-
title
|
|
668
|
-
longText
|
|
669
|
-
}
|
|
670
|
-
}
|
|
671
|
-
`
|
|
672
|
-
}
|
|
673
|
-
})
|
|
674
|
-
equal(res.statusCode, 200, 'posts status code')
|
|
675
|
-
same(res.json(), {
|
|
676
|
-
data: {
|
|
677
|
-
posts: []
|
|
678
|
-
}
|
|
679
|
-
}, 'posts response')
|
|
680
|
-
}
|
|
681
|
-
})
|
|
682
|
-
|
|
683
|
-
test('delete all', async ({ pass, teardown, same, equal }) => {
|
|
684
|
-
const app = fastify()
|
|
685
|
-
app.register(sqlMapper, {
|
|
686
|
-
...connInfo,
|
|
687
|
-
async onDatabaseLoad (db, sql) {
|
|
688
|
-
pass('onDatabaseLoad called')
|
|
689
|
-
|
|
690
|
-
await clear(db, sql)
|
|
691
|
-
|
|
692
|
-
if (isSQLite) {
|
|
693
|
-
await db.query(sql`CREATE TABLE posts (
|
|
694
|
-
id INTEGER PRIMARY KEY,
|
|
695
|
-
title VARCHAR(42),
|
|
696
|
-
long_text TEXT,
|
|
697
|
-
counter INTEGER
|
|
698
|
-
);`)
|
|
699
|
-
} else {
|
|
700
|
-
await db.query(sql`CREATE TABLE posts (
|
|
701
|
-
id SERIAL PRIMARY KEY,
|
|
702
|
-
title VARCHAR(42),
|
|
703
|
-
long_text TEXT,
|
|
704
|
-
counter INTEGER
|
|
705
|
-
);`)
|
|
706
|
-
}
|
|
707
|
-
}
|
|
708
|
-
})
|
|
709
|
-
app.register(sqlGraphQL)
|
|
710
|
-
teardown(app.close.bind(app))
|
|
711
|
-
|
|
712
|
-
await app.ready()
|
|
713
|
-
|
|
714
|
-
const posts = [{
|
|
715
|
-
title: 'Dog',
|
|
716
|
-
longText: 'Foo',
|
|
717
|
-
counter: 10
|
|
718
|
-
}, {
|
|
719
|
-
title: 'Cat',
|
|
720
|
-
longText: 'Bar',
|
|
721
|
-
counter: 20
|
|
722
|
-
}, {
|
|
723
|
-
title: 'Mouse',
|
|
724
|
-
longText: 'Baz',
|
|
725
|
-
counter: 30
|
|
726
|
-
}, {
|
|
727
|
-
title: 'Duck',
|
|
728
|
-
longText: 'A duck tale',
|
|
729
|
-
counter: 40
|
|
730
|
-
}]
|
|
731
|
-
|
|
732
|
-
await app.inject({
|
|
733
|
-
method: 'POST',
|
|
734
|
-
url: '/graphql',
|
|
735
|
-
body: {
|
|
736
|
-
query: `
|
|
737
|
-
mutation batch($inputs : [PostInput]!) {
|
|
738
|
-
insertPosts(inputs: $inputs) {
|
|
739
|
-
id
|
|
740
|
-
title
|
|
741
|
-
}
|
|
742
|
-
}
|
|
743
|
-
`,
|
|
744
|
-
variables: {
|
|
745
|
-
inputs: posts
|
|
746
|
-
}
|
|
747
|
-
}
|
|
748
|
-
})
|
|
749
|
-
|
|
750
|
-
{
|
|
751
|
-
const res = await app.inject({
|
|
752
|
-
method: 'POST',
|
|
753
|
-
url: '/graphql',
|
|
754
|
-
body: {
|
|
755
|
-
query: `
|
|
756
|
-
mutation {
|
|
757
|
-
deletePosts {
|
|
758
|
-
id
|
|
759
|
-
title
|
|
760
|
-
longText
|
|
761
|
-
}
|
|
762
|
-
}
|
|
763
|
-
`
|
|
764
|
-
}
|
|
765
|
-
})
|
|
766
|
-
equal(res.statusCode, 200, 'deletePosts status code')
|
|
767
|
-
same(res.json(), {
|
|
768
|
-
data: {
|
|
769
|
-
deletePosts: [{
|
|
770
|
-
id: 1,
|
|
771
|
-
title: 'Dog',
|
|
772
|
-
longText: 'Foo'
|
|
773
|
-
}, {
|
|
774
|
-
id: 2,
|
|
775
|
-
title: 'Cat',
|
|
776
|
-
longText: 'Bar'
|
|
777
|
-
}, {
|
|
778
|
-
id: 3,
|
|
779
|
-
title: 'Mouse',
|
|
780
|
-
longText: 'Baz'
|
|
781
|
-
}, {
|
|
782
|
-
id: 4,
|
|
783
|
-
title: 'Duck',
|
|
784
|
-
longText: 'A duck tale'
|
|
785
|
-
|
|
786
|
-
}]
|
|
787
|
-
}
|
|
788
|
-
}, 'deletePosts response')
|
|
789
|
-
}
|
|
790
|
-
|
|
791
|
-
{
|
|
792
|
-
const res = await app.inject({
|
|
793
|
-
method: 'POST',
|
|
794
|
-
url: '/graphql',
|
|
795
|
-
body: {
|
|
796
|
-
query: `
|
|
797
|
-
query {
|
|
798
|
-
posts {
|
|
799
|
-
id
|
|
800
|
-
title
|
|
801
|
-
longText
|
|
802
|
-
}
|
|
803
|
-
}
|
|
804
|
-
`
|
|
805
|
-
}
|
|
806
|
-
})
|
|
807
|
-
equal(res.statusCode, 200, 'posts status code')
|
|
808
|
-
same(res.json(), {
|
|
809
|
-
data: {
|
|
810
|
-
posts: []
|
|
811
|
-
}
|
|
812
|
-
}, 'posts response')
|
|
813
|
-
}
|
|
814
|
-
})
|
|
815
|
-
|
|
816
|
-
test('like', async ({ pass, teardown, same, equal }) => {
|
|
817
|
-
const app = fastify()
|
|
818
|
-
app.register(sqlMapper, {
|
|
819
|
-
...connInfo,
|
|
820
|
-
async onDatabaseLoad (db, sql) {
|
|
821
|
-
pass('onDatabaseLoad called')
|
|
822
|
-
|
|
823
|
-
await clear(db, sql)
|
|
824
|
-
|
|
825
|
-
if (isSQLite) {
|
|
826
|
-
await db.query(sql`CREATE TABLE posts (
|
|
827
|
-
id INTEGER PRIMARY KEY,
|
|
828
|
-
title VARCHAR(42),
|
|
829
|
-
long_text TEXT,
|
|
830
|
-
counter INTEGER
|
|
831
|
-
);`)
|
|
832
|
-
} else {
|
|
833
|
-
await db.query(sql`CREATE TABLE posts (
|
|
834
|
-
id SERIAL PRIMARY KEY,
|
|
835
|
-
title VARCHAR(42),
|
|
836
|
-
long_text TEXT,
|
|
837
|
-
counter INTEGER
|
|
838
|
-
);`)
|
|
839
|
-
}
|
|
840
|
-
}
|
|
841
|
-
})
|
|
842
|
-
app.register(sqlGraphQL)
|
|
843
|
-
teardown(app.close.bind(app))
|
|
844
|
-
|
|
845
|
-
await app.ready()
|
|
846
|
-
|
|
847
|
-
const posts = [{
|
|
848
|
-
title: 'Dog',
|
|
849
|
-
longText: 'The dog barks',
|
|
850
|
-
counter: 10
|
|
851
|
-
}, {
|
|
852
|
-
title: 'Cat',
|
|
853
|
-
longText: 'The cat meows',
|
|
854
|
-
counter: 20
|
|
855
|
-
}, {
|
|
856
|
-
title: 'Mouse',
|
|
857
|
-
longText: 'The mouse likes cheese',
|
|
858
|
-
counter: 30
|
|
859
|
-
}, {
|
|
860
|
-
title: 'Duck',
|
|
861
|
-
longText: 'A duck tale',
|
|
862
|
-
counter: 40
|
|
863
|
-
}]
|
|
864
|
-
|
|
865
|
-
await app.inject({
|
|
866
|
-
method: 'POST',
|
|
867
|
-
url: '/graphql',
|
|
868
|
-
body: {
|
|
869
|
-
query: `
|
|
870
|
-
mutation batch($inputs : [PostInput]!) {
|
|
871
|
-
insertPosts(inputs: $inputs) {
|
|
872
|
-
id
|
|
873
|
-
title
|
|
874
|
-
}
|
|
875
|
-
}
|
|
876
|
-
`,
|
|
877
|
-
variables: {
|
|
878
|
-
inputs: posts
|
|
879
|
-
}
|
|
880
|
-
}
|
|
881
|
-
})
|
|
882
|
-
|
|
883
|
-
{
|
|
884
|
-
const res = await app.inject({
|
|
885
|
-
method: 'POST',
|
|
886
|
-
url: '/graphql',
|
|
887
|
-
body: {
|
|
888
|
-
query: `
|
|
889
|
-
query {
|
|
890
|
-
posts {
|
|
891
|
-
id
|
|
892
|
-
title
|
|
893
|
-
longText
|
|
894
|
-
counter
|
|
895
|
-
}
|
|
896
|
-
}
|
|
897
|
-
`
|
|
898
|
-
}
|
|
899
|
-
})
|
|
900
|
-
equal(res.statusCode, 200, 'posts status code')
|
|
901
|
-
same(res.json(), {
|
|
902
|
-
data: {
|
|
903
|
-
posts: [{
|
|
904
|
-
id: '1',
|
|
905
|
-
title: 'Dog',
|
|
906
|
-
longText: 'The dog barks',
|
|
907
|
-
counter: 10
|
|
908
|
-
}, {
|
|
909
|
-
id: '2',
|
|
910
|
-
title: 'Cat',
|
|
911
|
-
longText: 'The cat meows',
|
|
912
|
-
counter: 20
|
|
913
|
-
}, {
|
|
914
|
-
id: '3',
|
|
915
|
-
title: 'Mouse',
|
|
916
|
-
longText: 'The mouse likes cheese',
|
|
917
|
-
counter: 30
|
|
918
|
-
}, {
|
|
919
|
-
id: '4',
|
|
920
|
-
title: 'Duck',
|
|
921
|
-
longText: 'A duck tale',
|
|
922
|
-
counter: 40
|
|
923
|
-
}]
|
|
924
|
-
}
|
|
925
|
-
}, 'posts response')
|
|
926
|
-
}
|
|
927
|
-
|
|
928
|
-
{
|
|
929
|
-
const res = await app.inject({
|
|
930
|
-
method: 'POST',
|
|
931
|
-
url: '/graphql',
|
|
932
|
-
body: {
|
|
933
|
-
query: `
|
|
934
|
-
query {
|
|
935
|
-
posts(where: { longText: { like: "The%" } }) {
|
|
936
|
-
id
|
|
937
|
-
title
|
|
938
|
-
longText
|
|
939
|
-
counter
|
|
940
|
-
}
|
|
941
|
-
}
|
|
942
|
-
`
|
|
943
|
-
}
|
|
944
|
-
})
|
|
945
|
-
equal(res.statusCode, 200, 'where: { longText: { like: "The%" } } status code')
|
|
946
|
-
same(res.json(), {
|
|
947
|
-
data: {
|
|
948
|
-
posts: [{
|
|
949
|
-
id: '1',
|
|
950
|
-
title: 'Dog',
|
|
951
|
-
longText: 'The dog barks',
|
|
952
|
-
counter: 10
|
|
953
|
-
}, {
|
|
954
|
-
id: '2',
|
|
955
|
-
title: 'Cat',
|
|
956
|
-
longText: 'The cat meows',
|
|
957
|
-
counter: 20
|
|
958
|
-
}, {
|
|
959
|
-
id: '3',
|
|
960
|
-
title: 'Mouse',
|
|
961
|
-
longText: 'The mouse likes cheese',
|
|
962
|
-
counter: 30
|
|
963
|
-
}]
|
|
964
|
-
}
|
|
965
|
-
}, 'where: { longText: { like: "The%" } } response')
|
|
966
|
-
}
|
|
967
|
-
|
|
968
|
-
{
|
|
969
|
-
const res = await app.inject({
|
|
970
|
-
method: 'POST',
|
|
971
|
-
url: '/graphql',
|
|
972
|
-
body: {
|
|
973
|
-
query: `
|
|
974
|
-
query {
|
|
975
|
-
posts(where: { longText: { like: "%s" } }) {
|
|
976
|
-
id
|
|
977
|
-
title
|
|
978
|
-
longText
|
|
979
|
-
counter
|
|
980
|
-
}
|
|
981
|
-
}
|
|
982
|
-
`
|
|
983
|
-
}
|
|
984
|
-
})
|
|
985
|
-
equal(res.statusCode, 200, 'where: { longText: { like: "%s" } } status code')
|
|
986
|
-
same(res.json(), {
|
|
987
|
-
data: {
|
|
988
|
-
posts: [{
|
|
989
|
-
id: '1',
|
|
990
|
-
title: 'Dog',
|
|
991
|
-
longText: 'The dog barks',
|
|
992
|
-
counter: 10
|
|
993
|
-
}, {
|
|
994
|
-
id: '2',
|
|
995
|
-
title: 'Cat',
|
|
996
|
-
longText: 'The cat meows',
|
|
997
|
-
counter: 20
|
|
998
|
-
}]
|
|
999
|
-
}
|
|
1000
|
-
}, 'where: { longText: { like: "%s" } } response')
|
|
1001
|
-
}
|
|
1002
|
-
|
|
1003
|
-
{
|
|
1004
|
-
const res = await app.inject({
|
|
1005
|
-
method: 'POST',
|
|
1006
|
-
url: '/graphql',
|
|
1007
|
-
body: {
|
|
1008
|
-
query: `
|
|
1009
|
-
query {
|
|
1010
|
-
posts(where: { longText: { like: "%o%" } }) {
|
|
1011
|
-
id
|
|
1012
|
-
title
|
|
1013
|
-
longText
|
|
1014
|
-
counter
|
|
1015
|
-
}
|
|
1016
|
-
}
|
|
1017
|
-
`
|
|
1018
|
-
}
|
|
1019
|
-
})
|
|
1020
|
-
equal(res.statusCode, 200, 'where: { longText: { like: "%o%" } } status code')
|
|
1021
|
-
same(res.json(), {
|
|
1022
|
-
data: {
|
|
1023
|
-
posts: [{
|
|
1024
|
-
id: '1',
|
|
1025
|
-
title: 'Dog',
|
|
1026
|
-
longText: 'The dog barks',
|
|
1027
|
-
counter: 10
|
|
1028
|
-
}, {
|
|
1029
|
-
id: '2',
|
|
1030
|
-
title: 'Cat',
|
|
1031
|
-
longText: 'The cat meows',
|
|
1032
|
-
counter: 20
|
|
1033
|
-
}, {
|
|
1034
|
-
id: '3',
|
|
1035
|
-
title: 'Mouse',
|
|
1036
|
-
longText: 'The mouse likes cheese',
|
|
1037
|
-
counter: 30
|
|
1038
|
-
}]
|
|
1039
|
-
}
|
|
1040
|
-
}, 'where: { longText: { like: "%o%" } } response')
|
|
1041
|
-
}
|
|
1042
|
-
|
|
1043
|
-
if (!isSQLite) {
|
|
1044
|
-
const res = await app.inject({
|
|
1045
|
-
method: 'POST',
|
|
1046
|
-
url: '/graphql',
|
|
1047
|
-
body: {
|
|
1048
|
-
query: `
|
|
1049
|
-
query {
|
|
1050
|
-
posts(where: { counter: { like: 10 } }) {
|
|
1051
|
-
id
|
|
1052
|
-
title
|
|
1053
|
-
longText
|
|
1054
|
-
counter
|
|
1055
|
-
}
|
|
1056
|
-
}
|
|
1057
|
-
`
|
|
1058
|
-
}
|
|
1059
|
-
})
|
|
1060
|
-
equal(res.statusCode, 200, 'where: { counter: { like: 10 } } status code')
|
|
1061
|
-
same(res.json(), {
|
|
1062
|
-
data: {
|
|
1063
|
-
posts: [{
|
|
1064
|
-
id: '1',
|
|
1065
|
-
title: 'Dog',
|
|
1066
|
-
longText: 'The dog barks',
|
|
1067
|
-
counter: 10
|
|
1068
|
-
}]
|
|
1069
|
-
}
|
|
1070
|
-
}, 'where: { counter: { like: 10 } } response')
|
|
1071
|
-
}
|
|
1072
|
-
|
|
1073
|
-
if (!isSQLite) {
|
|
1074
|
-
const res = await app.inject({
|
|
1075
|
-
method: 'POST',
|
|
1076
|
-
url: '/graphql',
|
|
1077
|
-
body: {
|
|
1078
|
-
query: `
|
|
1079
|
-
query {
|
|
1080
|
-
posts(where: { counter: { like: 40 } }) {
|
|
1081
|
-
id
|
|
1082
|
-
title
|
|
1083
|
-
longText
|
|
1084
|
-
counter
|
|
1085
|
-
}
|
|
1086
|
-
}
|
|
1087
|
-
`
|
|
1088
|
-
}
|
|
1089
|
-
})
|
|
1090
|
-
equal(res.statusCode, 200, 'where: { counter: { like: 40 } } status code')
|
|
1091
|
-
same(res.json(), {
|
|
1092
|
-
data: {
|
|
1093
|
-
posts: [{
|
|
1094
|
-
id: '4',
|
|
1095
|
-
title: 'Duck',
|
|
1096
|
-
longText: 'A duck tale',
|
|
1097
|
-
counter: 40
|
|
1098
|
-
}]
|
|
1099
|
-
}
|
|
1100
|
-
}, 'where: { counter: { like: 40 } } response')
|
|
1101
|
-
}
|
|
1102
|
-
})
|