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