@platformatic/sql-graphql 0.0.23

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.
Files changed (54) hide show
  1. package/.nyc_output/0681b2b7-587a-40f2-8242-257bc4c72456.json +1 -0
  2. package/.nyc_output/191054d4-6a1e-4a1b-87bb-f801ed78a223.json +1 -0
  3. package/.nyc_output/22ead0f6-e5a6-4647-a2ea-db2f42498081.json +1 -0
  4. package/.nyc_output/4e847e26-05cd-4063-9277-48aff86d6822.json +1 -0
  5. package/.nyc_output/5acfd416-02d1-497b-8dbd-69c0af167c62.json +1 -0
  6. package/.nyc_output/5ec04f76-9bcb-475d-b79e-f9304cc0026c.json +1 -0
  7. package/.nyc_output/5f3bb47a-0d2d-440a-a466-8ffa9ab3efaa.json +1 -0
  8. package/.nyc_output/71c2bd84-9a72-4e86-83c6-d587ce525fe4.json +1 -0
  9. package/.nyc_output/74cc1dab-7479-48e7-80b0-c97351d8856e.json +1 -0
  10. package/.nyc_output/9f5d12ba-bc3d-461c-a0e2-2a95d2020c19.json +1 -0
  11. package/.nyc_output/ac343b71-6f76-421c-a287-46d19bb48f89.json +1 -0
  12. package/.nyc_output/c1c0eecb-63a0-4258-81b6-50e7488bd67c.json +1 -0
  13. package/.nyc_output/c201a1cd-3105-4d18-bbbb-8d7fa674d439.json +1 -0
  14. package/.nyc_output/d6da0270-e9ed-41e2-bbf3-9262d1df683c.json +1 -0
  15. package/.nyc_output/processinfo/0681b2b7-587a-40f2-8242-257bc4c72456.json +1 -0
  16. package/.nyc_output/processinfo/191054d4-6a1e-4a1b-87bb-f801ed78a223.json +1 -0
  17. package/.nyc_output/processinfo/22ead0f6-e5a6-4647-a2ea-db2f42498081.json +1 -0
  18. package/.nyc_output/processinfo/4e847e26-05cd-4063-9277-48aff86d6822.json +1 -0
  19. package/.nyc_output/processinfo/5acfd416-02d1-497b-8dbd-69c0af167c62.json +1 -0
  20. package/.nyc_output/processinfo/5ec04f76-9bcb-475d-b79e-f9304cc0026c.json +1 -0
  21. package/.nyc_output/processinfo/5f3bb47a-0d2d-440a-a466-8ffa9ab3efaa.json +1 -0
  22. package/.nyc_output/processinfo/71c2bd84-9a72-4e86-83c6-d587ce525fe4.json +1 -0
  23. package/.nyc_output/processinfo/74cc1dab-7479-48e7-80b0-c97351d8856e.json +1 -0
  24. package/.nyc_output/processinfo/9f5d12ba-bc3d-461c-a0e2-2a95d2020c19.json +1 -0
  25. package/.nyc_output/processinfo/ac343b71-6f76-421c-a287-46d19bb48f89.json +1 -0
  26. package/.nyc_output/processinfo/c1c0eecb-63a0-4258-81b6-50e7488bd67c.json +1 -0
  27. package/.nyc_output/processinfo/c201a1cd-3105-4d18-bbbb-8d7fa674d439.json +1 -0
  28. package/.nyc_output/processinfo/d6da0270-e9ed-41e2-bbf3-9262d1df683c.json +1 -0
  29. package/.nyc_output/processinfo/index.json +1 -0
  30. package/.taprc +1 -0
  31. package/LICENSE +201 -0
  32. package/NOTICE +13 -0
  33. package/README.md +13 -0
  34. package/index.d.ts +40 -0
  35. package/index.js +117 -0
  36. package/lib/entity-to-type.js +248 -0
  37. package/lib/relationship.js +67 -0
  38. package/lib/utils.js +77 -0
  39. package/package.json +44 -0
  40. package/test/datatypes.test.js +708 -0
  41. package/test/federation.test.js +312 -0
  42. package/test/helper.js +70 -0
  43. package/test/hooks.test.js +660 -0
  44. package/test/ignore.test.js +117 -0
  45. package/test/insert.test.js +181 -0
  46. package/test/inserted_updated_at.test.js +517 -0
  47. package/test/nested.test.js +862 -0
  48. package/test/no-modification-of-entity.test.js +113 -0
  49. package/test/order_by.test.js +397 -0
  50. package/test/relations.test.js +60 -0
  51. package/test/simple.test.js +708 -0
  52. package/test/sqlite.test.js +276 -0
  53. package/test/types/index.test-d.ts +33 -0
  54. package/test/where.test.js +814 -0
@@ -0,0 +1,814 @@
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
+ })