drizzle-graphql-plus 0.8.7 → 0.8.8

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,4600 @@
1
+ import {
2
+ buildSchema,
3
+ type DeleteResolver,
4
+ type ExtractTables,
5
+ type GeneratedEntities,
6
+ type InsertArrResolver,
7
+ type InsertResolver,
8
+ type SelectResolver,
9
+ type SelectSingleResolver,
10
+ type UpdateResolver,
11
+ } from '@/index';
12
+ import Docker from 'dockerode';
13
+ import { eq, inArray, type Relations, sql } from 'drizzle-orm';
14
+ import { drizzle, type MySql2Database } from 'drizzle-orm/mysql2';
15
+ import getPort from 'get-port';
16
+ import {
17
+ GraphQLInputObjectType,
18
+ GraphQLList,
19
+ GraphQLNonNull,
20
+ GraphQLObjectType,
21
+ GraphQLScalarType,
22
+ GraphQLSchema,
23
+ } from 'graphql';
24
+ import { createYoga } from 'graphql-yoga';
25
+ import { createServer, type Server } from 'http';
26
+ import * as mysql from 'mysql2/promise';
27
+ import { v4 as uuid } from 'uuid';
28
+ import { afterAll, afterEach, beforeAll, beforeEach, describe, expect, expectTypeOf, it } from 'vitest';
29
+ import z from 'zod';
30
+ import * as schema from './schema/mysql';
31
+ import { GraphQLClient } from './util/query';
32
+
33
+ interface Context {
34
+ docker: Docker;
35
+ mysqlContainer: Docker.Container;
36
+ db: MySql2Database<typeof schema>;
37
+ client: mysql.Connection;
38
+ schema: GraphQLSchema;
39
+ entities: GeneratedEntities<MySql2Database<typeof schema>>;
40
+ server: Server;
41
+ gql: GraphQLClient;
42
+ }
43
+
44
+ const ctx: Context = {} as any;
45
+
46
+ async function createDockerDB(): Promise<string> {
47
+ const docker = (ctx.docker = new Docker());
48
+ const port = await getPort({ port: 3306 });
49
+ const image = 'mysql:8';
50
+
51
+ const pullStream = await docker.pull(image);
52
+ await new Promise((resolve, reject) =>
53
+ docker.modem.followProgress(pullStream, (err) => (err ? reject(err) : resolve(err)))
54
+ );
55
+
56
+ ctx.mysqlContainer = await docker.createContainer({
57
+ Image: image,
58
+ Env: ['MYSQL_ROOT_PASSWORD=mysql', 'MYSQL_DATABASE=drizzle'],
59
+ name: `drizzle-graphql-mysql-tests-${uuid()}`,
60
+ HostConfig: {
61
+ AutoRemove: true,
62
+ PortBindings: {
63
+ '3306/tcp': [{ HostPort: `${port}` }],
64
+ },
65
+ },
66
+ });
67
+
68
+ await ctx.mysqlContainer.start();
69
+
70
+ return `mysql://root:mysql@127.0.0.1:${port}/drizzle`;
71
+ }
72
+
73
+ beforeAll(async (t) => {
74
+ const connectionString = await createDockerDB();
75
+
76
+ const sleep = 1000;
77
+ let timeLeft = 30000;
78
+ let connected = false;
79
+ let lastError: unknown | undefined;
80
+ do {
81
+ try {
82
+ ctx.client = await mysql.createConnection(connectionString);
83
+ await ctx.client.connect();
84
+ connected = true;
85
+ break;
86
+ } catch (e) {
87
+ lastError = e;
88
+ await new Promise((resolve) => setTimeout(resolve, sleep));
89
+ timeLeft -= sleep;
90
+ }
91
+ } while (timeLeft > 0);
92
+ if (!connected) {
93
+ console.error('Cannot connect to MySQL');
94
+ await ctx.client?.end().catch(console.error);
95
+ await ctx.mysqlContainer?.stop().catch(console.error);
96
+ throw lastError;
97
+ }
98
+
99
+ ctx.db = drizzle(ctx.client, {
100
+ schema,
101
+ logger: process.env['LOG_SQL'] ? true : false,
102
+ mode: 'default',
103
+ });
104
+
105
+ const { schema: gqlSchema, entities } = buildSchema(ctx.db);
106
+ const yoga = createYoga({
107
+ schema: gqlSchema,
108
+ });
109
+ const server = createServer(yoga);
110
+
111
+ const port = 4001;
112
+ server.listen(port);
113
+ const gql = new GraphQLClient(`http://localhost:${port}/graphql`);
114
+
115
+ ctx.schema = gqlSchema;
116
+ ctx.entities = entities;
117
+ ctx.server = server;
118
+ ctx.gql = gql;
119
+ });
120
+
121
+ afterAll(async (t) => {
122
+ await ctx.client?.end().catch(console.error);
123
+ await ctx.mysqlContainer?.stop().catch(console.error);
124
+ });
125
+
126
+ beforeEach(async (t) => {
127
+ await ctx.db.execute(sql`CREATE TABLE IF NOT EXISTS \`customers\` (
128
+ \`id\` int AUTO_INCREMENT NOT NULL,
129
+ \`address\` text NOT NULL,
130
+ \`is_confirmed\` boolean,
131
+ \`registration_date\` timestamp NOT NULL DEFAULT (now()),
132
+ \`user_id\` int NOT NULL,
133
+ CONSTRAINT \`customers_id\` PRIMARY KEY(\`id\`)
134
+ );`);
135
+
136
+ await ctx.db.execute(sql`CREATE TABLE IF NOT EXISTS \`posts\` (
137
+ \`id\` int AUTO_INCREMENT NOT NULL,
138
+ \`content\` text,
139
+ \`author_id\` int,
140
+ CONSTRAINT \`posts_id\` PRIMARY KEY(\`id\`)
141
+ );`);
142
+
143
+ await ctx.db.execute(sql`CREATE TABLE \`users\` (
144
+ \`id\` int AUTO_INCREMENT NOT NULL,
145
+ \`name\` text NOT NULL,
146
+ \`email\` text,
147
+ \`big_int\` bigint unsigned,
148
+ \`birthday_string\` date,
149
+ \`birthday_date\` date,
150
+ \`created_at\` timestamp NOT NULL DEFAULT (now()),
151
+ \`role\` enum('admin','user'),
152
+ \`role1\` text,
153
+ \`role2\` text DEFAULT ('user'),
154
+ \`profession\` varchar(20),
155
+ \`initials\` char(2),
156
+ \`is_confirmed\` boolean,
157
+ CONSTRAINT \`users_id\` PRIMARY KEY(\`id\`)
158
+ );`);
159
+
160
+ await ctx.db.execute(
161
+ sql`ALTER TABLE \`customers\` ADD CONSTRAINT \`customers_user_id_users_id_fk\` FOREIGN KEY (\`user_id\`) REFERENCES \`users\`(\`id\`) ON DELETE no action ON UPDATE no action;`,
162
+ );
163
+
164
+ await ctx.db.insert(schema.Users).values([
165
+ {
166
+ id: 1,
167
+ name: 'FirstUser',
168
+ email: 'userOne@notmail.com',
169
+ bigint: BigInt(10),
170
+ birthdayString: '2024-04-02',
171
+ birthdayDate: new Date('2024-04-02T06:44:41.785Z'),
172
+ createdAt: new Date('2024-04-02T06:44:41.785Z'),
173
+ role: 'admin',
174
+ roleText: null,
175
+ profession: 'FirstUserProf',
176
+ initials: 'FU',
177
+ isConfirmed: true,
178
+ },
179
+ {
180
+ id: 2,
181
+ name: 'SecondUser',
182
+ createdAt: new Date('2024-04-02T06:44:41.785Z'),
183
+ },
184
+ {
185
+ id: 5,
186
+ name: 'FifthUser',
187
+ createdAt: new Date('2024-04-02T06:44:41.785Z'),
188
+ },
189
+ ]);
190
+
191
+ await ctx.db.insert(schema.Posts).values([
192
+ {
193
+ id: 1,
194
+ authorId: 1,
195
+ content: '1MESSAGE',
196
+ },
197
+ {
198
+ id: 2,
199
+ authorId: 1,
200
+ content: '2MESSAGE',
201
+ },
202
+ {
203
+ id: 3,
204
+ authorId: 1,
205
+ content: '3MESSAGE',
206
+ },
207
+ {
208
+ id: 4,
209
+ authorId: 5,
210
+ content: '1MESSAGE',
211
+ },
212
+ {
213
+ id: 5,
214
+ authorId: 5,
215
+ content: '2MESSAGE',
216
+ },
217
+ {
218
+ id: 6,
219
+ authorId: 1,
220
+ content: '4MESSAGE',
221
+ },
222
+ ]);
223
+
224
+ await ctx.db.insert(schema.Customers).values([
225
+ {
226
+ id: 1,
227
+ address: 'AdOne',
228
+ isConfirmed: false,
229
+ registrationDate: new Date('2024-03-27T03:54:45.235Z'),
230
+ userId: 1,
231
+ },
232
+ {
233
+ id: 2,
234
+ address: 'AdTwo',
235
+ isConfirmed: false,
236
+ registrationDate: new Date('2024-03-27T03:55:42.358Z'),
237
+ userId: 2,
238
+ },
239
+ ]);
240
+ });
241
+
242
+ afterEach(async (t) => {
243
+ await ctx.db.execute(sql`SET FOREIGN_KEY_CHECKS = 0;`);
244
+ await ctx.db.execute(sql`DROP TABLE IF EXISTS \`customers\` CASCADE;`);
245
+ await ctx.db.execute(sql`DROP TABLE IF EXISTS \`posts\` CASCADE;`);
246
+ await ctx.db.execute(sql`DROP TABLE IF EXISTS \`users\` CASCADE;`);
247
+ await ctx.db.execute(sql`SET FOREIGN_KEY_CHECKS = 1;`);
248
+ });
249
+
250
+ describe.sequential('Query tests', async () => {
251
+ it(`Select single`, async () => {
252
+ const res = await ctx.gql.queryGql(/* GraphQL */ `
253
+ {
254
+ usersSingle {
255
+ id
256
+ name
257
+ email
258
+ bigint
259
+ birthdayString
260
+ birthdayDate
261
+ createdAt
262
+ role
263
+ roleText
264
+ roleText2
265
+ profession
266
+ initials
267
+ isConfirmed
268
+ }
269
+
270
+ postsSingle {
271
+ id
272
+ authorId
273
+ content
274
+ }
275
+ }
276
+ `);
277
+
278
+ expect(res).toStrictEqual({
279
+ data: {
280
+ usersSingle: {
281
+ id: 1,
282
+ name: 'FirstUser',
283
+ email: 'userOne@notmail.com',
284
+ bigint: '10',
285
+ birthdayString: '2024-04-02',
286
+ birthdayDate: '2024-04-02T00:00:00.000Z',
287
+ createdAt: '2024-04-02T06:44:42.000Z',
288
+ role: 'admin',
289
+ roleText: null,
290
+ roleText2: 'user',
291
+ profession: 'FirstUserProf',
292
+ initials: 'FU',
293
+ isConfirmed: true,
294
+ },
295
+ postsSingle: {
296
+ id: 1,
297
+ authorId: 1,
298
+ content: '1MESSAGE',
299
+ },
300
+ },
301
+ });
302
+ });
303
+
304
+ it(`Select array`, async () => {
305
+ const res = await ctx.gql.queryGql(/* GraphQL */ `
306
+ {
307
+ users {
308
+ id
309
+ name
310
+ email
311
+ bigint
312
+ birthdayString
313
+ birthdayDate
314
+ createdAt
315
+ role
316
+ roleText
317
+ roleText2
318
+ profession
319
+ initials
320
+ isConfirmed
321
+ }
322
+
323
+ posts {
324
+ id
325
+ authorId
326
+ content
327
+ }
328
+ }
329
+ `);
330
+
331
+ expect(res).toStrictEqual({
332
+ data: {
333
+ users: [
334
+ {
335
+ id: 1,
336
+ name: 'FirstUser',
337
+ email: 'userOne@notmail.com',
338
+ bigint: '10',
339
+ birthdayString: '2024-04-02',
340
+ birthdayDate: '2024-04-02T00:00:00.000Z',
341
+ createdAt: '2024-04-02T06:44:42.000Z',
342
+ role: 'admin',
343
+ roleText: null,
344
+ roleText2: 'user',
345
+ profession: 'FirstUserProf',
346
+ initials: 'FU',
347
+ isConfirmed: true,
348
+ },
349
+ {
350
+ id: 2,
351
+ name: 'SecondUser',
352
+ email: null,
353
+ bigint: null,
354
+ birthdayString: null,
355
+ birthdayDate: null,
356
+ createdAt: '2024-04-02T06:44:42.000Z',
357
+ role: null,
358
+ roleText: null,
359
+ roleText2: 'user',
360
+ profession: null,
361
+ initials: null,
362
+ isConfirmed: null,
363
+ },
364
+ {
365
+ id: 5,
366
+ name: 'FifthUser',
367
+ email: null,
368
+ bigint: null,
369
+ birthdayString: null,
370
+ birthdayDate: null,
371
+ createdAt: '2024-04-02T06:44:42.000Z',
372
+ role: null,
373
+ roleText: null,
374
+ roleText2: 'user',
375
+ profession: null,
376
+ initials: null,
377
+ isConfirmed: null,
378
+ },
379
+ ],
380
+ posts: [
381
+ {
382
+ id: 1,
383
+ authorId: 1,
384
+ content: '1MESSAGE',
385
+ },
386
+ {
387
+ id: 2,
388
+ authorId: 1,
389
+ content: '2MESSAGE',
390
+ },
391
+ {
392
+ id: 3,
393
+ authorId: 1,
394
+ content: '3MESSAGE',
395
+ },
396
+ {
397
+ id: 4,
398
+ authorId: 5,
399
+ content: '1MESSAGE',
400
+ },
401
+ {
402
+ id: 5,
403
+ authorId: 5,
404
+ content: '2MESSAGE',
405
+ },
406
+ {
407
+ id: 6,
408
+ authorId: 1,
409
+ content: '4MESSAGE',
410
+ },
411
+ ],
412
+ },
413
+ });
414
+ });
415
+
416
+ it(`Select single with relations`, async () => {
417
+ const res = await ctx.gql.queryGql(/* GraphQL */ `
418
+ {
419
+ usersSingle {
420
+ id
421
+ name
422
+ email
423
+ bigint
424
+ birthdayString
425
+ birthdayDate
426
+ createdAt
427
+ role
428
+ roleText
429
+ roleText2
430
+ profession
431
+ initials
432
+ isConfirmed
433
+ posts {
434
+ id
435
+ authorId
436
+ content
437
+ }
438
+ }
439
+
440
+ postsSingle {
441
+ id
442
+ authorId
443
+ content
444
+ author {
445
+ id
446
+ name
447
+ email
448
+ bigint
449
+ birthdayString
450
+ birthdayDate
451
+ createdAt
452
+ role
453
+ roleText
454
+ roleText2
455
+ profession
456
+ initials
457
+ isConfirmed
458
+ }
459
+ }
460
+ }
461
+ `);
462
+
463
+ expect(res).toStrictEqual({
464
+ data: {
465
+ usersSingle: {
466
+ id: 1,
467
+ name: 'FirstUser',
468
+ email: 'userOne@notmail.com',
469
+ bigint: '10',
470
+ birthdayString: '2024-04-02',
471
+ birthdayDate: '2024-04-02T00:00:00.000Z',
472
+ createdAt: '2024-04-02T06:44:42.000Z',
473
+ role: 'admin',
474
+ roleText: null,
475
+ roleText2: 'user',
476
+ profession: 'FirstUserProf',
477
+ initials: 'FU',
478
+ isConfirmed: true,
479
+ posts: [
480
+ {
481
+ id: 1,
482
+ authorId: 1,
483
+ content: '1MESSAGE',
484
+ },
485
+ {
486
+ id: 2,
487
+ authorId: 1,
488
+ content: '2MESSAGE',
489
+ },
490
+ {
491
+ id: 3,
492
+ authorId: 1,
493
+ content: '3MESSAGE',
494
+ },
495
+
496
+ {
497
+ id: 6,
498
+ authorId: 1,
499
+ content: '4MESSAGE',
500
+ },
501
+ ],
502
+ },
503
+ postsSingle: {
504
+ id: 1,
505
+ authorId: 1,
506
+ content: '1MESSAGE',
507
+ author: {
508
+ id: 1,
509
+ name: 'FirstUser',
510
+ email: 'userOne@notmail.com',
511
+ bigint: '10',
512
+ birthdayString: '2024-04-02',
513
+ birthdayDate: '2024-04-02T00:00:00.000Z',
514
+ createdAt: '2024-04-02T06:44:42.000Z',
515
+ role: 'admin',
516
+ roleText: null,
517
+ roleText2: 'user',
518
+ profession: 'FirstUserProf',
519
+ initials: 'FU',
520
+ isConfirmed: true,
521
+ },
522
+ },
523
+ },
524
+ });
525
+ });
526
+
527
+ it(`Select array with relations`, async () => {
528
+ const res = await ctx.gql.queryGql(/* GraphQL */ `
529
+ {
530
+ users {
531
+ id
532
+ name
533
+ email
534
+ bigint
535
+ birthdayString
536
+ birthdayDate
537
+ createdAt
538
+ role
539
+ roleText
540
+ roleText2
541
+ profession
542
+ initials
543
+ isConfirmed
544
+ posts {
545
+ id
546
+ authorId
547
+ content
548
+ }
549
+ }
550
+
551
+ posts {
552
+ id
553
+ authorId
554
+ content
555
+ author {
556
+ id
557
+ name
558
+ email
559
+ bigint
560
+ birthdayString
561
+ birthdayDate
562
+ createdAt
563
+ role
564
+ roleText
565
+ roleText2
566
+ profession
567
+ initials
568
+ isConfirmed
569
+ }
570
+ }
571
+ }
572
+ `);
573
+
574
+ expect(res).toStrictEqual({
575
+ data: {
576
+ users: [
577
+ {
578
+ id: 1,
579
+ name: 'FirstUser',
580
+ email: 'userOne@notmail.com',
581
+ bigint: '10',
582
+ birthdayString: '2024-04-02',
583
+ birthdayDate: '2024-04-02T00:00:00.000Z',
584
+ createdAt: '2024-04-02T06:44:42.000Z',
585
+ role: 'admin',
586
+ roleText: null,
587
+ roleText2: 'user',
588
+ profession: 'FirstUserProf',
589
+ initials: 'FU',
590
+ isConfirmed: true,
591
+ posts: [
592
+ {
593
+ id: 1,
594
+ authorId: 1,
595
+ content: '1MESSAGE',
596
+ },
597
+ {
598
+ id: 2,
599
+ authorId: 1,
600
+ content: '2MESSAGE',
601
+ },
602
+ {
603
+ id: 3,
604
+ authorId: 1,
605
+ content: '3MESSAGE',
606
+ },
607
+ {
608
+ id: 6,
609
+ authorId: 1,
610
+ content: '4MESSAGE',
611
+ },
612
+ ],
613
+ },
614
+ {
615
+ id: 2,
616
+ name: 'SecondUser',
617
+ email: null,
618
+ bigint: null,
619
+ birthdayString: null,
620
+ birthdayDate: null,
621
+ createdAt: '2024-04-02T06:44:42.000Z',
622
+ role: null,
623
+ roleText: null,
624
+ roleText2: 'user',
625
+ profession: null,
626
+ initials: null,
627
+ isConfirmed: null,
628
+ posts: [],
629
+ },
630
+ {
631
+ id: 5,
632
+ name: 'FifthUser',
633
+ email: null,
634
+ bigint: null,
635
+ birthdayString: null,
636
+ birthdayDate: null,
637
+ createdAt: '2024-04-02T06:44:42.000Z',
638
+ role: null,
639
+ roleText: null,
640
+ roleText2: 'user',
641
+ profession: null,
642
+ initials: null,
643
+ isConfirmed: null,
644
+ posts: [
645
+ {
646
+ id: 4,
647
+ authorId: 5,
648
+ content: '1MESSAGE',
649
+ },
650
+ {
651
+ id: 5,
652
+ authorId: 5,
653
+ content: '2MESSAGE',
654
+ },
655
+ ],
656
+ },
657
+ ],
658
+ posts: [
659
+ {
660
+ id: 1,
661
+ authorId: 1,
662
+ content: '1MESSAGE',
663
+ author: {
664
+ id: 1,
665
+ name: 'FirstUser',
666
+ email: 'userOne@notmail.com',
667
+ bigint: '10',
668
+ birthdayString: '2024-04-02',
669
+ birthdayDate: '2024-04-02T00:00:00.000Z',
670
+ createdAt: '2024-04-02T06:44:42.000Z',
671
+ role: 'admin',
672
+ roleText: null,
673
+ roleText2: 'user',
674
+ profession: 'FirstUserProf',
675
+ initials: 'FU',
676
+ isConfirmed: true,
677
+ },
678
+ },
679
+ {
680
+ id: 2,
681
+ authorId: 1,
682
+ content: '2MESSAGE',
683
+ author: {
684
+ id: 1,
685
+ name: 'FirstUser',
686
+ email: 'userOne@notmail.com',
687
+ bigint: '10',
688
+ birthdayString: '2024-04-02',
689
+ birthdayDate: '2024-04-02T00:00:00.000Z',
690
+ createdAt: '2024-04-02T06:44:42.000Z',
691
+ role: 'admin',
692
+ roleText: null,
693
+ roleText2: 'user',
694
+ profession: 'FirstUserProf',
695
+ initials: 'FU',
696
+ isConfirmed: true,
697
+ },
698
+ },
699
+ {
700
+ id: 3,
701
+ authorId: 1,
702
+ content: '3MESSAGE',
703
+ author: {
704
+ id: 1,
705
+ name: 'FirstUser',
706
+ email: 'userOne@notmail.com',
707
+ bigint: '10',
708
+ birthdayString: '2024-04-02',
709
+ birthdayDate: '2024-04-02T00:00:00.000Z',
710
+ createdAt: '2024-04-02T06:44:42.000Z',
711
+ role: 'admin',
712
+ roleText: null,
713
+ roleText2: 'user',
714
+ profession: 'FirstUserProf',
715
+ initials: 'FU',
716
+ isConfirmed: true,
717
+ },
718
+ },
719
+ {
720
+ id: 4,
721
+ authorId: 5,
722
+ content: '1MESSAGE',
723
+ author: {
724
+ id: 5,
725
+ name: 'FifthUser',
726
+ email: null,
727
+ bigint: null,
728
+ birthdayString: null,
729
+ birthdayDate: null,
730
+ createdAt: '2024-04-02T06:44:42.000Z',
731
+ role: null,
732
+ roleText: null,
733
+ roleText2: 'user',
734
+ profession: null,
735
+ initials: null,
736
+ isConfirmed: null,
737
+ },
738
+ },
739
+ {
740
+ id: 5,
741
+ authorId: 5,
742
+ content: '2MESSAGE',
743
+ author: {
744
+ id: 5,
745
+ name: 'FifthUser',
746
+ email: null,
747
+ bigint: null,
748
+ birthdayString: null,
749
+ birthdayDate: null,
750
+ createdAt: '2024-04-02T06:44:42.000Z',
751
+ role: null,
752
+ roleText: null,
753
+ roleText2: 'user',
754
+ profession: null,
755
+ initials: null,
756
+ isConfirmed: null,
757
+ },
758
+ },
759
+ {
760
+ id: 6,
761
+ authorId: 1,
762
+ content: '4MESSAGE',
763
+ author: {
764
+ id: 1,
765
+ name: 'FirstUser',
766
+ email: 'userOne@notmail.com',
767
+ bigint: '10',
768
+ birthdayString: '2024-04-02',
769
+ birthdayDate: '2024-04-02T00:00:00.000Z',
770
+ createdAt: '2024-04-02T06:44:42.000Z',
771
+ role: 'admin',
772
+ roleText: null,
773
+ roleText2: 'user',
774
+ profession: 'FirstUserProf',
775
+ initials: 'FU',
776
+ isConfirmed: true,
777
+ },
778
+ },
779
+ ],
780
+ },
781
+ });
782
+ });
783
+
784
+ it(`Select single by fragment`, async () => {
785
+ const res = await ctx.gql.queryGql(/* GraphQL */ `
786
+ query testQuery {
787
+ usersSingle {
788
+ ...UsersFrag
789
+ }
790
+
791
+ postsSingle {
792
+ ...PostsFrag
793
+ }
794
+ }
795
+
796
+ fragment UsersFrag on UsersSelectItem {
797
+ id
798
+ name
799
+ email
800
+ bigint
801
+ birthdayString
802
+ birthdayDate
803
+ createdAt
804
+ role
805
+ roleText
806
+ roleText2
807
+ profession
808
+ initials
809
+ isConfirmed
810
+ }
811
+
812
+ fragment PostsFrag on PostsSelectItem {
813
+ id
814
+ authorId
815
+ content
816
+ }
817
+ `);
818
+
819
+ expect(res).toStrictEqual({
820
+ data: {
821
+ usersSingle: {
822
+ id: 1,
823
+ name: 'FirstUser',
824
+ email: 'userOne@notmail.com',
825
+ bigint: '10',
826
+ birthdayString: '2024-04-02',
827
+ birthdayDate: '2024-04-02T00:00:00.000Z',
828
+ createdAt: '2024-04-02T06:44:42.000Z',
829
+ role: 'admin',
830
+ roleText: null,
831
+ roleText2: 'user',
832
+ profession: 'FirstUserProf',
833
+ initials: 'FU',
834
+ isConfirmed: true,
835
+ },
836
+ postsSingle: {
837
+ id: 1,
838
+ authorId: 1,
839
+ content: '1MESSAGE',
840
+ },
841
+ },
842
+ });
843
+ });
844
+
845
+ it(`Select array by fragment`, async () => {
846
+ const res = await ctx.gql.queryGql(/* GraphQL */ `
847
+ query testQuery {
848
+ users {
849
+ ...UsersFrag
850
+ }
851
+
852
+ posts {
853
+ ...PostsFrag
854
+ }
855
+ }
856
+
857
+ fragment UsersFrag on UsersSelectItem {
858
+ id
859
+ name
860
+ email
861
+ bigint
862
+ birthdayString
863
+ birthdayDate
864
+ createdAt
865
+ role
866
+ roleText
867
+ roleText2
868
+ profession
869
+ initials
870
+ isConfirmed
871
+ }
872
+
873
+ fragment PostsFrag on PostsSelectItem {
874
+ id
875
+ authorId
876
+ content
877
+ }
878
+ `);
879
+
880
+ expect(res).toStrictEqual({
881
+ data: {
882
+ users: [
883
+ {
884
+ id: 1,
885
+ name: 'FirstUser',
886
+ email: 'userOne@notmail.com',
887
+ bigint: '10',
888
+ birthdayString: '2024-04-02',
889
+ birthdayDate: '2024-04-02T00:00:00.000Z',
890
+ createdAt: '2024-04-02T06:44:42.000Z',
891
+ role: 'admin',
892
+ roleText: null,
893
+ roleText2: 'user',
894
+ profession: 'FirstUserProf',
895
+ initials: 'FU',
896
+ isConfirmed: true,
897
+ },
898
+ {
899
+ id: 2,
900
+ name: 'SecondUser',
901
+ email: null,
902
+ bigint: null,
903
+ birthdayString: null,
904
+ birthdayDate: null,
905
+ createdAt: '2024-04-02T06:44:42.000Z',
906
+ role: null,
907
+ roleText: null,
908
+ roleText2: 'user',
909
+ profession: null,
910
+ initials: null,
911
+ isConfirmed: null,
912
+ },
913
+ {
914
+ id: 5,
915
+ name: 'FifthUser',
916
+ email: null,
917
+ bigint: null,
918
+ birthdayString: null,
919
+ birthdayDate: null,
920
+ createdAt: '2024-04-02T06:44:42.000Z',
921
+ role: null,
922
+ roleText: null,
923
+ roleText2: 'user',
924
+ profession: null,
925
+ initials: null,
926
+ isConfirmed: null,
927
+ },
928
+ ],
929
+ posts: [
930
+ {
931
+ id: 1,
932
+ authorId: 1,
933
+ content: '1MESSAGE',
934
+ },
935
+ {
936
+ id: 2,
937
+ authorId: 1,
938
+ content: '2MESSAGE',
939
+ },
940
+ {
941
+ id: 3,
942
+ authorId: 1,
943
+ content: '3MESSAGE',
944
+ },
945
+ {
946
+ id: 4,
947
+ authorId: 5,
948
+ content: '1MESSAGE',
949
+ },
950
+ {
951
+ id: 5,
952
+ authorId: 5,
953
+ content: '2MESSAGE',
954
+ },
955
+ {
956
+ id: 6,
957
+ authorId: 1,
958
+ content: '4MESSAGE',
959
+ },
960
+ ],
961
+ },
962
+ });
963
+ });
964
+
965
+ it(`Select single with relations by fragment`, async () => {
966
+ const res = await ctx.gql.queryGql(/* GraphQL */ `
967
+ query testQuery {
968
+ usersSingle {
969
+ ...UsersFrag
970
+ }
971
+
972
+ postsSingle {
973
+ ...PostsFrag
974
+ }
975
+ }
976
+
977
+ fragment UsersFrag on UsersSelectItem {
978
+ id
979
+ name
980
+ email
981
+ bigint
982
+ birthdayString
983
+ birthdayDate
984
+ createdAt
985
+ role
986
+ roleText
987
+ roleText2
988
+ profession
989
+ initials
990
+ isConfirmed
991
+ posts {
992
+ id
993
+ authorId
994
+ content
995
+ }
996
+ }
997
+
998
+ fragment PostsFrag on PostsSelectItem {
999
+ id
1000
+ authorId
1001
+ content
1002
+ author {
1003
+ id
1004
+ name
1005
+ email
1006
+ bigint
1007
+ birthdayString
1008
+ birthdayDate
1009
+ createdAt
1010
+ role
1011
+ roleText
1012
+ roleText2
1013
+ profession
1014
+ initials
1015
+ isConfirmed
1016
+ }
1017
+ }
1018
+ `);
1019
+
1020
+ expect(res).toStrictEqual({
1021
+ data: {
1022
+ usersSingle: {
1023
+ id: 1,
1024
+ name: 'FirstUser',
1025
+ email: 'userOne@notmail.com',
1026
+ bigint: '10',
1027
+ birthdayString: '2024-04-02',
1028
+ birthdayDate: '2024-04-02T00:00:00.000Z',
1029
+ createdAt: '2024-04-02T06:44:42.000Z',
1030
+ role: 'admin',
1031
+ roleText: null,
1032
+ roleText2: 'user',
1033
+ profession: 'FirstUserProf',
1034
+ initials: 'FU',
1035
+ isConfirmed: true,
1036
+ posts: [
1037
+ {
1038
+ id: 1,
1039
+ authorId: 1,
1040
+ content: '1MESSAGE',
1041
+ },
1042
+ {
1043
+ id: 2,
1044
+ authorId: 1,
1045
+ content: '2MESSAGE',
1046
+ },
1047
+ {
1048
+ id: 3,
1049
+ authorId: 1,
1050
+ content: '3MESSAGE',
1051
+ },
1052
+
1053
+ {
1054
+ id: 6,
1055
+ authorId: 1,
1056
+ content: '4MESSAGE',
1057
+ },
1058
+ ],
1059
+ },
1060
+ postsSingle: {
1061
+ id: 1,
1062
+ authorId: 1,
1063
+ content: '1MESSAGE',
1064
+ author: {
1065
+ id: 1,
1066
+ name: 'FirstUser',
1067
+ email: 'userOne@notmail.com',
1068
+ bigint: '10',
1069
+ birthdayString: '2024-04-02',
1070
+ birthdayDate: '2024-04-02T00:00:00.000Z',
1071
+ createdAt: '2024-04-02T06:44:42.000Z',
1072
+ role: 'admin',
1073
+ roleText: null,
1074
+ roleText2: 'user',
1075
+ profession: 'FirstUserProf',
1076
+ initials: 'FU',
1077
+ isConfirmed: true,
1078
+ },
1079
+ },
1080
+ },
1081
+ });
1082
+ });
1083
+
1084
+ it(`Select array with relations by fragment`, async () => {
1085
+ const res = await ctx.gql.queryGql(/* GraphQL */ `
1086
+ query testQuery {
1087
+ users {
1088
+ ...UsersFrag
1089
+ }
1090
+
1091
+ posts {
1092
+ ...PostsFrag
1093
+ }
1094
+ }
1095
+
1096
+ fragment UsersFrag on UsersSelectItem {
1097
+ id
1098
+ name
1099
+ email
1100
+ bigint
1101
+ birthdayString
1102
+ birthdayDate
1103
+ createdAt
1104
+ role
1105
+ roleText
1106
+ roleText2
1107
+ profession
1108
+ initials
1109
+ isConfirmed
1110
+ posts {
1111
+ id
1112
+ authorId
1113
+ content
1114
+ }
1115
+ }
1116
+
1117
+ fragment PostsFrag on PostsSelectItem {
1118
+ id
1119
+ authorId
1120
+ content
1121
+ author {
1122
+ id
1123
+ name
1124
+ email
1125
+ bigint
1126
+ birthdayString
1127
+ birthdayDate
1128
+ createdAt
1129
+ role
1130
+ roleText
1131
+ roleText2
1132
+ profession
1133
+ initials
1134
+ isConfirmed
1135
+ }
1136
+ }
1137
+ `);
1138
+
1139
+ expect(res).toStrictEqual({
1140
+ data: {
1141
+ users: [
1142
+ {
1143
+ id: 1,
1144
+ name: 'FirstUser',
1145
+ email: 'userOne@notmail.com',
1146
+ bigint: '10',
1147
+ birthdayString: '2024-04-02',
1148
+ birthdayDate: '2024-04-02T00:00:00.000Z',
1149
+ createdAt: '2024-04-02T06:44:42.000Z',
1150
+ role: 'admin',
1151
+ roleText: null,
1152
+ roleText2: 'user',
1153
+ profession: 'FirstUserProf',
1154
+ initials: 'FU',
1155
+ isConfirmed: true,
1156
+ posts: [
1157
+ {
1158
+ id: 1,
1159
+ authorId: 1,
1160
+ content: '1MESSAGE',
1161
+ },
1162
+ {
1163
+ id: 2,
1164
+ authorId: 1,
1165
+ content: '2MESSAGE',
1166
+ },
1167
+ {
1168
+ id: 3,
1169
+ authorId: 1,
1170
+ content: '3MESSAGE',
1171
+ },
1172
+ {
1173
+ id: 6,
1174
+ authorId: 1,
1175
+ content: '4MESSAGE',
1176
+ },
1177
+ ],
1178
+ },
1179
+ {
1180
+ id: 2,
1181
+ name: 'SecondUser',
1182
+ email: null,
1183
+ bigint: null,
1184
+ birthdayString: null,
1185
+ birthdayDate: null,
1186
+ createdAt: '2024-04-02T06:44:42.000Z',
1187
+ role: null,
1188
+ roleText: null,
1189
+ roleText2: 'user',
1190
+ profession: null,
1191
+ initials: null,
1192
+ isConfirmed: null,
1193
+ posts: [],
1194
+ },
1195
+ {
1196
+ id: 5,
1197
+ name: 'FifthUser',
1198
+ email: null,
1199
+ bigint: null,
1200
+ birthdayString: null,
1201
+ birthdayDate: null,
1202
+ createdAt: '2024-04-02T06:44:42.000Z',
1203
+ role: null,
1204
+ roleText: null,
1205
+ roleText2: 'user',
1206
+ profession: null,
1207
+ initials: null,
1208
+ isConfirmed: null,
1209
+ posts: [
1210
+ {
1211
+ id: 4,
1212
+ authorId: 5,
1213
+ content: '1MESSAGE',
1214
+ },
1215
+ {
1216
+ id: 5,
1217
+ authorId: 5,
1218
+ content: '2MESSAGE',
1219
+ },
1220
+ ],
1221
+ },
1222
+ ],
1223
+ posts: [
1224
+ {
1225
+ id: 1,
1226
+ authorId: 1,
1227
+ content: '1MESSAGE',
1228
+ author: {
1229
+ id: 1,
1230
+ name: 'FirstUser',
1231
+ email: 'userOne@notmail.com',
1232
+ bigint: '10',
1233
+ birthdayString: '2024-04-02',
1234
+ birthdayDate: '2024-04-02T00:00:00.000Z',
1235
+ createdAt: '2024-04-02T06:44:42.000Z',
1236
+ role: 'admin',
1237
+ roleText: null,
1238
+ roleText2: 'user',
1239
+ profession: 'FirstUserProf',
1240
+ initials: 'FU',
1241
+ isConfirmed: true,
1242
+ },
1243
+ },
1244
+ {
1245
+ id: 2,
1246
+ authorId: 1,
1247
+ content: '2MESSAGE',
1248
+ author: {
1249
+ id: 1,
1250
+ name: 'FirstUser',
1251
+ email: 'userOne@notmail.com',
1252
+ bigint: '10',
1253
+ birthdayString: '2024-04-02',
1254
+ birthdayDate: '2024-04-02T00:00:00.000Z',
1255
+ createdAt: '2024-04-02T06:44:42.000Z',
1256
+ role: 'admin',
1257
+ roleText: null,
1258
+ roleText2: 'user',
1259
+ profession: 'FirstUserProf',
1260
+ initials: 'FU',
1261
+ isConfirmed: true,
1262
+ },
1263
+ },
1264
+ {
1265
+ id: 3,
1266
+ authorId: 1,
1267
+ content: '3MESSAGE',
1268
+ author: {
1269
+ id: 1,
1270
+ name: 'FirstUser',
1271
+ email: 'userOne@notmail.com',
1272
+ bigint: '10',
1273
+ birthdayString: '2024-04-02',
1274
+ birthdayDate: '2024-04-02T00:00:00.000Z',
1275
+ createdAt: '2024-04-02T06:44:42.000Z',
1276
+ role: 'admin',
1277
+ roleText: null,
1278
+ roleText2: 'user',
1279
+ profession: 'FirstUserProf',
1280
+ initials: 'FU',
1281
+ isConfirmed: true,
1282
+ },
1283
+ },
1284
+ {
1285
+ id: 4,
1286
+ authorId: 5,
1287
+ content: '1MESSAGE',
1288
+ author: {
1289
+ id: 5,
1290
+ name: 'FifthUser',
1291
+ email: null,
1292
+ bigint: null,
1293
+ birthdayString: null,
1294
+ birthdayDate: null,
1295
+ createdAt: '2024-04-02T06:44:42.000Z',
1296
+ role: null,
1297
+ roleText: null,
1298
+ roleText2: 'user',
1299
+ profession: null,
1300
+ initials: null,
1301
+ isConfirmed: null,
1302
+ },
1303
+ },
1304
+ {
1305
+ id: 5,
1306
+ authorId: 5,
1307
+ content: '2MESSAGE',
1308
+ author: {
1309
+ id: 5,
1310
+ name: 'FifthUser',
1311
+ email: null,
1312
+ bigint: null,
1313
+ birthdayString: null,
1314
+ birthdayDate: null,
1315
+ createdAt: '2024-04-02T06:44:42.000Z',
1316
+ role: null,
1317
+ roleText: null,
1318
+ roleText2: 'user',
1319
+ profession: null,
1320
+ initials: null,
1321
+ isConfirmed: null,
1322
+ },
1323
+ },
1324
+ {
1325
+ id: 6,
1326
+ authorId: 1,
1327
+ content: '4MESSAGE',
1328
+ author: {
1329
+ id: 1,
1330
+ name: 'FirstUser',
1331
+ email: 'userOne@notmail.com',
1332
+ bigint: '10',
1333
+ birthdayString: '2024-04-02',
1334
+ birthdayDate: '2024-04-02T00:00:00.000Z',
1335
+ createdAt: '2024-04-02T06:44:42.000Z',
1336
+ role: 'admin',
1337
+ roleText: null,
1338
+ roleText2: 'user',
1339
+ profession: 'FirstUserProf',
1340
+ initials: 'FU',
1341
+ isConfirmed: true,
1342
+ },
1343
+ },
1344
+ ],
1345
+ },
1346
+ });
1347
+ });
1348
+
1349
+ it(`Insert single`, async () => {
1350
+ const res = await ctx.gql.queryGql(/* GraphQL */ `
1351
+ mutation {
1352
+ insertIntoUsersSingle(
1353
+ values: {
1354
+ id: 3
1355
+ name: "ThirdUser"
1356
+ email: "userThree@notmail.com"
1357
+ bigint: "15"
1358
+ birthdayString: "2024-04-02"
1359
+ birthdayDate: "2024-04-02T06:44:41.785Z"
1360
+ createdAt: "2024-04-02T06:44:41.785Z"
1361
+ role: admin
1362
+ roleText: null
1363
+ profession: "ThirdUserProf"
1364
+ initials: "FU"
1365
+ isConfirmed: true
1366
+ }
1367
+ ) {
1368
+ isSuccess
1369
+ }
1370
+ }
1371
+ `);
1372
+
1373
+ expect(res).toStrictEqual({
1374
+ data: {
1375
+ insertIntoUsersSingle: {
1376
+ isSuccess: true,
1377
+ },
1378
+ },
1379
+ });
1380
+
1381
+ const data = await ctx.db.select().from(schema.Users).where(eq(schema.Users.id, 3));
1382
+
1383
+ expect(data).toStrictEqual([
1384
+ {
1385
+ id: 3,
1386
+ name: 'ThirdUser',
1387
+ email: 'userThree@notmail.com',
1388
+ bigint: BigInt(15),
1389
+ birthdayString: '2024-04-02',
1390
+ birthdayDate: new Date('2024-04-02T00:00:00.000Z'),
1391
+ createdAt: new Date('2024-04-02T06:44:42.000Z'),
1392
+ role: 'admin',
1393
+ roleText: null,
1394
+ roleText2: 'user',
1395
+ profession: 'ThirdUserProf',
1396
+ initials: 'FU',
1397
+ isConfirmed: true,
1398
+ },
1399
+ ]);
1400
+ });
1401
+
1402
+ it(`Insert array`, async () => {
1403
+ const res = await ctx.gql.queryGql(/* GraphQL */ `
1404
+ mutation {
1405
+ insertIntoUsers(
1406
+ values: [
1407
+ {
1408
+ id: 3
1409
+ name: "ThirdUser"
1410
+ email: "userThree@notmail.com"
1411
+ bigint: "15"
1412
+ birthdayString: "2024-04-02"
1413
+ birthdayDate: "2024-04-02T06:44:41.785Z"
1414
+ createdAt: "2024-04-02T06:44:41.785Z"
1415
+ role: admin
1416
+ roleText: null
1417
+ profession: "ThirdUserProf"
1418
+ initials: "FU"
1419
+ isConfirmed: true
1420
+ }
1421
+ {
1422
+ id: 4
1423
+ name: "FourthUser"
1424
+ email: "userFour@notmail.com"
1425
+ bigint: "42"
1426
+ birthdayString: "2024-04-04"
1427
+ birthdayDate: "2024-04-04T00:00:00.000Z"
1428
+ createdAt: "2024-04-04T06:44:41.785Z"
1429
+ role: user
1430
+ roleText: null
1431
+ roleText2: user
1432
+ profession: "FourthUserProf"
1433
+ initials: "SU"
1434
+ isConfirmed: false
1435
+ }
1436
+ ]
1437
+ ) {
1438
+ isSuccess
1439
+ }
1440
+ }
1441
+ `);
1442
+
1443
+ expect(res).toStrictEqual({
1444
+ data: {
1445
+ insertIntoUsers: {
1446
+ isSuccess: true,
1447
+ },
1448
+ },
1449
+ });
1450
+
1451
+ const data = await ctx.db
1452
+ .select()
1453
+ .from(schema.Users)
1454
+ .where(inArray(schema.Users.id, [3, 4]));
1455
+
1456
+ expect(data).toStrictEqual([
1457
+ {
1458
+ id: 3,
1459
+ name: 'ThirdUser',
1460
+ email: 'userThree@notmail.com',
1461
+ bigint: BigInt(15),
1462
+ birthdayString: '2024-04-02',
1463
+ birthdayDate: new Date('2024-04-02T00:00:00.000Z'),
1464
+ createdAt: new Date('2024-04-02T06:44:42.000Z'),
1465
+ role: 'admin',
1466
+ roleText: null,
1467
+ roleText2: 'user',
1468
+ profession: 'ThirdUserProf',
1469
+ initials: 'FU',
1470
+ isConfirmed: true,
1471
+ },
1472
+ {
1473
+ id: 4,
1474
+ name: 'FourthUser',
1475
+ email: 'userFour@notmail.com',
1476
+ bigint: BigInt(42),
1477
+ birthdayString: '2024-04-04',
1478
+ birthdayDate: new Date('2024-04-04T00:00:00.000Z'),
1479
+ createdAt: new Date('2024-04-04T06:44:42.000Z'),
1480
+ role: 'user',
1481
+ roleText: null,
1482
+ roleText2: 'user',
1483
+ profession: 'FourthUserProf',
1484
+ initials: 'SU',
1485
+ isConfirmed: false,
1486
+ },
1487
+ ]);
1488
+ });
1489
+
1490
+ it(`Update`, async () => {
1491
+ const res = await ctx.gql.queryGql(/* GraphQL */ `
1492
+ mutation {
1493
+ updateCustomers(set: { isConfirmed: true, address: "Edited" }) {
1494
+ isSuccess
1495
+ }
1496
+ }
1497
+ `);
1498
+
1499
+ expect(res).toStrictEqual({
1500
+ data: {
1501
+ updateCustomers: {
1502
+ isSuccess: true,
1503
+ },
1504
+ },
1505
+ });
1506
+
1507
+ const data = await ctx.db.select().from(schema.Customers);
1508
+
1509
+ expect(data).toStrictEqual([
1510
+ {
1511
+ id: 1,
1512
+ address: 'Edited',
1513
+ isConfirmed: true,
1514
+ registrationDate: new Date('2024-03-27T03:54:45.000Z'),
1515
+ userId: 1,
1516
+ },
1517
+ {
1518
+ id: 2,
1519
+ address: 'Edited',
1520
+ isConfirmed: true,
1521
+ registrationDate: new Date('2024-03-27T03:55:42.000Z'),
1522
+ userId: 2,
1523
+ },
1524
+ ]);
1525
+ });
1526
+
1527
+ it(`Delete`, async () => {
1528
+ const res = await ctx.gql.queryGql(/* GraphQL */ `
1529
+ mutation {
1530
+ deleteFromCustomers {
1531
+ isSuccess
1532
+ }
1533
+ }
1534
+ `);
1535
+
1536
+ expect(res).toStrictEqual({
1537
+ data: {
1538
+ deleteFromCustomers: {
1539
+ isSuccess: true,
1540
+ },
1541
+ },
1542
+ });
1543
+
1544
+ const data = await ctx.db.select().from(schema.Customers);
1545
+
1546
+ expect(data).toStrictEqual([]);
1547
+ });
1548
+ });
1549
+
1550
+ describe.sequential('Aliased query tests', async () => {
1551
+ it(`Select single`, async () => {
1552
+ const res = await ctx.gql.queryGql(/* GraphQL */ `
1553
+ {
1554
+ user: usersSingle {
1555
+ id
1556
+ name
1557
+ email
1558
+ bigint
1559
+ birthdayString
1560
+ birthdayDate
1561
+ createdAt
1562
+ role
1563
+ roleText
1564
+ roleText2
1565
+ profession
1566
+ initials
1567
+ isConfirmed
1568
+ }
1569
+
1570
+ post: postsSingle {
1571
+ id
1572
+ user: authorId
1573
+ text: content
1574
+ }
1575
+ }
1576
+ `);
1577
+
1578
+ expect(res).toStrictEqual({
1579
+ data: {
1580
+ user: {
1581
+ id: 1,
1582
+ name: 'FirstUser',
1583
+ email: 'userOne@notmail.com',
1584
+ bigint: '10',
1585
+ birthdayString: '2024-04-02',
1586
+ birthdayDate: '2024-04-02T00:00:00.000Z',
1587
+ createdAt: '2024-04-02T06:44:42.000Z',
1588
+ role: 'admin',
1589
+ roleText: null,
1590
+ roleText2: 'user',
1591
+ profession: 'FirstUserProf',
1592
+ initials: 'FU',
1593
+ isConfirmed: true,
1594
+ },
1595
+ post: {
1596
+ id: 1,
1597
+ user: 1,
1598
+ text: '1MESSAGE',
1599
+ },
1600
+ },
1601
+ });
1602
+ });
1603
+
1604
+ it(`Select array`, async () => {
1605
+ const res = await ctx.gql.queryGql(/* GraphQL */ `
1606
+ {
1607
+ user: users {
1608
+ id
1609
+ name
1610
+ email
1611
+ bigint
1612
+ birthdayString
1613
+ birthdayDate
1614
+ createdAt
1615
+ role
1616
+ roleText
1617
+ roleText2
1618
+ profession
1619
+ initials
1620
+ isConfirmed
1621
+ }
1622
+
1623
+ post: posts {
1624
+ id
1625
+ author: authorId
1626
+ text: content
1627
+ }
1628
+ }
1629
+ `);
1630
+
1631
+ expect(res).toStrictEqual({
1632
+ data: {
1633
+ user: [
1634
+ {
1635
+ id: 1,
1636
+ name: 'FirstUser',
1637
+ email: 'userOne@notmail.com',
1638
+ bigint: '10',
1639
+ birthdayString: '2024-04-02',
1640
+ birthdayDate: '2024-04-02T00:00:00.000Z',
1641
+ createdAt: '2024-04-02T06:44:42.000Z',
1642
+ role: 'admin',
1643
+ roleText: null,
1644
+ roleText2: 'user',
1645
+ profession: 'FirstUserProf',
1646
+ initials: 'FU',
1647
+ isConfirmed: true,
1648
+ },
1649
+ {
1650
+ id: 2,
1651
+ name: 'SecondUser',
1652
+ email: null,
1653
+ bigint: null,
1654
+ birthdayString: null,
1655
+ birthdayDate: null,
1656
+ createdAt: '2024-04-02T06:44:42.000Z',
1657
+ role: null,
1658
+ roleText: null,
1659
+ roleText2: 'user',
1660
+ profession: null,
1661
+ initials: null,
1662
+ isConfirmed: null,
1663
+ },
1664
+ {
1665
+ id: 5,
1666
+ name: 'FifthUser',
1667
+ email: null,
1668
+ bigint: null,
1669
+ birthdayString: null,
1670
+ birthdayDate: null,
1671
+ createdAt: '2024-04-02T06:44:42.000Z',
1672
+ role: null,
1673
+ roleText: null,
1674
+ roleText2: 'user',
1675
+ profession: null,
1676
+ initials: null,
1677
+ isConfirmed: null,
1678
+ },
1679
+ ],
1680
+ post: [
1681
+ {
1682
+ id: 1,
1683
+ author: 1,
1684
+ text: '1MESSAGE',
1685
+ },
1686
+ {
1687
+ id: 2,
1688
+ author: 1,
1689
+ text: '2MESSAGE',
1690
+ },
1691
+ {
1692
+ id: 3,
1693
+ author: 1,
1694
+ text: '3MESSAGE',
1695
+ },
1696
+ {
1697
+ id: 4,
1698
+ author: 5,
1699
+ text: '1MESSAGE',
1700
+ },
1701
+ {
1702
+ id: 5,
1703
+ author: 5,
1704
+ text: '2MESSAGE',
1705
+ },
1706
+ {
1707
+ id: 6,
1708
+ author: 1,
1709
+ text: '4MESSAGE',
1710
+ },
1711
+ ],
1712
+ },
1713
+ });
1714
+ });
1715
+
1716
+ it(`Select single with relations`, async () => {
1717
+ const res = await ctx.gql.queryGql(/* GraphQL */ `
1718
+ {
1719
+ user: usersSingle {
1720
+ id
1721
+ name
1722
+ email
1723
+ bigint
1724
+ birthdayString
1725
+ birthdayDate
1726
+ createdAt
1727
+ role
1728
+ roleText
1729
+ roleText2
1730
+ profession
1731
+ initials
1732
+ isConfirmed
1733
+ messages: posts {
1734
+ id
1735
+ authorId
1736
+ text: content
1737
+ }
1738
+ }
1739
+
1740
+ post: postsSingle {
1741
+ id
1742
+ authorId
1743
+ content
1744
+ user: author {
1745
+ id
1746
+ from: name
1747
+ email
1748
+ bigint
1749
+ birthdayString
1750
+ birthdayDate
1751
+ createdAt
1752
+ role
1753
+ roleText
1754
+ roleText2
1755
+ profession
1756
+ initials
1757
+ isConfirmed
1758
+ }
1759
+ }
1760
+ }
1761
+ `);
1762
+
1763
+ expect(res).toStrictEqual({
1764
+ data: {
1765
+ user: {
1766
+ id: 1,
1767
+ name: 'FirstUser',
1768
+ email: 'userOne@notmail.com',
1769
+ bigint: '10',
1770
+ birthdayString: '2024-04-02',
1771
+ birthdayDate: '2024-04-02T00:00:00.000Z',
1772
+ createdAt: '2024-04-02T06:44:42.000Z',
1773
+ role: 'admin',
1774
+ roleText: null,
1775
+ roleText2: 'user',
1776
+ profession: 'FirstUserProf',
1777
+ initials: 'FU',
1778
+ isConfirmed: true,
1779
+ messages: [
1780
+ {
1781
+ id: 1,
1782
+ authorId: 1,
1783
+ text: '1MESSAGE',
1784
+ },
1785
+ {
1786
+ id: 2,
1787
+ authorId: 1,
1788
+ text: '2MESSAGE',
1789
+ },
1790
+ {
1791
+ id: 3,
1792
+ authorId: 1,
1793
+ text: '3MESSAGE',
1794
+ },
1795
+
1796
+ {
1797
+ id: 6,
1798
+ authorId: 1,
1799
+ text: '4MESSAGE',
1800
+ },
1801
+ ],
1802
+ },
1803
+ post: {
1804
+ id: 1,
1805
+ authorId: 1,
1806
+ content: '1MESSAGE',
1807
+ user: {
1808
+ id: 1,
1809
+ from: 'FirstUser',
1810
+ email: 'userOne@notmail.com',
1811
+ bigint: '10',
1812
+ birthdayString: '2024-04-02',
1813
+ birthdayDate: '2024-04-02T00:00:00.000Z',
1814
+ createdAt: '2024-04-02T06:44:42.000Z',
1815
+ role: 'admin',
1816
+ roleText: null,
1817
+ roleText2: 'user',
1818
+ profession: 'FirstUserProf',
1819
+ initials: 'FU',
1820
+ isConfirmed: true,
1821
+ },
1822
+ },
1823
+ },
1824
+ });
1825
+ });
1826
+
1827
+ it(`Select array with relations`, async () => {
1828
+ const res = await ctx.gql.queryGql(/* GraphQL */ `
1829
+ {
1830
+ user: users {
1831
+ id
1832
+ name
1833
+ email
1834
+ bigint
1835
+ birthdayString
1836
+ birthdayDate
1837
+ createdAt
1838
+ role
1839
+ roleText
1840
+ roleText2
1841
+ profession
1842
+ initials
1843
+ isConfirmed
1844
+ messages: posts {
1845
+ id
1846
+ authorId
1847
+ text: content
1848
+ }
1849
+ }
1850
+
1851
+ post: posts {
1852
+ id
1853
+ authorId
1854
+ content
1855
+ user: author {
1856
+ id
1857
+ from: name
1858
+ email
1859
+ bigint
1860
+ birthdayString
1861
+ birthdayDate
1862
+ createdAt
1863
+ role
1864
+ roleText
1865
+ roleText2
1866
+ profession
1867
+ initials
1868
+ isConfirmed
1869
+ }
1870
+ }
1871
+ }
1872
+ `);
1873
+
1874
+ expect(res).toStrictEqual({
1875
+ data: {
1876
+ user: [
1877
+ {
1878
+ id: 1,
1879
+ name: 'FirstUser',
1880
+ email: 'userOne@notmail.com',
1881
+ bigint: '10',
1882
+ birthdayString: '2024-04-02',
1883
+ birthdayDate: '2024-04-02T00:00:00.000Z',
1884
+ createdAt: '2024-04-02T06:44:42.000Z',
1885
+ role: 'admin',
1886
+ roleText: null,
1887
+ roleText2: 'user',
1888
+ profession: 'FirstUserProf',
1889
+ initials: 'FU',
1890
+ isConfirmed: true,
1891
+ messages: [
1892
+ {
1893
+ id: 1,
1894
+ authorId: 1,
1895
+ text: '1MESSAGE',
1896
+ },
1897
+ {
1898
+ id: 2,
1899
+ authorId: 1,
1900
+ text: '2MESSAGE',
1901
+ },
1902
+ {
1903
+ id: 3,
1904
+ authorId: 1,
1905
+ text: '3MESSAGE',
1906
+ },
1907
+ {
1908
+ id: 6,
1909
+ authorId: 1,
1910
+ text: '4MESSAGE',
1911
+ },
1912
+ ],
1913
+ },
1914
+ {
1915
+ id: 2,
1916
+ name: 'SecondUser',
1917
+ email: null,
1918
+ bigint: null,
1919
+ birthdayString: null,
1920
+ birthdayDate: null,
1921
+ createdAt: '2024-04-02T06:44:42.000Z',
1922
+ role: null,
1923
+ roleText: null,
1924
+ roleText2: 'user',
1925
+ profession: null,
1926
+ initials: null,
1927
+ isConfirmed: null,
1928
+ messages: [],
1929
+ },
1930
+ {
1931
+ id: 5,
1932
+ name: 'FifthUser',
1933
+ email: null,
1934
+ bigint: null,
1935
+ birthdayString: null,
1936
+ birthdayDate: null,
1937
+ createdAt: '2024-04-02T06:44:42.000Z',
1938
+ role: null,
1939
+ roleText: null,
1940
+ roleText2: 'user',
1941
+ profession: null,
1942
+ initials: null,
1943
+ isConfirmed: null,
1944
+ messages: [
1945
+ {
1946
+ id: 4,
1947
+ authorId: 5,
1948
+ text: '1MESSAGE',
1949
+ },
1950
+ {
1951
+ id: 5,
1952
+ authorId: 5,
1953
+ text: '2MESSAGE',
1954
+ },
1955
+ ],
1956
+ },
1957
+ ],
1958
+ post: [
1959
+ {
1960
+ id: 1,
1961
+ authorId: 1,
1962
+ content: '1MESSAGE',
1963
+ user: {
1964
+ id: 1,
1965
+ from: 'FirstUser',
1966
+ email: 'userOne@notmail.com',
1967
+ bigint: '10',
1968
+ birthdayString: '2024-04-02',
1969
+ birthdayDate: '2024-04-02T00:00:00.000Z',
1970
+ createdAt: '2024-04-02T06:44:42.000Z',
1971
+ role: 'admin',
1972
+ roleText: null,
1973
+ roleText2: 'user',
1974
+ profession: 'FirstUserProf',
1975
+ initials: 'FU',
1976
+ isConfirmed: true,
1977
+ },
1978
+ },
1979
+ {
1980
+ id: 2,
1981
+ authorId: 1,
1982
+ content: '2MESSAGE',
1983
+ user: {
1984
+ id: 1,
1985
+ from: 'FirstUser',
1986
+ email: 'userOne@notmail.com',
1987
+ bigint: '10',
1988
+ birthdayString: '2024-04-02',
1989
+ birthdayDate: '2024-04-02T00:00:00.000Z',
1990
+ createdAt: '2024-04-02T06:44:42.000Z',
1991
+ role: 'admin',
1992
+ roleText: null,
1993
+ roleText2: 'user',
1994
+ profession: 'FirstUserProf',
1995
+ initials: 'FU',
1996
+ isConfirmed: true,
1997
+ },
1998
+ },
1999
+ {
2000
+ id: 3,
2001
+ authorId: 1,
2002
+ content: '3MESSAGE',
2003
+ user: {
2004
+ id: 1,
2005
+ from: 'FirstUser',
2006
+ email: 'userOne@notmail.com',
2007
+ bigint: '10',
2008
+ birthdayString: '2024-04-02',
2009
+ birthdayDate: '2024-04-02T00:00:00.000Z',
2010
+ createdAt: '2024-04-02T06:44:42.000Z',
2011
+ role: 'admin',
2012
+ roleText: null,
2013
+ roleText2: 'user',
2014
+ profession: 'FirstUserProf',
2015
+ initials: 'FU',
2016
+ isConfirmed: true,
2017
+ },
2018
+ },
2019
+ {
2020
+ id: 4,
2021
+ authorId: 5,
2022
+ content: '1MESSAGE',
2023
+ user: {
2024
+ id: 5,
2025
+ from: 'FifthUser',
2026
+ email: null,
2027
+ bigint: null,
2028
+ birthdayString: null,
2029
+ birthdayDate: null,
2030
+ createdAt: '2024-04-02T06:44:42.000Z',
2031
+ role: null,
2032
+ roleText: null,
2033
+ roleText2: 'user',
2034
+ profession: null,
2035
+ initials: null,
2036
+ isConfirmed: null,
2037
+ },
2038
+ },
2039
+ {
2040
+ id: 5,
2041
+ authorId: 5,
2042
+ content: '2MESSAGE',
2043
+ user: {
2044
+ id: 5,
2045
+ from: 'FifthUser',
2046
+ email: null,
2047
+ bigint: null,
2048
+ birthdayString: null,
2049
+ birthdayDate: null,
2050
+ createdAt: '2024-04-02T06:44:42.000Z',
2051
+ role: null,
2052
+ roleText: null,
2053
+ roleText2: 'user',
2054
+ profession: null,
2055
+ initials: null,
2056
+ isConfirmed: null,
2057
+ },
2058
+ },
2059
+ {
2060
+ id: 6,
2061
+ authorId: 1,
2062
+ content: '4MESSAGE',
2063
+ user: {
2064
+ id: 1,
2065
+ from: 'FirstUser',
2066
+ email: 'userOne@notmail.com',
2067
+ bigint: '10',
2068
+ birthdayString: '2024-04-02',
2069
+ birthdayDate: '2024-04-02T00:00:00.000Z',
2070
+ createdAt: '2024-04-02T06:44:42.000Z',
2071
+ role: 'admin',
2072
+ roleText: null,
2073
+ roleText2: 'user',
2074
+ profession: 'FirstUserProf',
2075
+ initials: 'FU',
2076
+ isConfirmed: true,
2077
+ },
2078
+ },
2079
+ ],
2080
+ },
2081
+ });
2082
+ });
2083
+
2084
+ it(`Insert single`, async () => {
2085
+ const res = await ctx.gql.queryGql(/* GraphQL */ `
2086
+ mutation {
2087
+ insertIntoUsersSingle(
2088
+ values: {
2089
+ id: 3
2090
+ name: "ThirdUser"
2091
+ email: "userThree@notmail.com"
2092
+ bigint: "15"
2093
+ birthdayString: "2024-04-02"
2094
+ birthdayDate: "2024-04-02T06:44:41.785Z"
2095
+ createdAt: "2024-04-02T06:44:41.785Z"
2096
+ role: admin
2097
+ roleText: null
2098
+ profession: "ThirdUserProf"
2099
+ initials: "FU"
2100
+ isConfirmed: true
2101
+ }
2102
+ ) {
2103
+ success: isSuccess
2104
+ }
2105
+ }
2106
+ `);
2107
+
2108
+ expect(res).toStrictEqual({
2109
+ data: {
2110
+ insertIntoUsersSingle: {
2111
+ success: true,
2112
+ },
2113
+ },
2114
+ });
2115
+
2116
+ const data = await ctx.db.select().from(schema.Users).where(eq(schema.Users.id, 3));
2117
+
2118
+ expect(data).toStrictEqual([
2119
+ {
2120
+ id: 3,
2121
+ name: 'ThirdUser',
2122
+ email: 'userThree@notmail.com',
2123
+ bigint: BigInt(15),
2124
+ birthdayString: '2024-04-02',
2125
+ birthdayDate: new Date('2024-04-02T00:00:00.000Z'),
2126
+ createdAt: new Date('2024-04-02T06:44:42.000Z'),
2127
+ role: 'admin',
2128
+ roleText: null,
2129
+ roleText2: 'user',
2130
+ profession: 'ThirdUserProf',
2131
+ initials: 'FU',
2132
+ isConfirmed: true,
2133
+ },
2134
+ ]);
2135
+ });
2136
+
2137
+ it(`Insert array`, async () => {
2138
+ const res = await ctx.gql.queryGql(/* GraphQL */ `
2139
+ mutation {
2140
+ insertIntoUsers(
2141
+ values: [
2142
+ {
2143
+ id: 3
2144
+ name: "ThirdUser"
2145
+ email: "userThree@notmail.com"
2146
+ bigint: "15"
2147
+ birthdayString: "2024-04-02"
2148
+ birthdayDate: "2024-04-02T06:44:41.785Z"
2149
+ createdAt: "2024-04-02T06:44:41.785Z"
2150
+ role: admin
2151
+ roleText: null
2152
+ profession: "ThirdUserProf"
2153
+ initials: "FU"
2154
+ isConfirmed: true
2155
+ }
2156
+ {
2157
+ id: 4
2158
+ name: "FourthUser"
2159
+ email: "userFour@notmail.com"
2160
+ bigint: "42"
2161
+ birthdayString: "2024-04-04"
2162
+ birthdayDate: "2024-04-04T00:00:00.000Z"
2163
+ createdAt: "2024-04-04T06:44:41.785Z"
2164
+ role: user
2165
+ roleText: null
2166
+ roleText2: user
2167
+ profession: "FourthUserProf"
2168
+ initials: "SU"
2169
+ isConfirmed: false
2170
+ }
2171
+ ]
2172
+ ) {
2173
+ success: isSuccess
2174
+ }
2175
+ }
2176
+ `);
2177
+
2178
+ expect(res).toStrictEqual({
2179
+ data: {
2180
+ insertIntoUsers: {
2181
+ success: true,
2182
+ },
2183
+ },
2184
+ });
2185
+
2186
+ const data = await ctx.db
2187
+ .select()
2188
+ .from(schema.Users)
2189
+ .where(inArray(schema.Users.id, [3, 4]));
2190
+
2191
+ expect(data).toStrictEqual([
2192
+ {
2193
+ id: 3,
2194
+ name: 'ThirdUser',
2195
+ email: 'userThree@notmail.com',
2196
+ bigint: BigInt(15),
2197
+ birthdayString: '2024-04-02',
2198
+ birthdayDate: new Date('2024-04-02T00:00:00.000Z'),
2199
+ createdAt: new Date('2024-04-02T06:44:42.000Z'),
2200
+ role: 'admin',
2201
+ roleText: null,
2202
+ roleText2: 'user',
2203
+ profession: 'ThirdUserProf',
2204
+ initials: 'FU',
2205
+ isConfirmed: true,
2206
+ },
2207
+ {
2208
+ id: 4,
2209
+ name: 'FourthUser',
2210
+ email: 'userFour@notmail.com',
2211
+ bigint: BigInt(42),
2212
+ birthdayString: '2024-04-04',
2213
+ birthdayDate: new Date('2024-04-04T00:00:00.000Z'),
2214
+ createdAt: new Date('2024-04-04T06:44:42.000Z'),
2215
+ role: 'user',
2216
+ roleText: null,
2217
+ roleText2: 'user',
2218
+ profession: 'FourthUserProf',
2219
+ initials: 'SU',
2220
+ isConfirmed: false,
2221
+ },
2222
+ ]);
2223
+ });
2224
+
2225
+ it(`Update`, async () => {
2226
+ const res = await ctx.gql.queryGql(/* GraphQL */ `
2227
+ mutation {
2228
+ updateCustomers(set: { isConfirmed: true, address: "Edited" }) {
2229
+ success: isSuccess
2230
+ }
2231
+ }
2232
+ `);
2233
+
2234
+ expect(res).toStrictEqual({
2235
+ data: {
2236
+ updateCustomers: {
2237
+ success: true,
2238
+ },
2239
+ },
2240
+ });
2241
+
2242
+ const data = await ctx.db.select().from(schema.Customers);
2243
+
2244
+ expect(data).toStrictEqual([
2245
+ {
2246
+ id: 1,
2247
+ address: 'Edited',
2248
+ isConfirmed: true,
2249
+ registrationDate: new Date('2024-03-27T03:54:45.000Z'),
2250
+ userId: 1,
2251
+ },
2252
+ {
2253
+ id: 2,
2254
+ address: 'Edited',
2255
+ isConfirmed: true,
2256
+ registrationDate: new Date('2024-03-27T03:55:42.000Z'),
2257
+ userId: 2,
2258
+ },
2259
+ ]);
2260
+ });
2261
+
2262
+ it(`Delete`, async () => {
2263
+ const res = await ctx.gql.queryGql(/* GraphQL */ `
2264
+ mutation {
2265
+ deleteFromCustomers {
2266
+ success: isSuccess
2267
+ }
2268
+ }
2269
+ `);
2270
+
2271
+ expect(res).toStrictEqual({
2272
+ data: {
2273
+ deleteFromCustomers: {
2274
+ success: true,
2275
+ },
2276
+ },
2277
+ });
2278
+
2279
+ const data = await ctx.db.select().from(schema.Customers);
2280
+
2281
+ expect(data).toStrictEqual([]);
2282
+ });
2283
+ });
2284
+
2285
+ describe.sequential('Arguments tests', async () => {
2286
+ it('Order by', async () => {
2287
+ const res = await ctx.gql.queryGql(/* GraphQL */ `
2288
+ {
2289
+ posts(
2290
+ orderBy: { authorId: { priority: 1, direction: desc }, content: { priority: 0, direction: asc } }
2291
+ ) {
2292
+ id
2293
+ authorId
2294
+ content
2295
+ }
2296
+ }
2297
+ `);
2298
+
2299
+ expect(res).toStrictEqual({
2300
+ data: {
2301
+ posts: [
2302
+ {
2303
+ id: 4,
2304
+ authorId: 5,
2305
+ content: '1MESSAGE',
2306
+ },
2307
+ {
2308
+ id: 5,
2309
+ authorId: 5,
2310
+ content: '2MESSAGE',
2311
+ },
2312
+ {
2313
+ id: 1,
2314
+ authorId: 1,
2315
+ content: '1MESSAGE',
2316
+ },
2317
+ {
2318
+ id: 2,
2319
+ authorId: 1,
2320
+ content: '2MESSAGE',
2321
+ },
2322
+ {
2323
+ id: 3,
2324
+ authorId: 1,
2325
+ content: '3MESSAGE',
2326
+ },
2327
+
2328
+ {
2329
+ id: 6,
2330
+ authorId: 1,
2331
+ content: '4MESSAGE',
2332
+ },
2333
+ ],
2334
+ },
2335
+ });
2336
+ });
2337
+
2338
+ it('Order by on single', async () => {
2339
+ const res = await ctx.gql.queryGql(/* GraphQL */ `
2340
+ {
2341
+ postsSingle(
2342
+ orderBy: { authorId: { priority: 1, direction: desc }, content: { priority: 0, direction: asc } }
2343
+ ) {
2344
+ id
2345
+ authorId
2346
+ content
2347
+ }
2348
+ }
2349
+ `);
2350
+
2351
+ expect(res).toStrictEqual({
2352
+ data: {
2353
+ postsSingle: {
2354
+ id: 4,
2355
+ authorId: 5,
2356
+ content: '1MESSAGE',
2357
+ },
2358
+ },
2359
+ });
2360
+ });
2361
+
2362
+ it('Offset & limit', async () => {
2363
+ const res = await ctx.gql.queryGql(/* GraphQL */ `
2364
+ {
2365
+ posts(offset: 1, limit: 2) {
2366
+ id
2367
+ authorId
2368
+ content
2369
+ }
2370
+ }
2371
+ `);
2372
+
2373
+ expect(res).toStrictEqual({
2374
+ data: {
2375
+ posts: [
2376
+ {
2377
+ id: 2,
2378
+ authorId: 1,
2379
+ content: '2MESSAGE',
2380
+ },
2381
+ {
2382
+ id: 3,
2383
+ authorId: 1,
2384
+ content: '3MESSAGE',
2385
+ },
2386
+ ],
2387
+ },
2388
+ });
2389
+ });
2390
+
2391
+ it('Offset on single', async () => {
2392
+ const res = await ctx.gql.queryGql(/* GraphQL */ `
2393
+ {
2394
+ postsSingle(offset: 1) {
2395
+ id
2396
+ authorId
2397
+ content
2398
+ }
2399
+ }
2400
+ `);
2401
+
2402
+ expect(res).toStrictEqual({
2403
+ data: {
2404
+ postsSingle: {
2405
+ id: 2,
2406
+ authorId: 1,
2407
+ content: '2MESSAGE',
2408
+ },
2409
+ },
2410
+ });
2411
+ });
2412
+
2413
+ it('Filters - top level AND', async () => {
2414
+ const res = await ctx.gql.queryGql(/* GraphQL */ `
2415
+ {
2416
+ posts(where: { id: { inArray: [2, 3, 4, 5, 6] }, authorId: { ne: 5 }, content: { ne: "3MESSAGE" } }) {
2417
+ id
2418
+ authorId
2419
+ content
2420
+ }
2421
+ }
2422
+ `);
2423
+
2424
+ expect(res).toStrictEqual({
2425
+ data: {
2426
+ posts: [
2427
+ {
2428
+ id: 2,
2429
+ authorId: 1,
2430
+ content: '2MESSAGE',
2431
+ },
2432
+ {
2433
+ id: 6,
2434
+ authorId: 1,
2435
+ content: '4MESSAGE',
2436
+ },
2437
+ ],
2438
+ },
2439
+ });
2440
+ });
2441
+
2442
+ it('Filters - top level OR', async () => {
2443
+ const res = await ctx.gql.queryGql(/* GraphQL */ `
2444
+ {
2445
+ posts(where: { OR: [{ id: { lte: 3 } }, { authorId: { eq: 5 } }] }) {
2446
+ id
2447
+ authorId
2448
+ content
2449
+ }
2450
+ }
2451
+ `);
2452
+
2453
+ expect(res).toStrictEqual({
2454
+ data: {
2455
+ posts: [
2456
+ {
2457
+ id: 1,
2458
+ authorId: 1,
2459
+ content: '1MESSAGE',
2460
+ },
2461
+ {
2462
+ id: 2,
2463
+ authorId: 1,
2464
+ content: '2MESSAGE',
2465
+ },
2466
+ {
2467
+ id: 3,
2468
+ authorId: 1,
2469
+ content: '3MESSAGE',
2470
+ },
2471
+ {
2472
+ id: 4,
2473
+ authorId: 5,
2474
+ content: '1MESSAGE',
2475
+ },
2476
+ {
2477
+ id: 5,
2478
+ authorId: 5,
2479
+ content: '2MESSAGE',
2480
+ },
2481
+ ],
2482
+ },
2483
+ });
2484
+ });
2485
+
2486
+ it('Update filters', async () => {
2487
+ const res = await ctx.gql.queryGql(/* GraphQL */ `
2488
+ mutation {
2489
+ updatePosts(where: { OR: [{ id: { lte: 3 } }, { authorId: { eq: 5 } }] }, set: { content: "UPDATED" }) {
2490
+ isSuccess
2491
+ }
2492
+ }
2493
+ `);
2494
+
2495
+ expect(res).toStrictEqual({
2496
+ data: {
2497
+ updatePosts: {
2498
+ isSuccess: true,
2499
+ },
2500
+ },
2501
+ });
2502
+
2503
+ const data = await ctx.db.select().from(schema.Posts);
2504
+
2505
+ expect(data).toStrictEqual([
2506
+ {
2507
+ id: 1,
2508
+ authorId: 1,
2509
+ content: 'UPDATED',
2510
+ },
2511
+ {
2512
+ id: 2,
2513
+ authorId: 1,
2514
+ content: 'UPDATED',
2515
+ },
2516
+ {
2517
+ id: 3,
2518
+ authorId: 1,
2519
+ content: 'UPDATED',
2520
+ },
2521
+ {
2522
+ id: 4,
2523
+ authorId: 5,
2524
+ content: 'UPDATED',
2525
+ },
2526
+ {
2527
+ id: 5,
2528
+ authorId: 5,
2529
+ content: 'UPDATED',
2530
+ },
2531
+ {
2532
+ id: 6,
2533
+ authorId: 1,
2534
+ content: '4MESSAGE',
2535
+ },
2536
+ ]);
2537
+ });
2538
+
2539
+ it('Delete filters', async () => {
2540
+ const res = await ctx.gql.queryGql(/* GraphQL */ `
2541
+ mutation {
2542
+ deleteFromPosts(where: { OR: [{ id: { lte: 3 } }, { authorId: { eq: 5 } }] }) {
2543
+ isSuccess
2544
+ }
2545
+ }
2546
+ `);
2547
+
2548
+ expect(res).toStrictEqual({
2549
+ data: {
2550
+ deleteFromPosts: {
2551
+ isSuccess: true,
2552
+ },
2553
+ },
2554
+ });
2555
+
2556
+ const data = await ctx.db.select().from(schema.Posts);
2557
+
2558
+ expect(data).toStrictEqual([
2559
+ {
2560
+ id: 6,
2561
+ authorId: 1,
2562
+ content: '4MESSAGE',
2563
+ },
2564
+ ]);
2565
+ });
2566
+
2567
+ it('Relations orderBy', async () => {
2568
+ const res = await ctx.gql.queryGql(/* GraphQL */ `
2569
+ {
2570
+ users {
2571
+ id
2572
+ posts(orderBy: { id: { priority: 1, direction: desc } }) {
2573
+ id
2574
+ authorId
2575
+ content
2576
+ }
2577
+ }
2578
+ }
2579
+ `);
2580
+
2581
+ expect(res).toStrictEqual({
2582
+ data: {
2583
+ users: [
2584
+ {
2585
+ id: 1,
2586
+ posts: [
2587
+ {
2588
+ id: 6,
2589
+ authorId: 1,
2590
+ content: '4MESSAGE',
2591
+ },
2592
+ {
2593
+ id: 3,
2594
+ authorId: 1,
2595
+ content: '3MESSAGE',
2596
+ },
2597
+ {
2598
+ id: 2,
2599
+ authorId: 1,
2600
+ content: '2MESSAGE',
2601
+ },
2602
+ {
2603
+ id: 1,
2604
+ authorId: 1,
2605
+ content: '1MESSAGE',
2606
+ },
2607
+ ],
2608
+ },
2609
+ {
2610
+ id: 2,
2611
+ posts: [],
2612
+ },
2613
+ {
2614
+ id: 5,
2615
+ posts: [
2616
+ {
2617
+ id: 5,
2618
+ authorId: 5,
2619
+ content: '2MESSAGE',
2620
+ },
2621
+ {
2622
+ id: 4,
2623
+ authorId: 5,
2624
+ content: '1MESSAGE',
2625
+ },
2626
+ ],
2627
+ },
2628
+ ],
2629
+ },
2630
+ });
2631
+ });
2632
+
2633
+ it('Relations offset & limit', async () => {
2634
+ const res = await ctx.gql.queryGql(/* GraphQL */ `
2635
+ {
2636
+ users {
2637
+ id
2638
+ posts(offset: 1, limit: 2) {
2639
+ id
2640
+ authorId
2641
+ content
2642
+ }
2643
+ }
2644
+ }
2645
+ `);
2646
+
2647
+ expect(res).toStrictEqual({
2648
+ data: {
2649
+ users: [
2650
+ {
2651
+ id: 1,
2652
+ posts: [
2653
+ {
2654
+ id: 2,
2655
+ authorId: 1,
2656
+ content: '2MESSAGE',
2657
+ },
2658
+ {
2659
+ id: 3,
2660
+ authorId: 1,
2661
+ content: '3MESSAGE',
2662
+ },
2663
+ ],
2664
+ },
2665
+ {
2666
+ id: 2,
2667
+ posts: [],
2668
+ },
2669
+ {
2670
+ id: 5,
2671
+ posts: [
2672
+ {
2673
+ id: 5,
2674
+ authorId: 5,
2675
+ content: '2MESSAGE',
2676
+ },
2677
+ ],
2678
+ },
2679
+ ],
2680
+ },
2681
+ });
2682
+ });
2683
+
2684
+ it('Relations filters', async () => {
2685
+ const res = await ctx.gql.queryGql(/* GraphQL */ `
2686
+ {
2687
+ users {
2688
+ id
2689
+ posts(where: { content: { like: "2%" } }) {
2690
+ id
2691
+ authorId
2692
+ content
2693
+ }
2694
+ }
2695
+ }
2696
+ `);
2697
+
2698
+ expect(res).toStrictEqual({
2699
+ data: {
2700
+ users: [
2701
+ {
2702
+ id: 1,
2703
+ posts: [
2704
+ {
2705
+ id: 2,
2706
+ authorId: 1,
2707
+ content: '2MESSAGE',
2708
+ },
2709
+ ],
2710
+ },
2711
+ {
2712
+ id: 2,
2713
+ posts: [],
2714
+ },
2715
+ {
2716
+ id: 5,
2717
+ posts: [
2718
+ {
2719
+ id: 5,
2720
+ authorId: 5,
2721
+ content: '2MESSAGE',
2722
+ },
2723
+ ],
2724
+ },
2725
+ ],
2726
+ },
2727
+ });
2728
+ });
2729
+ });
2730
+
2731
+ describe.sequential('Returned data tests', () => {
2732
+ it('Schema', () => {
2733
+ expect(ctx.schema instanceof GraphQLSchema).toBe(true);
2734
+ });
2735
+
2736
+ it('Entities', () => {
2737
+ ctx.entities.mutations;
2738
+ const schema = z
2739
+ .object({
2740
+ queries: z
2741
+ .object({
2742
+ users: z
2743
+ .object({
2744
+ args: z
2745
+ .object({
2746
+ orderBy: z
2747
+ .object({
2748
+ type: z.instanceof(GraphQLInputObjectType),
2749
+ })
2750
+ .strict(),
2751
+ offset: z
2752
+ .object({
2753
+ type: z.instanceof(GraphQLScalarType),
2754
+ })
2755
+ .strict(),
2756
+ limit: z
2757
+ .object({
2758
+ type: z.instanceof(GraphQLScalarType),
2759
+ })
2760
+ .strict(),
2761
+ where: z
2762
+ .object({
2763
+ type: z.instanceof(GraphQLInputObjectType),
2764
+ })
2765
+ .strict(),
2766
+ })
2767
+ .strict(),
2768
+ resolve: z.function(),
2769
+ type: z.instanceof(GraphQLNonNull),
2770
+ })
2771
+ .strict(),
2772
+ usersSingle: z
2773
+ .object({
2774
+ args: z
2775
+ .object({
2776
+ orderBy: z
2777
+ .object({
2778
+ type: z.instanceof(GraphQLInputObjectType),
2779
+ })
2780
+ .strict(),
2781
+ offset: z
2782
+ .object({
2783
+ type: z.instanceof(GraphQLScalarType),
2784
+ })
2785
+ .strict(),
2786
+ where: z
2787
+ .object({
2788
+ type: z.instanceof(GraphQLInputObjectType),
2789
+ })
2790
+ .strict(),
2791
+ })
2792
+ .strict(),
2793
+ resolve: z.function(),
2794
+ type: z.instanceof(GraphQLObjectType),
2795
+ })
2796
+ .strict(),
2797
+ posts: z
2798
+ .object({
2799
+ args: z
2800
+ .object({
2801
+ orderBy: z
2802
+ .object({
2803
+ type: z.instanceof(GraphQLInputObjectType),
2804
+ })
2805
+ .strict(),
2806
+ offset: z
2807
+ .object({
2808
+ type: z.instanceof(GraphQLScalarType),
2809
+ })
2810
+ .strict(),
2811
+ limit: z
2812
+ .object({
2813
+ type: z.instanceof(GraphQLScalarType),
2814
+ })
2815
+ .strict(),
2816
+ where: z
2817
+ .object({
2818
+ type: z.instanceof(GraphQLInputObjectType),
2819
+ })
2820
+ .strict(),
2821
+ })
2822
+ .strict(),
2823
+ resolve: z.function(),
2824
+ type: z.instanceof(GraphQLNonNull),
2825
+ })
2826
+ .strict(),
2827
+ postsSingle: z
2828
+ .object({
2829
+ args: z
2830
+ .object({
2831
+ orderBy: z
2832
+ .object({
2833
+ type: z.instanceof(GraphQLInputObjectType),
2834
+ })
2835
+ .strict(),
2836
+ offset: z
2837
+ .object({
2838
+ type: z.instanceof(GraphQLScalarType),
2839
+ })
2840
+ .strict(),
2841
+ where: z
2842
+ .object({
2843
+ type: z.instanceof(GraphQLInputObjectType),
2844
+ })
2845
+ .strict(),
2846
+ })
2847
+ .strict(),
2848
+ resolve: z.function(),
2849
+ type: z.instanceof(GraphQLObjectType),
2850
+ })
2851
+ .strict(),
2852
+ customers: z
2853
+ .object({
2854
+ args: z
2855
+ .object({
2856
+ orderBy: z
2857
+ .object({
2858
+ type: z.instanceof(GraphQLInputObjectType),
2859
+ })
2860
+ .strict(),
2861
+ offset: z
2862
+ .object({
2863
+ type: z.instanceof(GraphQLScalarType),
2864
+ })
2865
+ .strict(),
2866
+ limit: z
2867
+ .object({
2868
+ type: z.instanceof(GraphQLScalarType),
2869
+ })
2870
+ .strict(),
2871
+ where: z
2872
+ .object({
2873
+ type: z.instanceof(GraphQLInputObjectType),
2874
+ })
2875
+ .strict(),
2876
+ })
2877
+ .strict(),
2878
+ resolve: z.function(),
2879
+ type: z.instanceof(GraphQLNonNull),
2880
+ })
2881
+ .strict(),
2882
+ customersSingle: z
2883
+ .object({
2884
+ args: z
2885
+ .object({
2886
+ orderBy: z
2887
+ .object({
2888
+ type: z.instanceof(GraphQLInputObjectType),
2889
+ })
2890
+ .strict(),
2891
+ offset: z
2892
+ .object({
2893
+ type: z.instanceof(GraphQLScalarType),
2894
+ })
2895
+ .strict(),
2896
+ where: z
2897
+ .object({
2898
+ type: z.instanceof(GraphQLInputObjectType),
2899
+ })
2900
+ .strict(),
2901
+ })
2902
+ .strict(),
2903
+ resolve: z.function(),
2904
+ type: z.instanceof(GraphQLObjectType),
2905
+ })
2906
+ .strict(),
2907
+ })
2908
+ .strict(),
2909
+ mutations: z
2910
+ .object({
2911
+ insertIntoUsers: z
2912
+ .object({
2913
+ args: z
2914
+ .object({
2915
+ values: z
2916
+ .object({
2917
+ type: z.instanceof(GraphQLNonNull),
2918
+ })
2919
+ .strict(),
2920
+ })
2921
+ .strict(),
2922
+ resolve: z.function(),
2923
+ type: z.instanceof(GraphQLObjectType),
2924
+ })
2925
+ .strict(),
2926
+ insertIntoUsersSingle: z
2927
+ .object({
2928
+ args: z
2929
+ .object({
2930
+ values: z
2931
+ .object({
2932
+ type: z.instanceof(GraphQLNonNull),
2933
+ })
2934
+ .strict(),
2935
+ })
2936
+ .strict(),
2937
+ resolve: z.function(),
2938
+ type: z.instanceof(GraphQLObjectType),
2939
+ })
2940
+ .strict(),
2941
+ updateUsers: z
2942
+ .object({
2943
+ args: z
2944
+ .object({
2945
+ set: z
2946
+ .object({
2947
+ type: z.instanceof(GraphQLNonNull),
2948
+ })
2949
+ .strict(),
2950
+ where: z
2951
+ .object({
2952
+ type: z.instanceof(GraphQLInputObjectType),
2953
+ })
2954
+ .strict(),
2955
+ })
2956
+ .strict(),
2957
+ resolve: z.function(),
2958
+ type: z.instanceof(GraphQLObjectType),
2959
+ })
2960
+ .strict(),
2961
+ deleteFromUsers: z
2962
+ .object({
2963
+ args: z
2964
+ .object({
2965
+ where: z
2966
+ .object({
2967
+ type: z.instanceof(GraphQLInputObjectType),
2968
+ })
2969
+ .strict(),
2970
+ })
2971
+ .strict(),
2972
+ resolve: z.function(),
2973
+ type: z.instanceof(GraphQLObjectType),
2974
+ })
2975
+ .strict(),
2976
+ insertIntoPosts: z
2977
+ .object({
2978
+ args: z
2979
+ .object({
2980
+ values: z
2981
+ .object({
2982
+ type: z.instanceof(GraphQLNonNull),
2983
+ })
2984
+ .strict(),
2985
+ })
2986
+ .strict(),
2987
+ resolve: z.function(),
2988
+ type: z.instanceof(GraphQLObjectType),
2989
+ })
2990
+ .strict(),
2991
+ insertIntoPostsSingle: z
2992
+ .object({
2993
+ args: z
2994
+ .object({
2995
+ values: z
2996
+ .object({
2997
+ type: z.instanceof(GraphQLNonNull),
2998
+ })
2999
+ .strict(),
3000
+ })
3001
+ .strict(),
3002
+ resolve: z.function(),
3003
+ type: z.instanceof(GraphQLObjectType),
3004
+ })
3005
+ .strict(),
3006
+ updatePosts: z
3007
+ .object({
3008
+ args: z
3009
+ .object({
3010
+ set: z
3011
+ .object({
3012
+ type: z.instanceof(GraphQLNonNull),
3013
+ })
3014
+ .strict(),
3015
+ where: z
3016
+ .object({
3017
+ type: z.instanceof(GraphQLInputObjectType),
3018
+ })
3019
+ .strict(),
3020
+ })
3021
+ .strict(),
3022
+ resolve: z.function(),
3023
+ type: z.instanceof(GraphQLObjectType),
3024
+ })
3025
+ .strict(),
3026
+ deleteFromPosts: z
3027
+ .object({
3028
+ args: z
3029
+ .object({
3030
+ where: z
3031
+ .object({
3032
+ type: z.instanceof(GraphQLInputObjectType),
3033
+ })
3034
+ .strict(),
3035
+ })
3036
+ .strict(),
3037
+ resolve: z.function(),
3038
+ type: z.instanceof(GraphQLObjectType),
3039
+ })
3040
+ .strict(),
3041
+ insertIntoCustomers: z
3042
+ .object({
3043
+ args: z
3044
+ .object({
3045
+ values: z
3046
+ .object({
3047
+ type: z.instanceof(GraphQLNonNull),
3048
+ })
3049
+ .strict(),
3050
+ })
3051
+ .strict(),
3052
+ resolve: z.function(),
3053
+ type: z.instanceof(GraphQLObjectType),
3054
+ })
3055
+ .strict(),
3056
+ insertIntoCustomersSingle: z
3057
+ .object({
3058
+ args: z
3059
+ .object({
3060
+ values: z
3061
+ .object({
3062
+ type: z.instanceof(GraphQLNonNull),
3063
+ })
3064
+ .strict(),
3065
+ })
3066
+ .strict(),
3067
+ resolve: z.function(),
3068
+ type: z.instanceof(GraphQLObjectType),
3069
+ })
3070
+ .strict(),
3071
+ updateCustomers: z
3072
+ .object({
3073
+ args: z
3074
+ .object({
3075
+ set: z
3076
+ .object({
3077
+ type: z.instanceof(GraphQLNonNull),
3078
+ })
3079
+ .strict(),
3080
+ where: z
3081
+ .object({
3082
+ type: z.instanceof(GraphQLInputObjectType),
3083
+ })
3084
+ .strict(),
3085
+ })
3086
+ .strict(),
3087
+ resolve: z.function(),
3088
+ type: z.instanceof(GraphQLObjectType),
3089
+ })
3090
+ .strict(),
3091
+ deleteFromCustomers: z
3092
+ .object({
3093
+ args: z
3094
+ .object({
3095
+ where: z
3096
+ .object({
3097
+ type: z.instanceof(GraphQLInputObjectType),
3098
+ })
3099
+ .strict(),
3100
+ })
3101
+ .strict(),
3102
+ resolve: z.function(),
3103
+ type: z.instanceof(GraphQLObjectType),
3104
+ })
3105
+ .strict(),
3106
+ })
3107
+ .strict(),
3108
+ types: z
3109
+ .object({
3110
+ UsersSelectItem: z.instanceof(GraphQLObjectType),
3111
+ PostsSelectItem: z.instanceof(GraphQLObjectType),
3112
+ CustomersSelectItem: z.instanceof(GraphQLObjectType),
3113
+ MutationReturn: z.instanceof(GraphQLObjectType),
3114
+ })
3115
+ .strict(),
3116
+ inputs: z
3117
+ .object({
3118
+ UsersFilters: z.instanceof(GraphQLInputObjectType),
3119
+ UsersOrderBy: z.instanceof(GraphQLInputObjectType),
3120
+ UsersInsertInput: z.instanceof(GraphQLInputObjectType),
3121
+ UsersUpdateInput: z.instanceof(GraphQLInputObjectType),
3122
+ PostsFilters: z.instanceof(GraphQLInputObjectType),
3123
+ PostsOrderBy: z.instanceof(GraphQLInputObjectType),
3124
+ PostsInsertInput: z.instanceof(GraphQLInputObjectType),
3125
+ PostsUpdateInput: z.instanceof(GraphQLInputObjectType),
3126
+ CustomersFilters: z.instanceof(GraphQLInputObjectType),
3127
+ CustomersOrderBy: z.instanceof(GraphQLInputObjectType),
3128
+ CustomersInsertInput: z.instanceof(GraphQLInputObjectType),
3129
+ CustomersUpdateInput: z.instanceof(GraphQLInputObjectType),
3130
+ })
3131
+ .strict(),
3132
+ })
3133
+ .strict();
3134
+
3135
+ const parseRes = schema.safeParse(ctx.entities);
3136
+
3137
+ if (!parseRes.success) console.log(parseRes.error);
3138
+
3139
+ expect(parseRes.success).toEqual(true);
3140
+ });
3141
+ });
3142
+
3143
+ describe.sequential('Type tests', () => {
3144
+ it('Schema', () => {
3145
+ expectTypeOf(ctx.schema).toEqualTypeOf<GraphQLSchema>();
3146
+ });
3147
+
3148
+ it('Queries', () => {
3149
+ expectTypeOf(ctx.entities.queries).toEqualTypeOf<
3150
+ {
3151
+ readonly customers: {
3152
+ type: GraphQLNonNull<GraphQLList<GraphQLNonNull<GraphQLObjectType>>>;
3153
+ args: {
3154
+ orderBy: { type: GraphQLInputObjectType };
3155
+ offset: { type: GraphQLScalarType<number, number> };
3156
+ limit: { type: GraphQLScalarType<number, number> };
3157
+ where: { type: GraphQLInputObjectType };
3158
+ };
3159
+ resolve: SelectResolver<
3160
+ typeof schema.Customers,
3161
+ ExtractTables<typeof schema>,
3162
+ typeof schema.customersRelations extends Relations<any, infer RelConf> ? RelConf : never
3163
+ >;
3164
+ };
3165
+ readonly posts: {
3166
+ type: GraphQLNonNull<GraphQLList<GraphQLNonNull<GraphQLObjectType>>>;
3167
+ args: {
3168
+ orderBy: { type: GraphQLInputObjectType };
3169
+ offset: { type: GraphQLScalarType<number, number> };
3170
+ limit: { type: GraphQLScalarType<number, number> };
3171
+ where: { type: GraphQLInputObjectType };
3172
+ };
3173
+ resolve: SelectResolver<
3174
+ typeof schema.Posts,
3175
+ ExtractTables<typeof schema>,
3176
+ typeof schema.postsRelations extends Relations<any, infer RelConf> ? RelConf : never
3177
+ >;
3178
+ };
3179
+ readonly users: {
3180
+ type: GraphQLNonNull<GraphQLList<GraphQLNonNull<GraphQLObjectType>>>;
3181
+ args: {
3182
+ orderBy: { type: GraphQLInputObjectType };
3183
+ offset: { type: GraphQLScalarType<number, number> };
3184
+ limit: { type: GraphQLScalarType<number, number> };
3185
+ where: { type: GraphQLInputObjectType };
3186
+ };
3187
+ resolve: SelectResolver<
3188
+ typeof schema.Users,
3189
+ ExtractTables<typeof schema>,
3190
+ typeof schema.usersRelations extends Relations<any, infer RelConf> ? RelConf : never
3191
+ >;
3192
+ };
3193
+ } & {
3194
+ readonly customersSingle: {
3195
+ type: GraphQLObjectType;
3196
+ args: {
3197
+ orderBy: { type: GraphQLInputObjectType };
3198
+ offset: { type: GraphQLScalarType<number, number> };
3199
+ where: { type: GraphQLInputObjectType };
3200
+ };
3201
+ resolve: SelectSingleResolver<
3202
+ typeof schema.Customers,
3203
+ ExtractTables<typeof schema>,
3204
+ typeof schema.customersRelations extends Relations<any, infer RelConf> ? RelConf : never
3205
+ >;
3206
+ };
3207
+ readonly postsSingle: {
3208
+ type: GraphQLObjectType;
3209
+ args: {
3210
+ orderBy: { type: GraphQLInputObjectType };
3211
+ offset: { type: GraphQLScalarType<number, number> };
3212
+ where: { type: GraphQLInputObjectType };
3213
+ };
3214
+ resolve: SelectSingleResolver<
3215
+ typeof schema.Posts,
3216
+ ExtractTables<typeof schema>,
3217
+ typeof schema.postsRelations extends Relations<any, infer RelConf> ? RelConf : never
3218
+ >;
3219
+ };
3220
+ readonly usersSingle: {
3221
+ type: GraphQLObjectType;
3222
+ args: {
3223
+ orderBy: { type: GraphQLInputObjectType };
3224
+ offset: { type: GraphQLScalarType<number, number> };
3225
+ where: { type: GraphQLInputObjectType };
3226
+ };
3227
+ resolve: SelectSingleResolver<
3228
+ typeof schema.Users,
3229
+ ExtractTables<typeof schema>,
3230
+ typeof schema.usersRelations extends Relations<any, infer RelConf> ? RelConf : never
3231
+ >;
3232
+ };
3233
+ }
3234
+ >();
3235
+ });
3236
+
3237
+ it('Mutations', () => {
3238
+ expectTypeOf(ctx.entities.mutations).toEqualTypeOf<
3239
+ {
3240
+ readonly insertIntoCustomers: {
3241
+ type: GraphQLObjectType;
3242
+ args: {
3243
+ values: {
3244
+ type: GraphQLNonNull<GraphQLList<GraphQLNonNull<GraphQLInputObjectType>>>;
3245
+ };
3246
+ };
3247
+ resolve: InsertArrResolver<typeof schema.Customers, true>;
3248
+ };
3249
+ readonly insertIntoPosts: {
3250
+ type: GraphQLObjectType;
3251
+ args: {
3252
+ values: {
3253
+ type: GraphQLNonNull<GraphQLList<GraphQLNonNull<GraphQLInputObjectType>>>;
3254
+ };
3255
+ };
3256
+ resolve: InsertArrResolver<typeof schema.Posts, true>;
3257
+ };
3258
+ readonly insertIntoUsers: {
3259
+ type: GraphQLObjectType;
3260
+ args: {
3261
+ values: {
3262
+ type: GraphQLNonNull<GraphQLList<GraphQLNonNull<GraphQLInputObjectType>>>;
3263
+ };
3264
+ };
3265
+ resolve: InsertArrResolver<typeof schema.Users, true>;
3266
+ };
3267
+ } & {
3268
+ readonly insertIntoCustomersSingle: {
3269
+ type: GraphQLObjectType;
3270
+ args: {
3271
+ values: {
3272
+ type: GraphQLNonNull<GraphQLInputObjectType>;
3273
+ };
3274
+ };
3275
+ resolve: InsertResolver<typeof schema.Customers, true>;
3276
+ };
3277
+ readonly insertIntoPostsSingle: {
3278
+ type: GraphQLObjectType;
3279
+ args: {
3280
+ values: {
3281
+ type: GraphQLNonNull<GraphQLInputObjectType>;
3282
+ };
3283
+ };
3284
+ resolve: InsertResolver<typeof schema.Posts, true>;
3285
+ };
3286
+ readonly insertIntoUsersSingle: {
3287
+ type: GraphQLObjectType;
3288
+ args: {
3289
+ values: {
3290
+ type: GraphQLNonNull<GraphQLInputObjectType>;
3291
+ };
3292
+ };
3293
+ resolve: InsertResolver<typeof schema.Users, true>;
3294
+ };
3295
+ } & {
3296
+ readonly updateCustomers: {
3297
+ type: GraphQLObjectType;
3298
+ args: {
3299
+ set: {
3300
+ type: GraphQLNonNull<GraphQLInputObjectType>;
3301
+ };
3302
+ where: { type: GraphQLInputObjectType };
3303
+ };
3304
+ resolve: UpdateResolver<typeof schema.Customers, true>;
3305
+ };
3306
+ readonly updatePosts: {
3307
+ type: GraphQLObjectType;
3308
+ args: {
3309
+ set: {
3310
+ type: GraphQLNonNull<GraphQLInputObjectType>;
3311
+ };
3312
+ where: { type: GraphQLInputObjectType };
3313
+ };
3314
+ resolve: UpdateResolver<typeof schema.Posts, true>;
3315
+ };
3316
+ readonly updateUsers: {
3317
+ type: GraphQLObjectType;
3318
+ args: {
3319
+ set: {
3320
+ type: GraphQLNonNull<GraphQLInputObjectType>;
3321
+ };
3322
+ where: { type: GraphQLInputObjectType };
3323
+ };
3324
+ resolve: UpdateResolver<typeof schema.Users, true>;
3325
+ };
3326
+ } & {
3327
+ readonly deleteFromCustomers: {
3328
+ type: GraphQLObjectType;
3329
+ args: {
3330
+ where: { type: GraphQLInputObjectType };
3331
+ };
3332
+ resolve: DeleteResolver<typeof schema.Customers, true>;
3333
+ };
3334
+ readonly deleteFromPosts: {
3335
+ type: GraphQLObjectType;
3336
+ args: {
3337
+ where: { type: GraphQLInputObjectType };
3338
+ };
3339
+ resolve: DeleteResolver<typeof schema.Posts, true>;
3340
+ };
3341
+ readonly deleteFromUsers: {
3342
+ type: GraphQLObjectType;
3343
+ args: {
3344
+ where: { type: GraphQLInputObjectType };
3345
+ };
3346
+ resolve: DeleteResolver<typeof schema.Users, true>;
3347
+ };
3348
+ }
3349
+ >();
3350
+ });
3351
+
3352
+ it('Types', () => {
3353
+ expectTypeOf(ctx.entities.types).toEqualTypeOf<
3354
+ {
3355
+ MutationReturn: GraphQLObjectType;
3356
+ } & {
3357
+ readonly CustomersSelectItem: GraphQLObjectType;
3358
+ readonly PostsSelectItem: GraphQLObjectType;
3359
+ readonly UsersSelectItem: GraphQLObjectType;
3360
+ }
3361
+ >();
3362
+ });
3363
+
3364
+ it('Inputs', () => {
3365
+ expectTypeOf(ctx.entities.inputs).toEqualTypeOf<
3366
+ {
3367
+ readonly UsersFilters: GraphQLInputObjectType;
3368
+ readonly CustomersFilters: GraphQLInputObjectType;
3369
+ readonly PostsFilters: GraphQLInputObjectType;
3370
+ } & {
3371
+ readonly UsersOrderBy: GraphQLInputObjectType;
3372
+ readonly CustomersOrderBy: GraphQLInputObjectType;
3373
+ readonly PostsOrderBy: GraphQLInputObjectType;
3374
+ } & {
3375
+ readonly UsersInsertInput: GraphQLInputObjectType;
3376
+ readonly CustomersInsertInput: GraphQLInputObjectType;
3377
+ readonly PostsInsertInput: GraphQLInputObjectType;
3378
+ } & {
3379
+ readonly UsersUpdateInput: GraphQLInputObjectType;
3380
+ readonly CustomersUpdateInput: GraphQLInputObjectType;
3381
+ readonly PostsUpdateInput: GraphQLInputObjectType;
3382
+ }
3383
+ >();
3384
+ });
3385
+ });
3386
+
3387
+ describe.sequential('__typename only tests', async () => {
3388
+ it(`Select single`, async () => {
3389
+ const res = await ctx.gql.queryGql(/* GraphQL */ `
3390
+ {
3391
+ usersSingle {
3392
+ __typename
3393
+ }
3394
+
3395
+ postsSingle {
3396
+ __typename
3397
+ }
3398
+ }
3399
+ `);
3400
+
3401
+ expect(res).toStrictEqual({
3402
+ data: {
3403
+ usersSingle: {
3404
+ __typename: 'UsersSelectItem',
3405
+ },
3406
+ postsSingle: {
3407
+ __typename: 'PostsSelectItem',
3408
+ },
3409
+ },
3410
+ });
3411
+ });
3412
+
3413
+ it(`Select array`, async () => {
3414
+ const res = await ctx.gql.queryGql(/* GraphQL */ `
3415
+ {
3416
+ users {
3417
+ __typename
3418
+ }
3419
+
3420
+ posts {
3421
+ __typename
3422
+ }
3423
+ }
3424
+ `);
3425
+
3426
+ expect(res).toStrictEqual({
3427
+ data: {
3428
+ users: [
3429
+ {
3430
+ __typename: 'UsersSelectItem',
3431
+ },
3432
+ {
3433
+ __typename: 'UsersSelectItem',
3434
+ },
3435
+ {
3436
+ __typename: 'UsersSelectItem',
3437
+ },
3438
+ ],
3439
+ posts: [
3440
+ {
3441
+ __typename: 'PostsSelectItem',
3442
+ },
3443
+ {
3444
+ __typename: 'PostsSelectItem',
3445
+ },
3446
+ {
3447
+ __typename: 'PostsSelectItem',
3448
+ },
3449
+ {
3450
+ __typename: 'PostsSelectItem',
3451
+ },
3452
+ {
3453
+ __typename: 'PostsSelectItem',
3454
+ },
3455
+ {
3456
+ __typename: 'PostsSelectItem',
3457
+ },
3458
+ ],
3459
+ },
3460
+ });
3461
+ });
3462
+
3463
+ it(`Select single with relations`, async () => {
3464
+ const res = await ctx.gql.queryGql(/* GraphQL */ `
3465
+ {
3466
+ usersSingle {
3467
+ __typename
3468
+ posts {
3469
+ __typename
3470
+ }
3471
+ }
3472
+
3473
+ postsSingle {
3474
+ __typename
3475
+ author {
3476
+ __typename
3477
+ }
3478
+ }
3479
+ }
3480
+ `);
3481
+
3482
+ expect(res).toStrictEqual({
3483
+ data: {
3484
+ usersSingle: {
3485
+ __typename: 'UsersSelectItem',
3486
+ posts: [
3487
+ {
3488
+ __typename: 'UsersPostsRelation',
3489
+ },
3490
+ {
3491
+ __typename: 'UsersPostsRelation',
3492
+ },
3493
+ {
3494
+ __typename: 'UsersPostsRelation',
3495
+ },
3496
+ {
3497
+ __typename: 'UsersPostsRelation',
3498
+ },
3499
+ ],
3500
+ },
3501
+ postsSingle: {
3502
+ __typename: 'PostsSelectItem',
3503
+ author: {
3504
+ __typename: 'PostsAuthorRelation',
3505
+ },
3506
+ },
3507
+ },
3508
+ });
3509
+ });
3510
+
3511
+ it(`Select array with relations`, async () => {
3512
+ const res = await ctx.gql.queryGql(/* GraphQL */ `
3513
+ {
3514
+ users {
3515
+ __typename
3516
+ posts {
3517
+ __typename
3518
+ }
3519
+ }
3520
+
3521
+ posts {
3522
+ __typename
3523
+ author {
3524
+ __typename
3525
+ }
3526
+ }
3527
+ }
3528
+ `);
3529
+
3530
+ expect(res).toStrictEqual({
3531
+ data: {
3532
+ users: [
3533
+ {
3534
+ __typename: 'UsersSelectItem',
3535
+ posts: [
3536
+ {
3537
+ __typename: 'UsersPostsRelation',
3538
+ },
3539
+ {
3540
+ __typename: 'UsersPostsRelation',
3541
+ },
3542
+ {
3543
+ __typename: 'UsersPostsRelation',
3544
+ },
3545
+ {
3546
+ __typename: 'UsersPostsRelation',
3547
+ },
3548
+ ],
3549
+ },
3550
+ {
3551
+ __typename: 'UsersSelectItem',
3552
+ posts: [],
3553
+ },
3554
+ {
3555
+ __typename: 'UsersSelectItem',
3556
+ posts: [
3557
+ {
3558
+ __typename: 'UsersPostsRelation',
3559
+ },
3560
+ {
3561
+ __typename: 'UsersPostsRelation',
3562
+ },
3563
+ ],
3564
+ },
3565
+ ],
3566
+ posts: [
3567
+ {
3568
+ __typename: 'PostsSelectItem',
3569
+ author: {
3570
+ __typename: 'PostsAuthorRelation',
3571
+ },
3572
+ },
3573
+ {
3574
+ __typename: 'PostsSelectItem',
3575
+ author: {
3576
+ __typename: 'PostsAuthorRelation',
3577
+ },
3578
+ },
3579
+ {
3580
+ __typename: 'PostsSelectItem',
3581
+ author: {
3582
+ __typename: 'PostsAuthorRelation',
3583
+ },
3584
+ },
3585
+ {
3586
+ __typename: 'PostsSelectItem',
3587
+ author: {
3588
+ __typename: 'PostsAuthorRelation',
3589
+ },
3590
+ },
3591
+ {
3592
+ __typename: 'PostsSelectItem',
3593
+ author: {
3594
+ __typename: 'PostsAuthorRelation',
3595
+ },
3596
+ },
3597
+ {
3598
+ __typename: 'PostsSelectItem',
3599
+ author: {
3600
+ __typename: 'PostsAuthorRelation',
3601
+ },
3602
+ },
3603
+ ],
3604
+ },
3605
+ });
3606
+ });
3607
+
3608
+ it(`Insert single`, async () => {
3609
+ const res = await ctx.gql.queryGql(/* GraphQL */ `
3610
+ mutation {
3611
+ insertIntoUsersSingle(
3612
+ values: {
3613
+ id: 3
3614
+ name: "ThirdUser"
3615
+ email: "userThree@notmail.com"
3616
+ bigint: "15"
3617
+ birthdayString: "2024-04-02"
3618
+ birthdayDate: "2024-04-02T06:44:41.785Z"
3619
+ createdAt: "2024-04-02T06:44:41.785Z"
3620
+ role: admin
3621
+ roleText: null
3622
+ profession: "ThirdUserProf"
3623
+ initials: "FU"
3624
+ isConfirmed: true
3625
+ }
3626
+ ) {
3627
+ __typename
3628
+ }
3629
+ }
3630
+ `);
3631
+
3632
+ expect(res).toStrictEqual({
3633
+ data: {
3634
+ insertIntoUsersSingle: {
3635
+ __typename: 'MutationReturn',
3636
+ },
3637
+ },
3638
+ });
3639
+
3640
+ const data = await ctx.db.select().from(schema.Users).where(eq(schema.Users.id, 3));
3641
+
3642
+ expect(data).toStrictEqual([
3643
+ {
3644
+ id: 3,
3645
+ name: 'ThirdUser',
3646
+ email: 'userThree@notmail.com',
3647
+ bigint: BigInt(15),
3648
+ birthdayString: '2024-04-02',
3649
+ birthdayDate: new Date('2024-04-02T00:00:00.000Z'),
3650
+ createdAt: new Date('2024-04-02T06:44:42.000Z'),
3651
+ role: 'admin',
3652
+ roleText: null,
3653
+ roleText2: 'user',
3654
+ profession: 'ThirdUserProf',
3655
+ initials: 'FU',
3656
+ isConfirmed: true,
3657
+ },
3658
+ ]);
3659
+ });
3660
+
3661
+ it(`Insert array`, async () => {
3662
+ const res = await ctx.gql.queryGql(/* GraphQL */ `
3663
+ mutation {
3664
+ insertIntoUsers(
3665
+ values: [
3666
+ {
3667
+ id: 3
3668
+ name: "ThirdUser"
3669
+ email: "userThree@notmail.com"
3670
+ bigint: "15"
3671
+ birthdayString: "2024-04-02"
3672
+ birthdayDate: "2024-04-02T06:44:41.785Z"
3673
+ createdAt: "2024-04-02T06:44:41.785Z"
3674
+ role: admin
3675
+ roleText: null
3676
+ profession: "ThirdUserProf"
3677
+ initials: "FU"
3678
+ isConfirmed: true
3679
+ }
3680
+ {
3681
+ id: 4
3682
+ name: "FourthUser"
3683
+ email: "userFour@notmail.com"
3684
+ bigint: "42"
3685
+ birthdayString: "2024-04-04"
3686
+ birthdayDate: "2024-04-04T00:00:00.000Z"
3687
+ createdAt: "2024-04-04T06:44:41.785Z"
3688
+ role: user
3689
+ roleText: null
3690
+ roleText2: user
3691
+ profession: "FourthUserProf"
3692
+ initials: "SU"
3693
+ isConfirmed: false
3694
+ }
3695
+ ]
3696
+ ) {
3697
+ __typename
3698
+ }
3699
+ }
3700
+ `);
3701
+
3702
+ expect(res).toStrictEqual({
3703
+ data: {
3704
+ insertIntoUsers: {
3705
+ __typename: 'MutationReturn',
3706
+ },
3707
+ },
3708
+ });
3709
+
3710
+ const data = await ctx.db
3711
+ .select()
3712
+ .from(schema.Users)
3713
+ .where(inArray(schema.Users.id, [3, 4]));
3714
+
3715
+ expect(data).toStrictEqual([
3716
+ {
3717
+ id: 3,
3718
+ name: 'ThirdUser',
3719
+ email: 'userThree@notmail.com',
3720
+ bigint: BigInt(15),
3721
+ birthdayString: '2024-04-02',
3722
+ birthdayDate: new Date('2024-04-02T00:00:00.000Z'),
3723
+ createdAt: new Date('2024-04-02T06:44:42.000Z'),
3724
+ role: 'admin',
3725
+ roleText: null,
3726
+ roleText2: 'user',
3727
+ profession: 'ThirdUserProf',
3728
+ initials: 'FU',
3729
+ isConfirmed: true,
3730
+ },
3731
+ {
3732
+ id: 4,
3733
+ name: 'FourthUser',
3734
+ email: 'userFour@notmail.com',
3735
+ bigint: BigInt(42),
3736
+ birthdayString: '2024-04-04',
3737
+ birthdayDate: new Date('2024-04-04T00:00:00.000Z'),
3738
+ createdAt: new Date('2024-04-04T06:44:42.000Z'),
3739
+ role: 'user',
3740
+ roleText: null,
3741
+ roleText2: 'user',
3742
+ profession: 'FourthUserProf',
3743
+ initials: 'SU',
3744
+ isConfirmed: false,
3745
+ },
3746
+ ]);
3747
+ });
3748
+
3749
+ it(`Update`, async () => {
3750
+ const res = await ctx.gql.queryGql(/* GraphQL */ `
3751
+ mutation {
3752
+ updateCustomers(set: { isConfirmed: true, address: "Edited" }) {
3753
+ __typename
3754
+ }
3755
+ }
3756
+ `);
3757
+
3758
+ expect(res).toStrictEqual({
3759
+ data: {
3760
+ updateCustomers: {
3761
+ __typename: 'MutationReturn',
3762
+ },
3763
+ },
3764
+ });
3765
+
3766
+ const data = await ctx.db.select().from(schema.Customers);
3767
+
3768
+ expect(data).toStrictEqual([
3769
+ {
3770
+ id: 1,
3771
+ address: 'Edited',
3772
+ isConfirmed: true,
3773
+ registrationDate: new Date('2024-03-27T03:54:45.000Z'),
3774
+ userId: 1,
3775
+ },
3776
+ {
3777
+ id: 2,
3778
+ address: 'Edited',
3779
+ isConfirmed: true,
3780
+ registrationDate: new Date('2024-03-27T03:55:42.000Z'),
3781
+ userId: 2,
3782
+ },
3783
+ ]);
3784
+ });
3785
+
3786
+ it(`Delete`, async () => {
3787
+ const res = await ctx.gql.queryGql(/* GraphQL */ `
3788
+ mutation {
3789
+ deleteFromCustomers {
3790
+ __typename
3791
+ }
3792
+ }
3793
+ `);
3794
+
3795
+ expect(res).toStrictEqual({
3796
+ data: {
3797
+ deleteFromCustomers: {
3798
+ __typename: 'MutationReturn',
3799
+ },
3800
+ },
3801
+ });
3802
+
3803
+ const data = await ctx.db.select().from(schema.Customers);
3804
+
3805
+ expect(data).toStrictEqual([]);
3806
+ });
3807
+ });
3808
+
3809
+ describe.sequential('__typename with data tests', async () => {
3810
+ it(`Select single`, async () => {
3811
+ const res = await ctx.gql.queryGql(/* GraphQL */ `
3812
+ {
3813
+ usersSingle {
3814
+ id
3815
+ name
3816
+ email
3817
+ bigint
3818
+ birthdayString
3819
+ birthdayDate
3820
+ createdAt
3821
+ role
3822
+ roleText
3823
+ roleText2
3824
+ profession
3825
+ initials
3826
+ isConfirmed
3827
+ __typename
3828
+ }
3829
+
3830
+ postsSingle {
3831
+ id
3832
+ authorId
3833
+ content
3834
+ __typename
3835
+ }
3836
+ }
3837
+ `);
3838
+
3839
+ expect(res).toStrictEqual({
3840
+ data: {
3841
+ usersSingle: {
3842
+ id: 1,
3843
+ name: 'FirstUser',
3844
+ email: 'userOne@notmail.com',
3845
+ bigint: '10',
3846
+ birthdayString: '2024-04-02',
3847
+ birthdayDate: '2024-04-02T00:00:00.000Z',
3848
+ createdAt: '2024-04-02T06:44:42.000Z',
3849
+ role: 'admin',
3850
+ roleText: null,
3851
+ roleText2: 'user',
3852
+ profession: 'FirstUserProf',
3853
+ initials: 'FU',
3854
+ isConfirmed: true,
3855
+ __typename: 'UsersSelectItem',
3856
+ },
3857
+ postsSingle: {
3858
+ id: 1,
3859
+ authorId: 1,
3860
+ content: '1MESSAGE',
3861
+ __typename: 'PostsSelectItem',
3862
+ },
3863
+ },
3864
+ });
3865
+ });
3866
+
3867
+ it(`Select array`, async () => {
3868
+ const res = await ctx.gql.queryGql(/* GraphQL */ `
3869
+ {
3870
+ users {
3871
+ id
3872
+ name
3873
+ email
3874
+ bigint
3875
+ birthdayString
3876
+ birthdayDate
3877
+ createdAt
3878
+ role
3879
+ roleText
3880
+ roleText2
3881
+ profession
3882
+ initials
3883
+ isConfirmed
3884
+ __typename
3885
+ }
3886
+
3887
+ posts {
3888
+ id
3889
+ authorId
3890
+ content
3891
+ __typename
3892
+ }
3893
+ }
3894
+ `);
3895
+
3896
+ expect(res).toStrictEqual({
3897
+ data: {
3898
+ users: [
3899
+ {
3900
+ id: 1,
3901
+ name: 'FirstUser',
3902
+ email: 'userOne@notmail.com',
3903
+ bigint: '10',
3904
+ birthdayString: '2024-04-02',
3905
+ birthdayDate: '2024-04-02T00:00:00.000Z',
3906
+ createdAt: '2024-04-02T06:44:42.000Z',
3907
+ role: 'admin',
3908
+ roleText: null,
3909
+ roleText2: 'user',
3910
+ profession: 'FirstUserProf',
3911
+ initials: 'FU',
3912
+ isConfirmed: true,
3913
+ __typename: 'UsersSelectItem',
3914
+ },
3915
+ {
3916
+ id: 2,
3917
+ name: 'SecondUser',
3918
+ email: null,
3919
+ bigint: null,
3920
+ birthdayString: null,
3921
+ birthdayDate: null,
3922
+ createdAt: '2024-04-02T06:44:42.000Z',
3923
+ role: null,
3924
+ roleText: null,
3925
+ roleText2: 'user',
3926
+ profession: null,
3927
+ initials: null,
3928
+ isConfirmed: null,
3929
+ __typename: 'UsersSelectItem',
3930
+ },
3931
+ {
3932
+ id: 5,
3933
+ name: 'FifthUser',
3934
+ email: null,
3935
+ bigint: null,
3936
+ birthdayString: null,
3937
+ birthdayDate: null,
3938
+ createdAt: '2024-04-02T06:44:42.000Z',
3939
+ role: null,
3940
+ roleText: null,
3941
+ roleText2: 'user',
3942
+ profession: null,
3943
+ initials: null,
3944
+ isConfirmed: null,
3945
+ __typename: 'UsersSelectItem',
3946
+ },
3947
+ ],
3948
+ posts: [
3949
+ {
3950
+ id: 1,
3951
+ authorId: 1,
3952
+ content: '1MESSAGE',
3953
+ __typename: 'PostsSelectItem',
3954
+ },
3955
+ {
3956
+ id: 2,
3957
+ authorId: 1,
3958
+ content: '2MESSAGE',
3959
+ __typename: 'PostsSelectItem',
3960
+ },
3961
+ {
3962
+ id: 3,
3963
+ authorId: 1,
3964
+ content: '3MESSAGE',
3965
+ __typename: 'PostsSelectItem',
3966
+ },
3967
+ {
3968
+ id: 4,
3969
+ authorId: 5,
3970
+ content: '1MESSAGE',
3971
+ __typename: 'PostsSelectItem',
3972
+ },
3973
+ {
3974
+ id: 5,
3975
+ authorId: 5,
3976
+ content: '2MESSAGE',
3977
+ __typename: 'PostsSelectItem',
3978
+ },
3979
+ {
3980
+ id: 6,
3981
+ authorId: 1,
3982
+ content: '4MESSAGE',
3983
+ __typename: 'PostsSelectItem',
3984
+ },
3985
+ ],
3986
+ },
3987
+ });
3988
+ });
3989
+
3990
+ it(`Select single with relations`, async () => {
3991
+ const res = await ctx.gql.queryGql(/* GraphQL */ `
3992
+ {
3993
+ usersSingle {
3994
+ id
3995
+ name
3996
+ email
3997
+ bigint
3998
+ birthdayString
3999
+ birthdayDate
4000
+ createdAt
4001
+ role
4002
+ roleText
4003
+ roleText2
4004
+ profession
4005
+ initials
4006
+ isConfirmed
4007
+ __typename
4008
+ posts {
4009
+ id
4010
+ authorId
4011
+ content
4012
+ __typename
4013
+ }
4014
+ }
4015
+
4016
+ postsSingle {
4017
+ id
4018
+ authorId
4019
+ content
4020
+ __typename
4021
+ author {
4022
+ id
4023
+ name
4024
+ email
4025
+ bigint
4026
+ birthdayString
4027
+ birthdayDate
4028
+ createdAt
4029
+ role
4030
+ roleText
4031
+ roleText2
4032
+ profession
4033
+ initials
4034
+ isConfirmed
4035
+ __typename
4036
+ }
4037
+ }
4038
+ }
4039
+ `);
4040
+
4041
+ expect(res).toStrictEqual({
4042
+ data: {
4043
+ usersSingle: {
4044
+ id: 1,
4045
+ name: 'FirstUser',
4046
+ email: 'userOne@notmail.com',
4047
+ bigint: '10',
4048
+ birthdayString: '2024-04-02',
4049
+ birthdayDate: '2024-04-02T00:00:00.000Z',
4050
+ createdAt: '2024-04-02T06:44:42.000Z',
4051
+ role: 'admin',
4052
+ roleText: null,
4053
+ roleText2: 'user',
4054
+ profession: 'FirstUserProf',
4055
+ initials: 'FU',
4056
+ isConfirmed: true,
4057
+ __typename: 'UsersSelectItem',
4058
+ posts: [
4059
+ {
4060
+ id: 1,
4061
+ authorId: 1,
4062
+ content: '1MESSAGE',
4063
+ __typename: 'UsersPostsRelation',
4064
+ },
4065
+ {
4066
+ id: 2,
4067
+ authorId: 1,
4068
+ content: '2MESSAGE',
4069
+ __typename: 'UsersPostsRelation',
4070
+ },
4071
+ {
4072
+ id: 3,
4073
+ authorId: 1,
4074
+ content: '3MESSAGE',
4075
+ __typename: 'UsersPostsRelation',
4076
+ },
4077
+ {
4078
+ id: 6,
4079
+ authorId: 1,
4080
+ content: '4MESSAGE',
4081
+ __typename: 'UsersPostsRelation',
4082
+ },
4083
+ ],
4084
+ },
4085
+ postsSingle: {
4086
+ id: 1,
4087
+ authorId: 1,
4088
+ content: '1MESSAGE',
4089
+ __typename: 'PostsSelectItem',
4090
+ author: {
4091
+ id: 1,
4092
+ name: 'FirstUser',
4093
+ email: 'userOne@notmail.com',
4094
+ bigint: '10',
4095
+ birthdayString: '2024-04-02',
4096
+ birthdayDate: '2024-04-02T00:00:00.000Z',
4097
+ createdAt: '2024-04-02T06:44:42.000Z',
4098
+ role: 'admin',
4099
+ roleText: null,
4100
+ roleText2: 'user',
4101
+ profession: 'FirstUserProf',
4102
+ initials: 'FU',
4103
+ isConfirmed: true,
4104
+ __typename: 'PostsAuthorRelation',
4105
+ },
4106
+ },
4107
+ },
4108
+ });
4109
+ });
4110
+
4111
+ it(`Select array with relations`, async () => {
4112
+ const res = await ctx.gql.queryGql(/* GraphQL */ `
4113
+ {
4114
+ users {
4115
+ id
4116
+ name
4117
+ email
4118
+ bigint
4119
+ birthdayString
4120
+ birthdayDate
4121
+ createdAt
4122
+ role
4123
+ roleText
4124
+ roleText2
4125
+ profession
4126
+ initials
4127
+ isConfirmed
4128
+ __typename
4129
+ posts {
4130
+ id
4131
+ authorId
4132
+ content
4133
+ __typename
4134
+ }
4135
+ }
4136
+
4137
+ posts {
4138
+ id
4139
+ authorId
4140
+ content
4141
+ __typename
4142
+ author {
4143
+ id
4144
+ name
4145
+ email
4146
+ bigint
4147
+ birthdayString
4148
+ birthdayDate
4149
+ createdAt
4150
+ role
4151
+ roleText
4152
+ roleText2
4153
+ profession
4154
+ initials
4155
+ isConfirmed
4156
+ __typename
4157
+ }
4158
+ }
4159
+ }
4160
+ `);
4161
+
4162
+ expect(res).toStrictEqual({
4163
+ data: {
4164
+ users: [
4165
+ {
4166
+ id: 1,
4167
+ name: 'FirstUser',
4168
+ email: 'userOne@notmail.com',
4169
+ bigint: '10',
4170
+ birthdayString: '2024-04-02',
4171
+ birthdayDate: '2024-04-02T00:00:00.000Z',
4172
+ createdAt: '2024-04-02T06:44:42.000Z',
4173
+ role: 'admin',
4174
+ roleText: null,
4175
+ roleText2: 'user',
4176
+ profession: 'FirstUserProf',
4177
+ initials: 'FU',
4178
+ isConfirmed: true,
4179
+ __typename: 'UsersSelectItem',
4180
+ posts: [
4181
+ {
4182
+ id: 1,
4183
+ authorId: 1,
4184
+ content: '1MESSAGE',
4185
+ __typename: 'UsersPostsRelation',
4186
+ },
4187
+ {
4188
+ id: 2,
4189
+ authorId: 1,
4190
+ content: '2MESSAGE',
4191
+ __typename: 'UsersPostsRelation',
4192
+ },
4193
+ {
4194
+ id: 3,
4195
+ authorId: 1,
4196
+ content: '3MESSAGE',
4197
+ __typename: 'UsersPostsRelation',
4198
+ },
4199
+ {
4200
+ id: 6,
4201
+ authorId: 1,
4202
+ content: '4MESSAGE',
4203
+ __typename: 'UsersPostsRelation',
4204
+ },
4205
+ ],
4206
+ },
4207
+ {
4208
+ id: 2,
4209
+ name: 'SecondUser',
4210
+ email: null,
4211
+ bigint: null,
4212
+ birthdayString: null,
4213
+ birthdayDate: null,
4214
+ createdAt: '2024-04-02T06:44:42.000Z',
4215
+ role: null,
4216
+ roleText: null,
4217
+ roleText2: 'user',
4218
+ profession: null,
4219
+ initials: null,
4220
+ isConfirmed: null,
4221
+ __typename: 'UsersSelectItem',
4222
+ posts: [],
4223
+ },
4224
+ {
4225
+ id: 5,
4226
+ name: 'FifthUser',
4227
+ email: null,
4228
+ bigint: null,
4229
+ birthdayString: null,
4230
+ birthdayDate: null,
4231
+ createdAt: '2024-04-02T06:44:42.000Z',
4232
+ role: null,
4233
+ roleText: null,
4234
+ roleText2: 'user',
4235
+ profession: null,
4236
+ initials: null,
4237
+ isConfirmed: null,
4238
+ __typename: 'UsersSelectItem',
4239
+ posts: [
4240
+ {
4241
+ id: 4,
4242
+ authorId: 5,
4243
+ content: '1MESSAGE',
4244
+ __typename: 'UsersPostsRelation',
4245
+ },
4246
+ {
4247
+ id: 5,
4248
+ authorId: 5,
4249
+ content: '2MESSAGE',
4250
+ __typename: 'UsersPostsRelation',
4251
+ },
4252
+ ],
4253
+ },
4254
+ ],
4255
+ posts: [
4256
+ {
4257
+ id: 1,
4258
+ authorId: 1,
4259
+ content: '1MESSAGE',
4260
+ __typename: 'PostsSelectItem',
4261
+ author: {
4262
+ id: 1,
4263
+ name: 'FirstUser',
4264
+ email: 'userOne@notmail.com',
4265
+ bigint: '10',
4266
+ birthdayString: '2024-04-02',
4267
+ birthdayDate: '2024-04-02T00:00:00.000Z',
4268
+ createdAt: '2024-04-02T06:44:42.000Z',
4269
+ role: 'admin',
4270
+ roleText: null,
4271
+ roleText2: 'user',
4272
+ profession: 'FirstUserProf',
4273
+ initials: 'FU',
4274
+ isConfirmed: true,
4275
+ __typename: 'PostsAuthorRelation',
4276
+ },
4277
+ },
4278
+ {
4279
+ id: 2,
4280
+ authorId: 1,
4281
+ content: '2MESSAGE',
4282
+ __typename: 'PostsSelectItem',
4283
+ author: {
4284
+ id: 1,
4285
+ name: 'FirstUser',
4286
+ email: 'userOne@notmail.com',
4287
+ bigint: '10',
4288
+ birthdayString: '2024-04-02',
4289
+ birthdayDate: '2024-04-02T00:00:00.000Z',
4290
+ createdAt: '2024-04-02T06:44:42.000Z',
4291
+ role: 'admin',
4292
+ roleText: null,
4293
+ roleText2: 'user',
4294
+ profession: 'FirstUserProf',
4295
+ initials: 'FU',
4296
+ isConfirmed: true,
4297
+ __typename: 'PostsAuthorRelation',
4298
+ },
4299
+ },
4300
+ {
4301
+ id: 3,
4302
+ authorId: 1,
4303
+ content: '3MESSAGE',
4304
+ __typename: 'PostsSelectItem',
4305
+ author: {
4306
+ id: 1,
4307
+ name: 'FirstUser',
4308
+ email: 'userOne@notmail.com',
4309
+ bigint: '10',
4310
+ birthdayString: '2024-04-02',
4311
+ birthdayDate: '2024-04-02T00:00:00.000Z',
4312
+ createdAt: '2024-04-02T06:44:42.000Z',
4313
+ role: 'admin',
4314
+ roleText: null,
4315
+ roleText2: 'user',
4316
+ profession: 'FirstUserProf',
4317
+ initials: 'FU',
4318
+ isConfirmed: true,
4319
+ __typename: 'PostsAuthorRelation',
4320
+ },
4321
+ },
4322
+ {
4323
+ id: 4,
4324
+ authorId: 5,
4325
+ content: '1MESSAGE',
4326
+ __typename: 'PostsSelectItem',
4327
+ author: {
4328
+ id: 5,
4329
+ name: 'FifthUser',
4330
+ email: null,
4331
+ bigint: null,
4332
+ birthdayString: null,
4333
+ birthdayDate: null,
4334
+ createdAt: '2024-04-02T06:44:42.000Z',
4335
+ role: null,
4336
+ roleText: null,
4337
+ roleText2: 'user',
4338
+ profession: null,
4339
+ initials: null,
4340
+ isConfirmed: null,
4341
+ __typename: 'PostsAuthorRelation',
4342
+ },
4343
+ },
4344
+ {
4345
+ id: 5,
4346
+ authorId: 5,
4347
+ content: '2MESSAGE',
4348
+ __typename: 'PostsSelectItem',
4349
+ author: {
4350
+ id: 5,
4351
+ name: 'FifthUser',
4352
+ email: null,
4353
+ bigint: null,
4354
+ birthdayString: null,
4355
+ birthdayDate: null,
4356
+ createdAt: '2024-04-02T06:44:42.000Z',
4357
+ role: null,
4358
+ roleText: null,
4359
+ roleText2: 'user',
4360
+ profession: null,
4361
+ initials: null,
4362
+ isConfirmed: null,
4363
+ __typename: 'PostsAuthorRelation',
4364
+ },
4365
+ },
4366
+ {
4367
+ id: 6,
4368
+ authorId: 1,
4369
+ content: '4MESSAGE',
4370
+ __typename: 'PostsSelectItem',
4371
+ author: {
4372
+ id: 1,
4373
+ name: 'FirstUser',
4374
+ email: 'userOne@notmail.com',
4375
+ bigint: '10',
4376
+ birthdayString: '2024-04-02',
4377
+ birthdayDate: '2024-04-02T00:00:00.000Z',
4378
+ createdAt: '2024-04-02T06:44:42.000Z',
4379
+ role: 'admin',
4380
+ roleText: null,
4381
+ roleText2: 'user',
4382
+ profession: 'FirstUserProf',
4383
+ initials: 'FU',
4384
+ isConfirmed: true,
4385
+ __typename: 'PostsAuthorRelation',
4386
+ },
4387
+ },
4388
+ ],
4389
+ },
4390
+ });
4391
+ });
4392
+
4393
+ it(`Insert single`, async () => {
4394
+ const res = await ctx.gql.queryGql(/* GraphQL */ `
4395
+ mutation {
4396
+ insertIntoUsersSingle(
4397
+ values: {
4398
+ id: 3
4399
+ name: "ThirdUser"
4400
+ email: "userThree@notmail.com"
4401
+ bigint: "15"
4402
+ birthdayString: "2024-04-02"
4403
+ birthdayDate: "2024-04-02T06:44:41.785Z"
4404
+ createdAt: "2024-04-02T06:44:41.785Z"
4405
+ role: admin
4406
+ roleText: null
4407
+ profession: "ThirdUserProf"
4408
+ initials: "FU"
4409
+ isConfirmed: true
4410
+ }
4411
+ ) {
4412
+ isSuccess
4413
+ __typename
4414
+ }
4415
+ }
4416
+ `);
4417
+
4418
+ expect(res).toStrictEqual({
4419
+ data: {
4420
+ insertIntoUsersSingle: {
4421
+ isSuccess: true,
4422
+ __typename: 'MutationReturn',
4423
+ },
4424
+ },
4425
+ });
4426
+
4427
+ const data = await ctx.db.select().from(schema.Users).where(eq(schema.Users.id, 3));
4428
+
4429
+ expect(data).toStrictEqual([
4430
+ {
4431
+ id: 3,
4432
+ name: 'ThirdUser',
4433
+ email: 'userThree@notmail.com',
4434
+ bigint: BigInt(15),
4435
+ birthdayString: '2024-04-02',
4436
+ birthdayDate: new Date('2024-04-02T00:00:00.000Z'),
4437
+ createdAt: new Date('2024-04-02T06:44:42.000Z'),
4438
+ role: 'admin',
4439
+ roleText: null,
4440
+ roleText2: 'user',
4441
+ profession: 'ThirdUserProf',
4442
+ initials: 'FU',
4443
+ isConfirmed: true,
4444
+ },
4445
+ ]);
4446
+ });
4447
+
4448
+ it(`Insert array`, async () => {
4449
+ const res = await ctx.gql.queryGql(/* GraphQL */ `
4450
+ mutation {
4451
+ insertIntoUsers(
4452
+ values: [
4453
+ {
4454
+ id: 3
4455
+ name: "ThirdUser"
4456
+ email: "userThree@notmail.com"
4457
+ bigint: "15"
4458
+ birthdayString: "2024-04-02"
4459
+ birthdayDate: "2024-04-02T06:44:41.785Z"
4460
+ createdAt: "2024-04-02T06:44:41.785Z"
4461
+ role: admin
4462
+ roleText: null
4463
+ profession: "ThirdUserProf"
4464
+ initials: "FU"
4465
+ isConfirmed: true
4466
+ }
4467
+ {
4468
+ id: 4
4469
+ name: "FourthUser"
4470
+ email: "userFour@notmail.com"
4471
+ bigint: "42"
4472
+ birthdayString: "2024-04-04"
4473
+ birthdayDate: "2024-04-04T00:00:00.000Z"
4474
+ createdAt: "2024-04-04T06:44:41.785Z"
4475
+ role: user
4476
+ roleText: null
4477
+ roleText2: user
4478
+ profession: "FourthUserProf"
4479
+ initials: "SU"
4480
+ isConfirmed: false
4481
+ }
4482
+ ]
4483
+ ) {
4484
+ isSuccess
4485
+ __typename
4486
+ }
4487
+ }
4488
+ `);
4489
+
4490
+ expect(res).toStrictEqual({
4491
+ data: {
4492
+ insertIntoUsers: {
4493
+ isSuccess: true,
4494
+ __typename: 'MutationReturn',
4495
+ },
4496
+ },
4497
+ });
4498
+
4499
+ const data = await ctx.db
4500
+ .select()
4501
+ .from(schema.Users)
4502
+ .where(inArray(schema.Users.id, [3, 4]));
4503
+
4504
+ expect(data).toStrictEqual([
4505
+ {
4506
+ id: 3,
4507
+ name: 'ThirdUser',
4508
+ email: 'userThree@notmail.com',
4509
+ bigint: BigInt(15),
4510
+ birthdayString: '2024-04-02',
4511
+ birthdayDate: new Date('2024-04-02T00:00:00.000Z'),
4512
+ createdAt: new Date('2024-04-02T06:44:42.000Z'),
4513
+ role: 'admin',
4514
+ roleText: null,
4515
+ roleText2: 'user',
4516
+ profession: 'ThirdUserProf',
4517
+ initials: 'FU',
4518
+ isConfirmed: true,
4519
+ },
4520
+ {
4521
+ id: 4,
4522
+ name: 'FourthUser',
4523
+ email: 'userFour@notmail.com',
4524
+ bigint: BigInt(42),
4525
+ birthdayString: '2024-04-04',
4526
+ birthdayDate: new Date('2024-04-04T00:00:00.000Z'),
4527
+ createdAt: new Date('2024-04-04T06:44:42.000Z'),
4528
+ role: 'user',
4529
+ roleText: null,
4530
+ roleText2: 'user',
4531
+ profession: 'FourthUserProf',
4532
+ initials: 'SU',
4533
+ isConfirmed: false,
4534
+ },
4535
+ ]);
4536
+ });
4537
+
4538
+ it(`Update`, async () => {
4539
+ const res = await ctx.gql.queryGql(/* GraphQL */ `
4540
+ mutation {
4541
+ updateCustomers(set: { isConfirmed: true, address: "Edited" }) {
4542
+ isSuccess
4543
+ __typename
4544
+ }
4545
+ }
4546
+ `);
4547
+
4548
+ expect(res).toStrictEqual({
4549
+ data: {
4550
+ updateCustomers: {
4551
+ isSuccess: true,
4552
+ __typename: 'MutationReturn',
4553
+ },
4554
+ },
4555
+ });
4556
+
4557
+ const data = await ctx.db.select().from(schema.Customers);
4558
+
4559
+ expect(data).toStrictEqual([
4560
+ {
4561
+ id: 1,
4562
+ address: 'Edited',
4563
+ isConfirmed: true,
4564
+ registrationDate: new Date('2024-03-27T03:54:45.000Z'),
4565
+ userId: 1,
4566
+ },
4567
+ {
4568
+ id: 2,
4569
+ address: 'Edited',
4570
+ isConfirmed: true,
4571
+ registrationDate: new Date('2024-03-27T03:55:42.000Z'),
4572
+ userId: 2,
4573
+ },
4574
+ ]);
4575
+ });
4576
+
4577
+ it(`Delete`, async () => {
4578
+ const res = await ctx.gql.queryGql(/* GraphQL */ `
4579
+ mutation {
4580
+ deleteFromCustomers {
4581
+ isSuccess
4582
+ __typename
4583
+ }
4584
+ }
4585
+ `);
4586
+
4587
+ expect(res).toStrictEqual({
4588
+ data: {
4589
+ deleteFromCustomers: {
4590
+ isSuccess: true,
4591
+ __typename: 'MutationReturn',
4592
+ },
4593
+ },
4594
+ });
4595
+
4596
+ const data = await ctx.db.select().from(schema.Customers);
4597
+
4598
+ expect(data).toStrictEqual([]);
4599
+ });
4600
+ });