drizzle-graphql-plus 0.8.6

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.
@@ -0,0 +1,1956 @@
1
+ import { buildSchema, type GeneratedEntities } from '@/index';
2
+ import { type Client, createClient } from '@libsql/client';
3
+ import { sql } from 'drizzle-orm';
4
+ import { drizzle } from 'drizzle-orm/libsql';
5
+ import { type BaseSQLiteDatabase } from 'drizzle-orm/sqlite-core';
6
+ import { GraphQLObjectType, GraphQLSchema } from 'graphql';
7
+ import { createYoga } from 'graphql-yoga';
8
+ import { createServer, type Server } from 'node:http';
9
+ import path from 'path';
10
+ import { afterAll, afterEach, beforeAll, beforeEach, describe, expect, it } from 'vitest';
11
+ import * as schema from './schema/sqlite';
12
+ import { GraphQLClient } from './util/query';
13
+
14
+ interface Context {
15
+ db: BaseSQLiteDatabase<'async', any, typeof schema>;
16
+ client: Client;
17
+ schema: GraphQLSchema;
18
+ entities: GeneratedEntities<BaseSQLiteDatabase<'async', any, typeof schema>>;
19
+ server: Server;
20
+ gql: GraphQLClient;
21
+ }
22
+
23
+ const ctx: Context = {} as any;
24
+
25
+ beforeAll(async () => {
26
+ const sleep = 250;
27
+ let timeLeft = 5000;
28
+ let connected = false;
29
+ let lastError: unknown | undefined;
30
+
31
+ do {
32
+ try {
33
+ ctx.client = createClient({
34
+ url: `file://${path.join(__dirname, '/.temp/db-custom.sqlite')}`,
35
+ });
36
+ connected = true;
37
+ break;
38
+ } catch (e) {
39
+ lastError = e;
40
+ await new Promise((resolve) => setTimeout(resolve, sleep));
41
+ timeLeft -= sleep;
42
+ }
43
+ } while (timeLeft > 0);
44
+
45
+ if (!connected) {
46
+ console.error('Cannot connect to libsql');
47
+ throw lastError;
48
+ }
49
+
50
+ ctx.db = drizzle(ctx.client, {
51
+ schema,
52
+ logger: process.env['LOG_SQL'] ? true : false,
53
+ });
54
+
55
+ const { entities } = buildSchema(ctx.db);
56
+
57
+ const customSchema = new GraphQLSchema({
58
+ query: new GraphQLObjectType({
59
+ name: 'Query',
60
+ fields: {
61
+ customUsersSingle: entities.queries.usersSingle,
62
+ customUsers: entities.queries.users,
63
+ customCustomersSingle: entities.queries.customersSingle,
64
+ customCustomers: entities.queries.customers,
65
+ customPostsSingle: entities.queries.postsSingle,
66
+ customPosts: entities.queries.posts,
67
+ },
68
+ }),
69
+ mutation: new GraphQLObjectType({
70
+ name: 'Mutation',
71
+ fields: {
72
+ deleteFromCustomUsers: entities.mutations.deleteFromUsers,
73
+ deleteFromCustomCustomers: entities.mutations.deleteFromCustomers,
74
+ deleteFromCustomPosts: entities.mutations.deleteFromPosts,
75
+ updateCustomUsers: entities.mutations.updateUsers,
76
+ updateCustomCustomers: entities.mutations.updateCustomers,
77
+ updateCustomPosts: entities.mutations.updatePosts,
78
+ insertIntoCustomUsers: entities.mutations.insertIntoUsers,
79
+ insertIntoCustomUsersSingle: entities.mutations.insertIntoUsersSingle,
80
+ insertIntoCustomCustomers: entities.mutations.insertIntoCustomers,
81
+ insertIntoCustomCustomersSingle: entities.mutations.insertIntoCustomersSingle,
82
+ insertIntoCustomPosts: entities.mutations.insertIntoPosts,
83
+ insertIntoCustomPostsSingle: entities.mutations.insertIntoPostsSingle,
84
+ },
85
+ }),
86
+ types: [...Object.values(entities.types), ...Object.values(entities.inputs)],
87
+ });
88
+
89
+ const yoga = createYoga({
90
+ schema: customSchema,
91
+ });
92
+ const server = createServer(yoga);
93
+
94
+ const port = 5001;
95
+ server.listen(port);
96
+ const gql = new GraphQLClient(`http://localhost:${port}/graphql`);
97
+
98
+ ctx.schema = customSchema;
99
+ ctx.entities = entities;
100
+ ctx.server = server;
101
+ ctx.gql = gql;
102
+ });
103
+
104
+ afterAll(async (t) => {
105
+ ctx.client.close();
106
+ });
107
+
108
+ beforeEach(async (t) => {
109
+ await ctx.db.run(sql`CREATE TABLE IF NOT EXISTS \`customers\` (
110
+ \`id\` integer PRIMARY KEY NOT NULL,
111
+ \`address\` text NOT NULL,
112
+ \`is_confirmed\` integer,
113
+ \`registration_date\` integer NOT NULL,
114
+ \`user_id\` integer NOT NULL,
115
+ FOREIGN KEY (\`user_id\`) REFERENCES \`users\`(\`id\`) ON UPDATE no action ON DELETE no action
116
+ );`);
117
+
118
+ await ctx.db.run(sql`CREATE TABLE IF NOT EXISTS \`posts\` (
119
+ \`id\` integer PRIMARY KEY NOT NULL,
120
+ \`content\` text,
121
+ \`author_id\` integer
122
+ );`);
123
+
124
+ await ctx.db.run(sql`CREATE TABLE IF NOT EXISTS \`users\` (
125
+ \`id\` integer PRIMARY KEY NOT NULL,
126
+ \`name\` text NOT NULL,
127
+ \`email\` text,
128
+ \`text_json\` text,
129
+ \`blob_bigint\` blob,
130
+ \`numeric\` numeric,
131
+ \`created_at\` integer,
132
+ \`created_at_ms\` integer,
133
+ \`real\` real,
134
+ \`text\` text(255),
135
+ \`role\` text DEFAULT 'user',
136
+ \`is_confirmed\` integer
137
+ );`);
138
+
139
+ await ctx.db.insert(schema.Users).values([
140
+ {
141
+ id: 1,
142
+ name: 'FirstUser',
143
+ email: 'userOne@notmail.com',
144
+ textJson: { field: 'value' },
145
+ blobBigInt: BigInt(10),
146
+ numeric: '250.2',
147
+ createdAt: new Date('2024-04-02T06:44:41.785Z'),
148
+ createdAtMs: new Date('2024-04-02T06:44:41.785Z'),
149
+ real: 13.5,
150
+ text: 'sometext',
151
+ role: 'admin',
152
+ isConfirmed: true,
153
+ },
154
+ {
155
+ id: 2,
156
+ name: 'SecondUser',
157
+ createdAt: new Date('2024-04-02T06:44:41.785Z'),
158
+ },
159
+ {
160
+ id: 5,
161
+ name: 'FifthUser',
162
+ createdAt: new Date('2024-04-02T06:44:41.785Z'),
163
+ },
164
+ ]);
165
+
166
+ await ctx.db.insert(schema.Posts).values([
167
+ {
168
+ id: 1,
169
+ authorId: 1,
170
+ content: '1MESSAGE',
171
+ },
172
+ {
173
+ id: 2,
174
+ authorId: 1,
175
+ content: '2MESSAGE',
176
+ },
177
+ {
178
+ id: 3,
179
+ authorId: 1,
180
+ content: '3MESSAGE',
181
+ },
182
+ {
183
+ id: 4,
184
+ authorId: 5,
185
+ content: '1MESSAGE',
186
+ },
187
+ {
188
+ id: 5,
189
+ authorId: 5,
190
+ content: '2MESSAGE',
191
+ },
192
+ {
193
+ id: 6,
194
+ authorId: 1,
195
+ content: '4MESSAGE',
196
+ },
197
+ ]);
198
+
199
+ await ctx.db.insert(schema.Customers).values([
200
+ {
201
+ id: 1,
202
+ address: 'AdOne',
203
+ isConfirmed: false,
204
+ registrationDate: new Date('2024-03-27T03:54:45.235Z'),
205
+ userId: 1,
206
+ },
207
+ {
208
+ id: 2,
209
+ address: 'AdTwo',
210
+ isConfirmed: false,
211
+ registrationDate: new Date('2024-03-27T03:55:42.358Z'),
212
+ userId: 2,
213
+ },
214
+ ]);
215
+ });
216
+
217
+ afterEach(async (t) => {
218
+ await ctx.db.run(sql`PRAGMA foreign_keys = OFF;`);
219
+ await ctx.db.run(sql`DROP TABLE IF EXISTS \`customers\`;`);
220
+ await ctx.db.run(sql`DROP TABLE IF EXISTS \`posts\`;`);
221
+ await ctx.db.run(sql`DROP TABLE IF EXISTS \`users\`;`);
222
+ await ctx.db.run(sql`PRAGMA foreign_keys = ON;`);
223
+ });
224
+
225
+ describe.sequential('Query tests', async () => {
226
+ it(`Select single`, async () => {
227
+ const res = await ctx.gql.queryGql(/* GraphQL */ `
228
+ {
229
+ customUsersSingle {
230
+ id
231
+ name
232
+ email
233
+ textJson
234
+ blobBigInt
235
+ numeric
236
+ createdAt
237
+ createdAtMs
238
+ real
239
+ text
240
+ role
241
+ isConfirmed
242
+ }
243
+
244
+ customPostsSingle {
245
+ id
246
+ authorId
247
+ content
248
+ }
249
+ }
250
+ `);
251
+
252
+ expect(res).toStrictEqual({
253
+ data: {
254
+ customUsersSingle: {
255
+ id: 1,
256
+ name: 'FirstUser',
257
+ email: 'userOne@notmail.com',
258
+ textJson: '{"field":"value"}',
259
+ blobBigInt: '10',
260
+ numeric: '250.2',
261
+ createdAt: '2024-04-02T06:44:41.000Z',
262
+ createdAtMs: '2024-04-02T06:44:41.785Z',
263
+ real: 13.5,
264
+ text: 'sometext',
265
+ role: 'admin',
266
+ isConfirmed: true,
267
+ },
268
+ customPostsSingle: {
269
+ id: 1,
270
+ authorId: 1,
271
+ content: '1MESSAGE',
272
+ },
273
+ },
274
+ });
275
+ });
276
+
277
+ it(`Select array`, async () => {
278
+ const res = await ctx.gql.queryGql(/* GraphQL */ `
279
+ {
280
+ customUsers {
281
+ id
282
+ name
283
+ email
284
+ textJson
285
+ blobBigInt
286
+ numeric
287
+ createdAt
288
+ createdAtMs
289
+ real
290
+ text
291
+ role
292
+ isConfirmed
293
+ }
294
+
295
+ customPosts {
296
+ id
297
+ authorId
298
+ content
299
+ }
300
+ }
301
+ `);
302
+
303
+ expect(res).toStrictEqual({
304
+ data: {
305
+ customUsers: [
306
+ {
307
+ id: 1,
308
+ name: 'FirstUser',
309
+ email: 'userOne@notmail.com',
310
+ textJson: '{"field":"value"}',
311
+ blobBigInt: '10',
312
+ numeric: '250.2',
313
+ createdAt: '2024-04-02T06:44:41.000Z',
314
+ createdAtMs: '2024-04-02T06:44:41.785Z',
315
+ real: 13.5,
316
+ text: 'sometext',
317
+ role: 'admin',
318
+ isConfirmed: true,
319
+ },
320
+ {
321
+ id: 2,
322
+ name: 'SecondUser',
323
+ email: null,
324
+ blobBigInt: null,
325
+ textJson: null,
326
+ createdAt: '2024-04-02T06:44:41.000Z',
327
+ createdAtMs: null,
328
+ numeric: null,
329
+ real: null,
330
+ text: null,
331
+ role: 'user',
332
+ isConfirmed: null,
333
+ },
334
+ {
335
+ id: 5,
336
+ name: 'FifthUser',
337
+ email: null,
338
+ createdAt: '2024-04-02T06:44:41.000Z',
339
+ role: 'user',
340
+ blobBigInt: null,
341
+ textJson: null,
342
+ createdAtMs: null,
343
+ numeric: null,
344
+ real: null,
345
+ text: null,
346
+ isConfirmed: null,
347
+ },
348
+ ],
349
+ customPosts: [
350
+ {
351
+ id: 1,
352
+ authorId: 1,
353
+ content: '1MESSAGE',
354
+ },
355
+ {
356
+ id: 2,
357
+ authorId: 1,
358
+ content: '2MESSAGE',
359
+ },
360
+ {
361
+ id: 3,
362
+ authorId: 1,
363
+ content: '3MESSAGE',
364
+ },
365
+ {
366
+ id: 4,
367
+ authorId: 5,
368
+ content: '1MESSAGE',
369
+ },
370
+ {
371
+ id: 5,
372
+ authorId: 5,
373
+ content: '2MESSAGE',
374
+ },
375
+ {
376
+ id: 6,
377
+ authorId: 1,
378
+ content: '4MESSAGE',
379
+ },
380
+ ],
381
+ },
382
+ });
383
+ });
384
+
385
+ it(`Select single with relations`, async () => {
386
+ const res = await ctx.gql.queryGql(/* GraphQL */ `
387
+ {
388
+ customUsersSingle {
389
+ id
390
+ name
391
+ email
392
+ textJson
393
+ blobBigInt
394
+ numeric
395
+ createdAt
396
+ createdAtMs
397
+ real
398
+ text
399
+ role
400
+ isConfirmed
401
+ posts {
402
+ id
403
+ authorId
404
+ content
405
+ }
406
+ }
407
+
408
+ customPostsSingle {
409
+ id
410
+ authorId
411
+ content
412
+ author {
413
+ id
414
+ name
415
+ email
416
+ textJson
417
+ numeric
418
+ createdAt
419
+ createdAtMs
420
+ real
421
+ text
422
+ role
423
+ isConfirmed
424
+ }
425
+ }
426
+ }
427
+ `);
428
+
429
+ expect(res).toStrictEqual({
430
+ data: {
431
+ customUsersSingle: {
432
+ id: 1,
433
+ name: 'FirstUser',
434
+ email: 'userOne@notmail.com',
435
+ textJson: '{"field":"value"}',
436
+ blobBigInt: '10',
437
+ numeric: '250.2',
438
+ createdAt: '2024-04-02T06:44:41.000Z',
439
+ createdAtMs: '2024-04-02T06:44:41.785Z',
440
+ real: 13.5,
441
+ text: 'sometext',
442
+ role: 'admin',
443
+ isConfirmed: true,
444
+ posts: [
445
+ {
446
+ id: 1,
447
+ authorId: 1,
448
+ content: '1MESSAGE',
449
+ },
450
+ {
451
+ id: 2,
452
+ authorId: 1,
453
+ content: '2MESSAGE',
454
+ },
455
+ {
456
+ id: 3,
457
+ authorId: 1,
458
+ content: '3MESSAGE',
459
+ },
460
+
461
+ {
462
+ id: 6,
463
+ authorId: 1,
464
+ content: '4MESSAGE',
465
+ },
466
+ ],
467
+ },
468
+ customPostsSingle: {
469
+ id: 1,
470
+ authorId: 1,
471
+ content: '1MESSAGE',
472
+ author: {
473
+ id: 1,
474
+ name: 'FirstUser',
475
+ email: 'userOne@notmail.com',
476
+ textJson: '{"field":"value"}',
477
+ // RQB can't handle blobs in JSON, for now
478
+ // blobBigInt: '10',
479
+ numeric: '250.2',
480
+ createdAt: '2024-04-02T06:44:41.000Z',
481
+ createdAtMs: '2024-04-02T06:44:41.785Z',
482
+ real: 13.5,
483
+ text: 'sometext',
484
+ role: 'admin',
485
+ isConfirmed: true,
486
+ },
487
+ },
488
+ },
489
+ });
490
+ });
491
+
492
+ it(`Select array with relations`, async () => {
493
+ const res = await ctx.gql.queryGql(/* GraphQL */ `
494
+ {
495
+ customUsers {
496
+ id
497
+ name
498
+ email
499
+ textJson
500
+ blobBigInt
501
+ numeric
502
+ createdAt
503
+ createdAtMs
504
+ real
505
+ text
506
+ role
507
+ isConfirmed
508
+ posts {
509
+ id
510
+ authorId
511
+ content
512
+ }
513
+ }
514
+
515
+ customPosts {
516
+ id
517
+ authorId
518
+ content
519
+ author {
520
+ id
521
+ name
522
+ email
523
+ textJson
524
+ numeric
525
+ createdAt
526
+ createdAtMs
527
+ real
528
+ text
529
+ role
530
+ isConfirmed
531
+ }
532
+ }
533
+ }
534
+ `);
535
+
536
+ expect(res).toStrictEqual({
537
+ data: {
538
+ customUsers: [
539
+ {
540
+ id: 1,
541
+ name: 'FirstUser',
542
+ email: 'userOne@notmail.com',
543
+ textJson: '{"field":"value"}',
544
+ blobBigInt: '10',
545
+ numeric: '250.2',
546
+ createdAt: '2024-04-02T06:44:41.000Z',
547
+ createdAtMs: '2024-04-02T06:44:41.785Z',
548
+ real: 13.5,
549
+ text: 'sometext',
550
+ role: 'admin',
551
+ isConfirmed: true,
552
+ posts: [
553
+ {
554
+ id: 1,
555
+ authorId: 1,
556
+ content: '1MESSAGE',
557
+ },
558
+ {
559
+ id: 2,
560
+ authorId: 1,
561
+ content: '2MESSAGE',
562
+ },
563
+ {
564
+ id: 3,
565
+ authorId: 1,
566
+ content: '3MESSAGE',
567
+ },
568
+ {
569
+ id: 6,
570
+ authorId: 1,
571
+ content: '4MESSAGE',
572
+ },
573
+ ],
574
+ },
575
+ {
576
+ id: 2,
577
+ name: 'SecondUser',
578
+ email: null,
579
+ textJson: null,
580
+ blobBigInt: null,
581
+ numeric: null,
582
+ createdAt: '2024-04-02T06:44:41.000Z',
583
+ createdAtMs: null,
584
+ real: null,
585
+ text: null,
586
+ role: 'user',
587
+ isConfirmed: null,
588
+ posts: [],
589
+ },
590
+ {
591
+ id: 5,
592
+ name: 'FifthUser',
593
+ email: null,
594
+ textJson: null,
595
+ blobBigInt: null,
596
+ numeric: null,
597
+ createdAt: '2024-04-02T06:44:41.000Z',
598
+ createdAtMs: null,
599
+ real: null,
600
+ text: null,
601
+ role: 'user',
602
+ isConfirmed: null,
603
+ posts: [
604
+ {
605
+ id: 4,
606
+ authorId: 5,
607
+ content: '1MESSAGE',
608
+ },
609
+ {
610
+ id: 5,
611
+ authorId: 5,
612
+ content: '2MESSAGE',
613
+ },
614
+ ],
615
+ },
616
+ ],
617
+ customPosts: [
618
+ {
619
+ id: 1,
620
+ authorId: 1,
621
+ content: '1MESSAGE',
622
+ author: {
623
+ id: 1,
624
+ name: 'FirstUser',
625
+ email: 'userOne@notmail.com',
626
+ textJson: '{"field":"value"}',
627
+ // RQB can't handle blobs in JSON, for now
628
+ // blobBigInt: '10',
629
+ numeric: '250.2',
630
+ createdAt: '2024-04-02T06:44:41.000Z',
631
+ createdAtMs: '2024-04-02T06:44:41.785Z',
632
+ real: 13.5,
633
+ text: 'sometext',
634
+ role: 'admin',
635
+ isConfirmed: true,
636
+ },
637
+ },
638
+ {
639
+ id: 2,
640
+ authorId: 1,
641
+ content: '2MESSAGE',
642
+ author: {
643
+ id: 1,
644
+ name: 'FirstUser',
645
+ email: 'userOne@notmail.com',
646
+ textJson: '{"field":"value"}',
647
+ // RQB can't handle blobs in JSON, for now
648
+ // blobBigInt: '10',
649
+ numeric: '250.2',
650
+ createdAt: '2024-04-02T06:44:41.000Z',
651
+ createdAtMs: '2024-04-02T06:44:41.785Z',
652
+ real: 13.5,
653
+ text: 'sometext',
654
+ role: 'admin',
655
+ isConfirmed: true,
656
+ },
657
+ },
658
+ {
659
+ id: 3,
660
+ authorId: 1,
661
+ content: '3MESSAGE',
662
+ author: {
663
+ id: 1,
664
+ name: 'FirstUser',
665
+ email: 'userOne@notmail.com',
666
+ textJson: '{"field":"value"}',
667
+ // RQB can't handle blobs in JSON, for now
668
+ // blobBigInt: '10',
669
+ numeric: '250.2',
670
+ createdAt: '2024-04-02T06:44:41.000Z',
671
+ createdAtMs: '2024-04-02T06:44:41.785Z',
672
+ real: 13.5,
673
+ text: 'sometext',
674
+ role: 'admin',
675
+ isConfirmed: true,
676
+ },
677
+ },
678
+ {
679
+ id: 4,
680
+ authorId: 5,
681
+ content: '1MESSAGE',
682
+ author: {
683
+ id: 5,
684
+ name: 'FifthUser',
685
+ email: null,
686
+ textJson: null,
687
+ // RQB can't handle blobs in JSON, for now
688
+ // blobBigInt: null,
689
+ numeric: null,
690
+ createdAt: '2024-04-02T06:44:41.000Z',
691
+ createdAtMs: null,
692
+ real: null,
693
+ text: null,
694
+ role: 'user',
695
+ isConfirmed: null,
696
+ },
697
+ },
698
+ {
699
+ id: 5,
700
+ authorId: 5,
701
+ content: '2MESSAGE',
702
+ author: {
703
+ id: 5,
704
+ name: 'FifthUser',
705
+ email: null,
706
+ textJson: null,
707
+ // RQB can't handle blobs in JSON, for now
708
+ // blobBigInt: null,
709
+ numeric: null,
710
+ createdAt: '2024-04-02T06:44:41.000Z',
711
+ createdAtMs: null,
712
+ real: null,
713
+ text: null,
714
+ role: 'user',
715
+ isConfirmed: null,
716
+ },
717
+ },
718
+ {
719
+ id: 6,
720
+ authorId: 1,
721
+ content: '4MESSAGE',
722
+ author: {
723
+ id: 1,
724
+ name: 'FirstUser',
725
+ email: 'userOne@notmail.com',
726
+ textJson: '{"field":"value"}',
727
+ // RQB can't handle blobs in JSON, for now
728
+ // blobBigInt: '10',
729
+ numeric: '250.2',
730
+ createdAt: '2024-04-02T06:44:41.000Z',
731
+ createdAtMs: '2024-04-02T06:44:41.785Z',
732
+ real: 13.5,
733
+ text: 'sometext',
734
+ role: 'admin',
735
+ isConfirmed: true,
736
+ },
737
+ },
738
+ ],
739
+ },
740
+ });
741
+ });
742
+
743
+ it(`Select single by fragment`, async () => {
744
+ const res = await ctx.gql.queryGql(/* GraphQL */ `
745
+ query testQuery {
746
+ customUsersSingle {
747
+ ...UsersFrag
748
+ }
749
+
750
+ customPostsSingle {
751
+ ...PostsFrag
752
+ }
753
+ }
754
+
755
+ fragment UsersFrag on UsersSelectItem {
756
+ id
757
+ name
758
+ email
759
+ textJson
760
+ blobBigInt
761
+ numeric
762
+ createdAt
763
+ createdAtMs
764
+ real
765
+ text
766
+ role
767
+ isConfirmed
768
+ }
769
+
770
+ fragment PostsFrag on PostsSelectItem {
771
+ id
772
+ authorId
773
+ content
774
+ }
775
+ `);
776
+
777
+ expect(res).toStrictEqual({
778
+ data: {
779
+ customUsersSingle: {
780
+ id: 1,
781
+ name: 'FirstUser',
782
+ email: 'userOne@notmail.com',
783
+ textJson: '{"field":"value"}',
784
+ blobBigInt: '10',
785
+ numeric: '250.2',
786
+ createdAt: '2024-04-02T06:44:41.000Z',
787
+ createdAtMs: '2024-04-02T06:44:41.785Z',
788
+ real: 13.5,
789
+ text: 'sometext',
790
+ role: 'admin',
791
+ isConfirmed: true,
792
+ },
793
+ customPostsSingle: {
794
+ id: 1,
795
+ authorId: 1,
796
+ content: '1MESSAGE',
797
+ },
798
+ },
799
+ });
800
+ });
801
+
802
+ it(`Select array by fragment`, async () => {
803
+ const res = await ctx.gql.queryGql(/* GraphQL */ `
804
+ query testQuery {
805
+ customUsers {
806
+ ...UsersFrag
807
+ }
808
+
809
+ customPosts {
810
+ ...PostsFrag
811
+ }
812
+ }
813
+
814
+ fragment UsersFrag on UsersSelectItem {
815
+ id
816
+ name
817
+ email
818
+ textJson
819
+ blobBigInt
820
+ numeric
821
+ createdAt
822
+ createdAtMs
823
+ real
824
+ text
825
+ role
826
+ isConfirmed
827
+ }
828
+
829
+ fragment PostsFrag on PostsSelectItem {
830
+ id
831
+ authorId
832
+ content
833
+ }
834
+ `);
835
+
836
+ expect(res).toStrictEqual({
837
+ data: {
838
+ customUsers: [
839
+ {
840
+ id: 1,
841
+ name: 'FirstUser',
842
+ email: 'userOne@notmail.com',
843
+ textJson: '{"field":"value"}',
844
+ blobBigInt: '10',
845
+ numeric: '250.2',
846
+ createdAt: '2024-04-02T06:44:41.000Z',
847
+ createdAtMs: '2024-04-02T06:44:41.785Z',
848
+ real: 13.5,
849
+ text: 'sometext',
850
+ role: 'admin',
851
+ isConfirmed: true,
852
+ },
853
+ {
854
+ id: 2,
855
+ name: 'SecondUser',
856
+ email: null,
857
+ blobBigInt: null,
858
+ textJson: null,
859
+ createdAt: '2024-04-02T06:44:41.000Z',
860
+ createdAtMs: null,
861
+ numeric: null,
862
+ real: null,
863
+ text: null,
864
+ role: 'user',
865
+ isConfirmed: null,
866
+ },
867
+ {
868
+ id: 5,
869
+ name: 'FifthUser',
870
+ email: null,
871
+ createdAt: '2024-04-02T06:44:41.000Z',
872
+ role: 'user',
873
+ blobBigInt: null,
874
+ textJson: null,
875
+ createdAtMs: null,
876
+ numeric: null,
877
+ real: null,
878
+ text: null,
879
+ isConfirmed: null,
880
+ },
881
+ ],
882
+ customPosts: [
883
+ {
884
+ id: 1,
885
+ authorId: 1,
886
+ content: '1MESSAGE',
887
+ },
888
+ {
889
+ id: 2,
890
+ authorId: 1,
891
+ content: '2MESSAGE',
892
+ },
893
+ {
894
+ id: 3,
895
+ authorId: 1,
896
+ content: '3MESSAGE',
897
+ },
898
+ {
899
+ id: 4,
900
+ authorId: 5,
901
+ content: '1MESSAGE',
902
+ },
903
+ {
904
+ id: 5,
905
+ authorId: 5,
906
+ content: '2MESSAGE',
907
+ },
908
+ {
909
+ id: 6,
910
+ authorId: 1,
911
+ content: '4MESSAGE',
912
+ },
913
+ ],
914
+ },
915
+ });
916
+ });
917
+
918
+ it(`Select single with relations by fragment`, async () => {
919
+ const res = await ctx.gql.queryGql(/* GraphQL */ `
920
+ query testQuery {
921
+ customUsersSingle {
922
+ ...UsersFrag
923
+ }
924
+
925
+ customPostsSingle {
926
+ ...PostsFrag
927
+ }
928
+ }
929
+
930
+ fragment UsersFrag on UsersSelectItem {
931
+ id
932
+ name
933
+ email
934
+ textJson
935
+ blobBigInt
936
+ numeric
937
+ createdAt
938
+ createdAtMs
939
+ real
940
+ text
941
+ role
942
+ isConfirmed
943
+ posts {
944
+ id
945
+ authorId
946
+ content
947
+ }
948
+ }
949
+
950
+ fragment PostsFrag on PostsSelectItem {
951
+ id
952
+ authorId
953
+ content
954
+ author {
955
+ id
956
+ name
957
+ email
958
+ textJson
959
+ numeric
960
+ createdAt
961
+ createdAtMs
962
+ real
963
+ text
964
+ role
965
+ isConfirmed
966
+ }
967
+ }
968
+ `);
969
+
970
+ expect(res).toStrictEqual({
971
+ data: {
972
+ customUsersSingle: {
973
+ id: 1,
974
+ name: 'FirstUser',
975
+ email: 'userOne@notmail.com',
976
+ textJson: '{"field":"value"}',
977
+ blobBigInt: '10',
978
+ numeric: '250.2',
979
+ createdAt: '2024-04-02T06:44:41.000Z',
980
+ createdAtMs: '2024-04-02T06:44:41.785Z',
981
+ real: 13.5,
982
+ text: 'sometext',
983
+ role: 'admin',
984
+ isConfirmed: true,
985
+ posts: [
986
+ {
987
+ id: 1,
988
+ authorId: 1,
989
+ content: '1MESSAGE',
990
+ },
991
+ {
992
+ id: 2,
993
+ authorId: 1,
994
+ content: '2MESSAGE',
995
+ },
996
+ {
997
+ id: 3,
998
+ authorId: 1,
999
+ content: '3MESSAGE',
1000
+ },
1001
+
1002
+ {
1003
+ id: 6,
1004
+ authorId: 1,
1005
+ content: '4MESSAGE',
1006
+ },
1007
+ ],
1008
+ },
1009
+ customPostsSingle: {
1010
+ id: 1,
1011
+ authorId: 1,
1012
+ content: '1MESSAGE',
1013
+ author: {
1014
+ id: 1,
1015
+ name: 'FirstUser',
1016
+ email: 'userOne@notmail.com',
1017
+ textJson: '{"field":"value"}',
1018
+ // RQB can't handle blobs in JSON, for now
1019
+ // blobBigInt: '10',
1020
+ numeric: '250.2',
1021
+ createdAt: '2024-04-02T06:44:41.000Z',
1022
+ createdAtMs: '2024-04-02T06:44:41.785Z',
1023
+ real: 13.5,
1024
+ text: 'sometext',
1025
+ role: 'admin',
1026
+ isConfirmed: true,
1027
+ },
1028
+ },
1029
+ },
1030
+ });
1031
+ });
1032
+
1033
+ it(`Select array with relations by fragment`, async () => {
1034
+ const res = await ctx.gql.queryGql(/* GraphQL */ `
1035
+ query testQuery {
1036
+ customUsers {
1037
+ ...UsersFrag
1038
+ }
1039
+
1040
+ customPosts {
1041
+ ...PostsFrag
1042
+ }
1043
+ }
1044
+
1045
+ fragment UsersFrag on UsersSelectItem {
1046
+ id
1047
+ name
1048
+ email
1049
+ textJson
1050
+ blobBigInt
1051
+ numeric
1052
+ createdAt
1053
+ createdAtMs
1054
+ real
1055
+ text
1056
+ role
1057
+ isConfirmed
1058
+ posts {
1059
+ id
1060
+ authorId
1061
+ content
1062
+ }
1063
+ }
1064
+
1065
+ fragment PostsFrag on PostsSelectItem {
1066
+ id
1067
+ authorId
1068
+ content
1069
+ author {
1070
+ id
1071
+ name
1072
+ email
1073
+ textJson
1074
+ numeric
1075
+ createdAt
1076
+ createdAtMs
1077
+ real
1078
+ text
1079
+ role
1080
+ isConfirmed
1081
+ }
1082
+ }
1083
+ `);
1084
+
1085
+ expect(res).toStrictEqual({
1086
+ data: {
1087
+ customUsers: [
1088
+ {
1089
+ id: 1,
1090
+ name: 'FirstUser',
1091
+ email: 'userOne@notmail.com',
1092
+ textJson: '{"field":"value"}',
1093
+ blobBigInt: '10',
1094
+ numeric: '250.2',
1095
+ createdAt: '2024-04-02T06:44:41.000Z',
1096
+ createdAtMs: '2024-04-02T06:44:41.785Z',
1097
+ real: 13.5,
1098
+ text: 'sometext',
1099
+ role: 'admin',
1100
+ isConfirmed: true,
1101
+ posts: [
1102
+ {
1103
+ id: 1,
1104
+ authorId: 1,
1105
+ content: '1MESSAGE',
1106
+ },
1107
+ {
1108
+ id: 2,
1109
+ authorId: 1,
1110
+ content: '2MESSAGE',
1111
+ },
1112
+ {
1113
+ id: 3,
1114
+ authorId: 1,
1115
+ content: '3MESSAGE',
1116
+ },
1117
+ {
1118
+ id: 6,
1119
+ authorId: 1,
1120
+ content: '4MESSAGE',
1121
+ },
1122
+ ],
1123
+ },
1124
+ {
1125
+ id: 2,
1126
+ name: 'SecondUser',
1127
+ email: null,
1128
+ textJson: null,
1129
+ blobBigInt: null,
1130
+ numeric: null,
1131
+ createdAt: '2024-04-02T06:44:41.000Z',
1132
+ createdAtMs: null,
1133
+ real: null,
1134
+ text: null,
1135
+ role: 'user',
1136
+ isConfirmed: null,
1137
+ posts: [],
1138
+ },
1139
+ {
1140
+ id: 5,
1141
+ name: 'FifthUser',
1142
+ email: null,
1143
+ textJson: null,
1144
+ blobBigInt: null,
1145
+ numeric: null,
1146
+ createdAt: '2024-04-02T06:44:41.000Z',
1147
+ createdAtMs: null,
1148
+ real: null,
1149
+ text: null,
1150
+ role: 'user',
1151
+ isConfirmed: null,
1152
+ posts: [
1153
+ {
1154
+ id: 4,
1155
+ authorId: 5,
1156
+ content: '1MESSAGE',
1157
+ },
1158
+ {
1159
+ id: 5,
1160
+ authorId: 5,
1161
+ content: '2MESSAGE',
1162
+ },
1163
+ ],
1164
+ },
1165
+ ],
1166
+ customPosts: [
1167
+ {
1168
+ id: 1,
1169
+ authorId: 1,
1170
+ content: '1MESSAGE',
1171
+ author: {
1172
+ id: 1,
1173
+ name: 'FirstUser',
1174
+ email: 'userOne@notmail.com',
1175
+ textJson: '{"field":"value"}',
1176
+ // RQB can't handle blobs in JSON, for now
1177
+ // blobBigInt: '10',
1178
+ numeric: '250.2',
1179
+ createdAt: '2024-04-02T06:44:41.000Z',
1180
+ createdAtMs: '2024-04-02T06:44:41.785Z',
1181
+ real: 13.5,
1182
+ text: 'sometext',
1183
+ role: 'admin',
1184
+ isConfirmed: true,
1185
+ },
1186
+ },
1187
+ {
1188
+ id: 2,
1189
+ authorId: 1,
1190
+ content: '2MESSAGE',
1191
+ author: {
1192
+ id: 1,
1193
+ name: 'FirstUser',
1194
+ email: 'userOne@notmail.com',
1195
+ textJson: '{"field":"value"}',
1196
+ // RQB can't handle blobs in JSON, for now
1197
+ // blobBigInt: '10',
1198
+ numeric: '250.2',
1199
+ createdAt: '2024-04-02T06:44:41.000Z',
1200
+ createdAtMs: '2024-04-02T06:44:41.785Z',
1201
+ real: 13.5,
1202
+ text: 'sometext',
1203
+ role: 'admin',
1204
+ isConfirmed: true,
1205
+ },
1206
+ },
1207
+ {
1208
+ id: 3,
1209
+ authorId: 1,
1210
+ content: '3MESSAGE',
1211
+ author: {
1212
+ id: 1,
1213
+ name: 'FirstUser',
1214
+ email: 'userOne@notmail.com',
1215
+ textJson: '{"field":"value"}',
1216
+ // RQB can't handle blobs in JSON, for now
1217
+ // blobBigInt: '10',
1218
+ numeric: '250.2',
1219
+ createdAt: '2024-04-02T06:44:41.000Z',
1220
+ createdAtMs: '2024-04-02T06:44:41.785Z',
1221
+ real: 13.5,
1222
+ text: 'sometext',
1223
+ role: 'admin',
1224
+ isConfirmed: true,
1225
+ },
1226
+ },
1227
+ {
1228
+ id: 4,
1229
+ authorId: 5,
1230
+ content: '1MESSAGE',
1231
+ author: {
1232
+ id: 5,
1233
+ name: 'FifthUser',
1234
+ email: null,
1235
+ textJson: null,
1236
+ // RQB can't handle blobs in JSON, for now
1237
+ // blobBigInt: null,
1238
+ numeric: null,
1239
+ createdAt: '2024-04-02T06:44:41.000Z',
1240
+ createdAtMs: null,
1241
+ real: null,
1242
+ text: null,
1243
+ role: 'user',
1244
+ isConfirmed: null,
1245
+ },
1246
+ },
1247
+ {
1248
+ id: 5,
1249
+ authorId: 5,
1250
+ content: '2MESSAGE',
1251
+ author: {
1252
+ id: 5,
1253
+ name: 'FifthUser',
1254
+ email: null,
1255
+ textJson: null,
1256
+ // RQB can't handle blobs in JSON, for now
1257
+ // blobBigInt: null,
1258
+ numeric: null,
1259
+ createdAt: '2024-04-02T06:44:41.000Z',
1260
+ createdAtMs: null,
1261
+ real: null,
1262
+ text: null,
1263
+ role: 'user',
1264
+ isConfirmed: null,
1265
+ },
1266
+ },
1267
+ {
1268
+ id: 6,
1269
+ authorId: 1,
1270
+ content: '4MESSAGE',
1271
+ author: {
1272
+ id: 1,
1273
+ name: 'FirstUser',
1274
+ email: 'userOne@notmail.com',
1275
+ textJson: '{"field":"value"}',
1276
+ // RQB can't handle blobs in JSON, for now
1277
+ // blobBigInt: '10',
1278
+ numeric: '250.2',
1279
+ createdAt: '2024-04-02T06:44:41.000Z',
1280
+ createdAtMs: '2024-04-02T06:44:41.785Z',
1281
+ real: 13.5,
1282
+ text: 'sometext',
1283
+ role: 'admin',
1284
+ isConfirmed: true,
1285
+ },
1286
+ },
1287
+ ],
1288
+ },
1289
+ });
1290
+ });
1291
+
1292
+ it(`Insert single`, async () => {
1293
+ const res = await ctx.gql.queryGql(/* GraphQL */ `
1294
+ mutation {
1295
+ insertIntoCustomUsersSingle(
1296
+ values: {
1297
+ id: 3
1298
+ name: "ThirdUser"
1299
+ email: "userThree@notmail.com"
1300
+ textJson: "{ \\"field\\": \\"value\\" }"
1301
+ blobBigInt: "10"
1302
+ numeric: "250.2"
1303
+ createdAt: "2024-04-02T06:44:41.785Z"
1304
+ createdAtMs: "2024-04-02T06:44:41.785Z"
1305
+ real: 13.5
1306
+ text: "sometext"
1307
+ role: admin
1308
+ isConfirmed: true
1309
+ }
1310
+ ) {
1311
+ id
1312
+ name
1313
+ email
1314
+ textJson
1315
+ blobBigInt
1316
+ numeric
1317
+ createdAt
1318
+ createdAtMs
1319
+ real
1320
+ text
1321
+ role
1322
+ isConfirmed
1323
+ }
1324
+ }
1325
+ `);
1326
+
1327
+ expect(res).toStrictEqual({
1328
+ data: {
1329
+ insertIntoCustomUsersSingle: {
1330
+ id: 3,
1331
+ name: 'ThirdUser',
1332
+ email: 'userThree@notmail.com',
1333
+ textJson: '{"field":"value"}',
1334
+ blobBigInt: '10',
1335
+ numeric: '250.2',
1336
+ createdAt: '2024-04-02T06:44:41.000Z',
1337
+ createdAtMs: '2024-04-02T06:44:41.785Z',
1338
+ real: 13.5,
1339
+ text: 'sometext',
1340
+ role: 'admin',
1341
+ isConfirmed: true,
1342
+ },
1343
+ },
1344
+ });
1345
+ });
1346
+
1347
+ it(`Insert array`, async () => {
1348
+ const res = await ctx.gql.queryGql(/* GraphQL */ `
1349
+ mutation {
1350
+ insertIntoCustomUsers(
1351
+ values: [
1352
+ {
1353
+ id: 3
1354
+ name: "ThirdUser"
1355
+ email: "userThree@notmail.com"
1356
+ textJson: "{ \\"field\\": \\"value\\" }"
1357
+ blobBigInt: "10"
1358
+ numeric: "250.2"
1359
+ createdAt: "2024-04-02T06:44:41.785Z"
1360
+ createdAtMs: "2024-04-02T06:44:41.785Z"
1361
+ real: 13.5
1362
+ text: "sometext"
1363
+ role: admin
1364
+ isConfirmed: true
1365
+ }
1366
+ {
1367
+ id: 4
1368
+ name: "FourthUser"
1369
+ email: "userFour@notmail.com"
1370
+ textJson: "{ \\"field\\": \\"value\\" }"
1371
+ blobBigInt: "10"
1372
+ numeric: "250.2"
1373
+ createdAt: "2024-04-02T06:44:41.785Z"
1374
+ createdAtMs: "2024-04-02T06:44:41.785Z"
1375
+ real: 13.5
1376
+ text: "sometext"
1377
+ role: user
1378
+ isConfirmed: false
1379
+ }
1380
+ ]
1381
+ ) {
1382
+ id
1383
+ name
1384
+ email
1385
+ textJson
1386
+ blobBigInt
1387
+ numeric
1388
+ createdAt
1389
+ createdAtMs
1390
+ real
1391
+ text
1392
+ role
1393
+ isConfirmed
1394
+ }
1395
+ }
1396
+ `);
1397
+
1398
+ expect(res).toStrictEqual({
1399
+ data: {
1400
+ insertIntoCustomUsers: [
1401
+ {
1402
+ id: 3,
1403
+ name: 'ThirdUser',
1404
+ email: 'userThree@notmail.com',
1405
+ textJson: '{"field":"value"}',
1406
+ blobBigInt: '10',
1407
+ numeric: '250.2',
1408
+ createdAt: '2024-04-02T06:44:41.000Z',
1409
+ createdAtMs: '2024-04-02T06:44:41.785Z',
1410
+ real: 13.5,
1411
+ text: 'sometext',
1412
+ role: 'admin',
1413
+ isConfirmed: true,
1414
+ },
1415
+ {
1416
+ id: 4,
1417
+ name: 'FourthUser',
1418
+ email: 'userFour@notmail.com',
1419
+ textJson: '{"field":"value"}',
1420
+ blobBigInt: '10',
1421
+ numeric: '250.2',
1422
+ createdAt: '2024-04-02T06:44:41.000Z',
1423
+ createdAtMs: '2024-04-02T06:44:41.785Z',
1424
+ real: 13.5,
1425
+ text: 'sometext',
1426
+ role: 'user',
1427
+ isConfirmed: false,
1428
+ },
1429
+ ],
1430
+ },
1431
+ });
1432
+ });
1433
+
1434
+ it(`Update`, async () => {
1435
+ const res = await ctx.gql.queryGql(/* GraphQL */ `
1436
+ mutation {
1437
+ updateCustomCustomers(set: { isConfirmed: true, address: "Edited" }) {
1438
+ id
1439
+ address
1440
+ isConfirmed
1441
+ registrationDate
1442
+ userId
1443
+ }
1444
+ }
1445
+ `);
1446
+
1447
+ expect(res).toStrictEqual({
1448
+ data: {
1449
+ updateCustomCustomers: [
1450
+ {
1451
+ id: 1,
1452
+ address: 'Edited',
1453
+ isConfirmed: true,
1454
+ registrationDate: '2024-03-27T03:54:45.235Z',
1455
+ userId: 1,
1456
+ },
1457
+ {
1458
+ id: 2,
1459
+ address: 'Edited',
1460
+ isConfirmed: true,
1461
+ registrationDate: '2024-03-27T03:55:42.358Z',
1462
+ userId: 2,
1463
+ },
1464
+ ],
1465
+ },
1466
+ });
1467
+ });
1468
+
1469
+ it(`Delete`, async () => {
1470
+ const res = await ctx.gql.queryGql(/* GraphQL */ `
1471
+ mutation {
1472
+ deleteFromCustomCustomers {
1473
+ id
1474
+ address
1475
+ isConfirmed
1476
+ registrationDate
1477
+ userId
1478
+ }
1479
+ }
1480
+ `);
1481
+
1482
+ expect(res).toStrictEqual({
1483
+ data: {
1484
+ deleteFromCustomCustomers: [
1485
+ {
1486
+ id: 1,
1487
+ address: 'AdOne',
1488
+ isConfirmed: false,
1489
+ registrationDate: '2024-03-27T03:54:45.235Z',
1490
+ userId: 1,
1491
+ },
1492
+ {
1493
+ id: 2,
1494
+ address: 'AdTwo',
1495
+ isConfirmed: false,
1496
+ registrationDate: '2024-03-27T03:55:42.358Z',
1497
+ userId: 2,
1498
+ },
1499
+ ],
1500
+ },
1501
+ });
1502
+ });
1503
+ });
1504
+
1505
+ describe.sequential('Arguments tests', async () => {
1506
+ it('Order by', async () => {
1507
+ const res = await ctx.gql.queryGql(/* GraphQL */ `
1508
+ {
1509
+ customPosts(
1510
+ orderBy: { authorId: { priority: 1, direction: desc }, content: { priority: 0, direction: asc } }
1511
+ ) {
1512
+ id
1513
+ authorId
1514
+ content
1515
+ }
1516
+ }
1517
+ `);
1518
+
1519
+ expect(res).toStrictEqual({
1520
+ data: {
1521
+ customPosts: [
1522
+ {
1523
+ id: 4,
1524
+ authorId: 5,
1525
+ content: '1MESSAGE',
1526
+ },
1527
+ {
1528
+ id: 5,
1529
+ authorId: 5,
1530
+ content: '2MESSAGE',
1531
+ },
1532
+ {
1533
+ id: 1,
1534
+ authorId: 1,
1535
+ content: '1MESSAGE',
1536
+ },
1537
+ {
1538
+ id: 2,
1539
+ authorId: 1,
1540
+ content: '2MESSAGE',
1541
+ },
1542
+ {
1543
+ id: 3,
1544
+ authorId: 1,
1545
+ content: '3MESSAGE',
1546
+ },
1547
+
1548
+ {
1549
+ id: 6,
1550
+ authorId: 1,
1551
+ content: '4MESSAGE',
1552
+ },
1553
+ ],
1554
+ },
1555
+ });
1556
+ });
1557
+
1558
+ it('Order by on single', async () => {
1559
+ const res = await ctx.gql.queryGql(/* GraphQL */ `
1560
+ {
1561
+ customPostsSingle(
1562
+ orderBy: { authorId: { priority: 1, direction: desc }, content: { priority: 0, direction: asc } }
1563
+ ) {
1564
+ id
1565
+ authorId
1566
+ content
1567
+ }
1568
+ }
1569
+ `);
1570
+
1571
+ expect(res).toStrictEqual({
1572
+ data: {
1573
+ customPostsSingle: {
1574
+ id: 4,
1575
+ authorId: 5,
1576
+ content: '1MESSAGE',
1577
+ },
1578
+ },
1579
+ });
1580
+ });
1581
+
1582
+ it('Offset & limit', async () => {
1583
+ const res = await ctx.gql.queryGql(/* GraphQL */ `
1584
+ {
1585
+ customPosts(offset: 1, limit: 2) {
1586
+ id
1587
+ authorId
1588
+ content
1589
+ }
1590
+ }
1591
+ `);
1592
+
1593
+ expect(res).toStrictEqual({
1594
+ data: {
1595
+ customPosts: [
1596
+ {
1597
+ id: 2,
1598
+ authorId: 1,
1599
+ content: '2MESSAGE',
1600
+ },
1601
+ {
1602
+ id: 3,
1603
+ authorId: 1,
1604
+ content: '3MESSAGE',
1605
+ },
1606
+ ],
1607
+ },
1608
+ });
1609
+ });
1610
+
1611
+ it('Offset on single', async () => {
1612
+ const res = await ctx.gql.queryGql(/* GraphQL */ `
1613
+ {
1614
+ customPostsSingle(offset: 1) {
1615
+ id
1616
+ authorId
1617
+ content
1618
+ }
1619
+ }
1620
+ `);
1621
+
1622
+ expect(res).toStrictEqual({
1623
+ data: {
1624
+ customPostsSingle: {
1625
+ id: 2,
1626
+ authorId: 1,
1627
+ content: '2MESSAGE',
1628
+ },
1629
+ },
1630
+ });
1631
+ });
1632
+
1633
+ it('Filters - top level AND', async () => {
1634
+ const res = await ctx.gql.queryGql(/* GraphQL */ `
1635
+ {
1636
+ customPosts(where: { id: { inArray: [2, 3, 4, 5, 6] }, authorId: { ne: 5 }, content: { ne: "3MESSAGE" } }) {
1637
+ id
1638
+ authorId
1639
+ content
1640
+ }
1641
+ }
1642
+ `);
1643
+
1644
+ expect(res).toStrictEqual({
1645
+ data: {
1646
+ customPosts: [
1647
+ {
1648
+ id: 2,
1649
+ authorId: 1,
1650
+ content: '2MESSAGE',
1651
+ },
1652
+ {
1653
+ id: 6,
1654
+ authorId: 1,
1655
+ content: '4MESSAGE',
1656
+ },
1657
+ ],
1658
+ },
1659
+ });
1660
+ });
1661
+
1662
+ it('Filters - top level OR', async () => {
1663
+ const res = await ctx.gql.queryGql(/* GraphQL */ `
1664
+ {
1665
+ customPosts(where: { OR: [{ id: { lte: 3 } }, { authorId: { eq: 5 } }] }) {
1666
+ id
1667
+ authorId
1668
+ content
1669
+ }
1670
+ }
1671
+ `);
1672
+
1673
+ expect(res).toStrictEqual({
1674
+ data: {
1675
+ customPosts: [
1676
+ {
1677
+ id: 1,
1678
+ authorId: 1,
1679
+ content: '1MESSAGE',
1680
+ },
1681
+ {
1682
+ id: 2,
1683
+ authorId: 1,
1684
+ content: '2MESSAGE',
1685
+ },
1686
+ {
1687
+ id: 3,
1688
+ authorId: 1,
1689
+ content: '3MESSAGE',
1690
+ },
1691
+ {
1692
+ id: 4,
1693
+ authorId: 5,
1694
+ content: '1MESSAGE',
1695
+ },
1696
+ {
1697
+ id: 5,
1698
+ authorId: 5,
1699
+ content: '2MESSAGE',
1700
+ },
1701
+ ],
1702
+ },
1703
+ });
1704
+ });
1705
+
1706
+ it('Update filters', async () => {
1707
+ const res = await ctx.gql.queryGql(/* GraphQL */ `
1708
+ mutation {
1709
+ updateCustomPosts(where: { OR: [{ id: { lte: 3 } }, { authorId: { eq: 5 } }] }, set: { content: "UPDATED" }) {
1710
+ id
1711
+ authorId
1712
+ content
1713
+ }
1714
+ }
1715
+ `);
1716
+
1717
+ expect(res).toStrictEqual({
1718
+ data: {
1719
+ updateCustomPosts: [
1720
+ {
1721
+ id: 1,
1722
+ authorId: 1,
1723
+ content: 'UPDATED',
1724
+ },
1725
+ {
1726
+ id: 2,
1727
+ authorId: 1,
1728
+ content: 'UPDATED',
1729
+ },
1730
+ {
1731
+ id: 3,
1732
+ authorId: 1,
1733
+ content: 'UPDATED',
1734
+ },
1735
+ {
1736
+ id: 4,
1737
+ authorId: 5,
1738
+ content: 'UPDATED',
1739
+ },
1740
+ {
1741
+ id: 5,
1742
+ authorId: 5,
1743
+ content: 'UPDATED',
1744
+ },
1745
+ ],
1746
+ },
1747
+ });
1748
+ });
1749
+
1750
+ it('Delete filters', async () => {
1751
+ const res = await ctx.gql.queryGql(/* GraphQL */ `
1752
+ mutation {
1753
+ deleteFromCustomPosts(where: { OR: [{ id: { lte: 3 } }, { authorId: { eq: 5 } }] }) {
1754
+ id
1755
+ authorId
1756
+ content
1757
+ }
1758
+ }
1759
+ `);
1760
+
1761
+ expect(res).toStrictEqual({
1762
+ data: {
1763
+ deleteFromCustomPosts: [
1764
+ {
1765
+ id: 1,
1766
+ authorId: 1,
1767
+ content: '1MESSAGE',
1768
+ },
1769
+ {
1770
+ id: 2,
1771
+ authorId: 1,
1772
+ content: '2MESSAGE',
1773
+ },
1774
+ {
1775
+ id: 3,
1776
+ authorId: 1,
1777
+ content: '3MESSAGE',
1778
+ },
1779
+ {
1780
+ id: 4,
1781
+ authorId: 5,
1782
+ content: '1MESSAGE',
1783
+ },
1784
+ {
1785
+ id: 5,
1786
+ authorId: 5,
1787
+ content: '2MESSAGE',
1788
+ },
1789
+ ],
1790
+ },
1791
+ });
1792
+ });
1793
+
1794
+ it('Relations orderBy', async () => {
1795
+ const res = await ctx.gql.queryGql(/* GraphQL */ `
1796
+ {
1797
+ customUsers {
1798
+ id
1799
+ posts(orderBy: { id: { priority: 1, direction: desc } }) {
1800
+ id
1801
+ authorId
1802
+ content
1803
+ }
1804
+ }
1805
+ }
1806
+ `);
1807
+
1808
+ expect(res).toStrictEqual({
1809
+ data: {
1810
+ customUsers: [
1811
+ {
1812
+ id: 1,
1813
+ posts: [
1814
+ {
1815
+ id: 6,
1816
+ authorId: 1,
1817
+ content: '4MESSAGE',
1818
+ },
1819
+ {
1820
+ id: 3,
1821
+ authorId: 1,
1822
+ content: '3MESSAGE',
1823
+ },
1824
+ {
1825
+ id: 2,
1826
+ authorId: 1,
1827
+ content: '2MESSAGE',
1828
+ },
1829
+ {
1830
+ id: 1,
1831
+ authorId: 1,
1832
+ content: '1MESSAGE',
1833
+ },
1834
+ ],
1835
+ },
1836
+ {
1837
+ id: 2,
1838
+ posts: [],
1839
+ },
1840
+ {
1841
+ id: 5,
1842
+ posts: [
1843
+ {
1844
+ id: 5,
1845
+ authorId: 5,
1846
+ content: '2MESSAGE',
1847
+ },
1848
+ {
1849
+ id: 4,
1850
+ authorId: 5,
1851
+ content: '1MESSAGE',
1852
+ },
1853
+ ],
1854
+ },
1855
+ ],
1856
+ },
1857
+ });
1858
+ });
1859
+
1860
+ it('Relations offset & limit', async () => {
1861
+ const res = await ctx.gql.queryGql(/* GraphQL */ `
1862
+ {
1863
+ customUsers {
1864
+ id
1865
+ posts(offset: 1, limit: 2) {
1866
+ id
1867
+ authorId
1868
+ content
1869
+ }
1870
+ }
1871
+ }
1872
+ `);
1873
+
1874
+ expect(res).toStrictEqual({
1875
+ data: {
1876
+ customUsers: [
1877
+ {
1878
+ id: 1,
1879
+ posts: [
1880
+ {
1881
+ id: 2,
1882
+ authorId: 1,
1883
+ content: '2MESSAGE',
1884
+ },
1885
+ {
1886
+ id: 3,
1887
+ authorId: 1,
1888
+ content: '3MESSAGE',
1889
+ },
1890
+ ],
1891
+ },
1892
+ {
1893
+ id: 2,
1894
+ posts: [],
1895
+ },
1896
+ {
1897
+ id: 5,
1898
+ posts: [
1899
+ {
1900
+ id: 5,
1901
+ authorId: 5,
1902
+ content: '2MESSAGE',
1903
+ },
1904
+ ],
1905
+ },
1906
+ ],
1907
+ },
1908
+ });
1909
+ });
1910
+
1911
+ it('Relations filters', async () => {
1912
+ const res = await ctx.gql.queryGql(/* GraphQL */ `
1913
+ {
1914
+ customUsers {
1915
+ id
1916
+ posts(where: { content: { like: "2%" } }) {
1917
+ id
1918
+ authorId
1919
+ content
1920
+ }
1921
+ }
1922
+ }
1923
+ `);
1924
+
1925
+ expect(res).toStrictEqual({
1926
+ data: {
1927
+ customUsers: [
1928
+ {
1929
+ id: 1,
1930
+ posts: [
1931
+ {
1932
+ id: 2,
1933
+ authorId: 1,
1934
+ content: '2MESSAGE',
1935
+ },
1936
+ ],
1937
+ },
1938
+ {
1939
+ id: 2,
1940
+ posts: [],
1941
+ },
1942
+ {
1943
+ id: 5,
1944
+ posts: [
1945
+ {
1946
+ id: 5,
1947
+ authorId: 5,
1948
+ content: '2MESSAGE',
1949
+ },
1950
+ ],
1951
+ },
1952
+ ],
1953
+ },
1954
+ });
1955
+ });
1956
+ });