drizzle-graphql-plus 0.8.6 → 0.8.7

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