@contember/client-content 2.0.0-alpha.9 → 2.0.0-beta.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (52) hide show
  1. package/dist/development/src/ContentClient.cjs.map +1 -1
  2. package/dist/development/src/ContentClient.js.map +1 -1
  3. package/dist/development/src/ContentQueryBuilder.cjs.map +1 -1
  4. package/dist/development/src/ContentQueryBuilder.js.map +1 -1
  5. package/dist/development/src/nodes/ContentEntitySelection.cjs.map +1 -1
  6. package/dist/development/src/nodes/ContentEntitySelection.js.map +1 -1
  7. package/dist/development/src/nodes/ContentOperation.cjs.map +1 -1
  8. package/dist/development/src/nodes/ContentOperation.js.map +1 -1
  9. package/dist/development/src/utils/ContentOperationSet.cjs.map +1 -1
  10. package/dist/development/src/utils/ContentOperationSet.js.map +1 -1
  11. package/dist/development/src/utils/createListArgs.cjs.map +1 -1
  12. package/dist/development/src/utils/createListArgs.js.map +1 -1
  13. package/dist/development/src/utils/createMutationOperationSet.cjs.map +1 -1
  14. package/dist/development/src/utils/createMutationOperationSet.js.map +1 -1
  15. package/dist/development/src/utils/createQueryOperationSet.cjs.map +1 -1
  16. package/dist/development/src/utils/createQueryOperationSet.js.map +1 -1
  17. package/dist/development/src/utils/createTypedArgs.cjs.map +1 -1
  18. package/dist/development/src/utils/createTypedArgs.js.map +1 -1
  19. package/dist/development/src/utils/mutationFragments.cjs.map +1 -1
  20. package/dist/development/src/utils/mutationFragments.js.map +1 -1
  21. package/dist/production/src/ContentClient.cjs.map +1 -1
  22. package/dist/production/src/ContentClient.js.map +1 -1
  23. package/dist/production/src/ContentQueryBuilder.cjs.map +1 -1
  24. package/dist/production/src/ContentQueryBuilder.js.map +1 -1
  25. package/dist/production/src/nodes/ContentEntitySelection.cjs.map +1 -1
  26. package/dist/production/src/nodes/ContentEntitySelection.js.map +1 -1
  27. package/dist/production/src/nodes/ContentOperation.cjs.map +1 -1
  28. package/dist/production/src/nodes/ContentOperation.js.map +1 -1
  29. package/dist/production/src/utils/ContentOperationSet.cjs.map +1 -1
  30. package/dist/production/src/utils/ContentOperationSet.js.map +1 -1
  31. package/dist/production/src/utils/createListArgs.cjs.map +1 -1
  32. package/dist/production/src/utils/createListArgs.js.map +1 -1
  33. package/dist/production/src/utils/createMutationOperationSet.cjs.map +1 -1
  34. package/dist/production/src/utils/createMutationOperationSet.js.map +1 -1
  35. package/dist/production/src/utils/createQueryOperationSet.cjs.map +1 -1
  36. package/dist/production/src/utils/createQueryOperationSet.js.map +1 -1
  37. package/dist/production/src/utils/createTypedArgs.cjs.map +1 -1
  38. package/dist/production/src/utils/createTypedArgs.js.map +1 -1
  39. package/dist/production/src/utils/mutationFragments.cjs.map +1 -1
  40. package/dist/production/src/utils/mutationFragments.js.map +1 -1
  41. package/dist/types/tsconfig.tsbuildinfo +1 -1
  42. package/dist/types/types/Schema.d.ts +6 -3
  43. package/dist/types/types/Schema.d.ts.map +1 -1
  44. package/package.json +6 -6
  45. package/src/types/Schema.ts +6 -3
  46. package/tests/cases/unit/__snapshots__/mutation.test.ts.snap +1198 -0
  47. package/tests/cases/unit/__snapshots__/query.test.ts.snap +102 -0
  48. package/tests/cases/unit/mutation.test.ts +244 -1199
  49. package/tests/cases/unit/query.test.ts +55 -124
  50. package/tests/cases/unit/types.test.ts +3 -2
  51. package/tests/client/enums.ts +3 -1
  52. package/tests/client/names.ts +2 -1
@@ -1,4 +1,4 @@
1
- import { describe, expect, test } from 'vitest'
1
+ import { describe, expect, test } from 'bun:test'
2
2
  import { createClient } from '../../lib'
3
3
  import { queryBuilder } from '../../client'
4
4
 
@@ -24,70 +24,8 @@ describe('mutations in trx', () => {
24
24
 
25
25
  expect(result.data.ok).toBe(true)
26
26
  expect(calls).toHaveLength(1)
27
- expect(calls[0].query).toMatchInlineSnapshot(`
28
- "mutation($MutationTransactionOptions_0: MutationTransactionOptions, $AuthorCreateInput_1: AuthorCreateInput!) {
29
- mut: transaction(options: $MutationTransactionOptions_0) {
30
- ok
31
- errorMessage
32
- errors {
33
- ... MutationError
34
- }
35
- validation {
36
- ... ValidationResult
37
- }
38
- mut: createAuthor(data: $AuthorCreateInput_1) {
39
- ok
40
- errorMessage
41
- errors {
42
- ... MutationError
43
- }
44
- validation {
45
- ... ValidationResult
46
- }
47
- }
48
- }
49
- }
50
- fragment MutationError on _MutationError {
51
- paths {
52
- ... on _FieldPathFragment {
53
- field
54
- }
55
- ... on _IndexPathFragment {
56
- index
57
- alias
58
- }
59
- }
60
- message
61
- type
62
- }
63
- fragment ValidationResult on _ValidationResult {
64
- valid
65
- errors {
66
- path {
67
- ... on _FieldPathFragment {
68
- field
69
- }
70
- ... on _IndexPathFragment {
71
- index
72
- alias
73
- }
74
- }
75
- message {
76
- text
77
- }
78
- }
79
- }
80
- "
81
- `)
82
- expect(calls[0].variables).toMatchInlineSnapshot(`
83
- {
84
- "AuthorCreateInput_1": {
85
- "email": "xx@localhost",
86
- "name": "John",
87
- },
88
- "MutationTransactionOptions_0": {},
89
- }
90
- `)
27
+ expect(calls[0].query).toMatchSnapshot()
28
+ expect(calls[0].variables).toMatchSnapshot()
91
29
  })
92
30
 
93
31
  test('mutation with a node', async () => {
@@ -109,73 +47,8 @@ describe('mutations in trx', () => {
109
47
  expect(result.ok).toBe(true)
110
48
  expect(result.data?.node?.id).toBe('ca7a9b84-efbb-435d-a063-da11f205335a')
111
49
  expect(calls).toHaveLength(1)
112
- expect(calls[0].query).toMatchInlineSnapshot(`
113
- "mutation($MutationTransactionOptions_0: MutationTransactionOptions, $AuthorCreateInput_1: AuthorCreateInput!) {
114
- mut: transaction(options: $MutationTransactionOptions_0) {
115
- ok
116
- errorMessage
117
- errors {
118
- ... MutationError
119
- }
120
- validation {
121
- ... ValidationResult
122
- }
123
- mut: createAuthor(data: $AuthorCreateInput_1) {
124
- ok
125
- errorMessage
126
- errors {
127
- ... MutationError
128
- }
129
- validation {
130
- ... ValidationResult
131
- }
132
- node {
133
- id
134
- }
135
- }
136
- }
137
- }
138
- fragment MutationError on _MutationError {
139
- paths {
140
- ... on _FieldPathFragment {
141
- field
142
- }
143
- ... on _IndexPathFragment {
144
- index
145
- alias
146
- }
147
- }
148
- message
149
- type
150
- }
151
- fragment ValidationResult on _ValidationResult {
152
- valid
153
- errors {
154
- path {
155
- ... on _FieldPathFragment {
156
- field
157
- }
158
- ... on _IndexPathFragment {
159
- index
160
- alias
161
- }
162
- }
163
- message {
164
- text
165
- }
166
- }
167
- }
168
- "
169
- `)
170
- expect(calls[0].variables).toMatchInlineSnapshot(`
171
- {
172
- "AuthorCreateInput_1": {
173
- "email": "xx@localhost",
174
- "name": "John",
175
- },
176
- "MutationTransactionOptions_0": {},
177
- }
178
- `)
50
+ expect(calls[0].query).toMatchSnapshot()
51
+ expect(calls[0].variables).toMatchSnapshot()
179
52
  })
180
53
 
181
54
  test('update', async () => {
@@ -195,8 +68,129 @@ describe('mutations in trx', () => {
195
68
  },
196
69
  })))
197
70
  expect(calls).toHaveLength(1)
198
- expect(calls[0].query).toMatchInlineSnapshot(`
199
- "mutation($MutationTransactionOptions_0: MutationTransactionOptions, $AuthorUniqueWhere_1: AuthorUniqueWhere!, $AuthorUpdateInput_2: AuthorUpdateInput!) {
71
+ expect(calls[0].query).toMatchSnapshot()
72
+ expect(calls[0].variables).toMatchSnapshot()
73
+ })
74
+
75
+ test('delete', async () => {
76
+ const [client, calls] = createClient({
77
+ mut: {
78
+ ok: true,
79
+ mut: {
80
+ ok: true,
81
+ },
82
+ },
83
+ })
84
+ await client.mutate(qb.transaction(qb.delete('Author', {
85
+ by: { id: 'ca7a9b84-efbb-435d-a063-da11f205335a' },
86
+ })))
87
+ expect(calls).toHaveLength(1)
88
+ expect(calls[0].query).toMatchSnapshot()
89
+ expect(calls[0].variables).toMatchSnapshot()
90
+ })
91
+
92
+ test('upsert', async () => {
93
+ const [client, calls] = createClient({
94
+ mut: {
95
+ ok: true,
96
+ mut: {
97
+ ok: true,
98
+ },
99
+ },
100
+ })
101
+ await client.mutate(qb.transaction(qb.upsert('Author', {
102
+ by: { id: 'ca7a9b84-efbb-435d-a063-da11f205335a' },
103
+ create: {
104
+ name: 'John',
105
+ email: 'xx@localhost',
106
+ },
107
+ update: {
108
+ name: 'John',
109
+ email: 'xx@localhost',
110
+ },
111
+ })))
112
+ expect(calls).toHaveLength(1)
113
+ expect(calls[0].query).toMatchSnapshot()
114
+ expect(calls[0].variables).toMatchSnapshot()
115
+ })
116
+
117
+ test('multiple mutations as array', async () => {
118
+ const [client, calls] = createClient({
119
+ mut: {
120
+ ok: true,
121
+ mut_0: {
122
+ ok: true,
123
+ },
124
+ mut_1: {
125
+ ok: true,
126
+ },
127
+ },
128
+ })
129
+ const result = await client.mutate(qb.transaction([
130
+ qb.create('Author', {
131
+ data: {
132
+ name: 'John',
133
+ email: 'xx@localhost',
134
+ },
135
+ }),
136
+ qb.create('Author', {
137
+ data: {
138
+ name: 'John',
139
+ email: 'xx@localhost',
140
+ },
141
+ }),
142
+ ]))
143
+ expect(result.ok).toBe(true)
144
+ expect(result.data).toHaveLength(2)
145
+ expect(result.data[0].ok).toBe(true)
146
+ expect(result.data[1].ok).toBe(true)
147
+ expect(calls).toHaveLength(1)
148
+ expect(calls[0].query).toMatchSnapshot()
149
+ expect(calls[0].variables).toMatchSnapshot(`
150
+ {
151
+ "AuthorCreateInput_1": {
152
+ "email": "xx@localhost",
153
+ "name": "John",
154
+ },
155
+ "AuthorCreateInput_2": {
156
+ "email": "xx@localhost",
157
+ "name": "John",
158
+ },
159
+ "MutationTransactionOptions_0": {},
160
+ }
161
+ `)
162
+ })
163
+
164
+ test('multiple named mutations trx', async () => {
165
+ const [client, calls] = createClient({
166
+ mut: {
167
+ ok: true,
168
+ createAuthor: {
169
+ ok: true,
170
+ },
171
+ createPost: {
172
+ ok: true,
173
+ },
174
+ },
175
+ })
176
+ const result = await client.mutate(qb.transaction({
177
+ createAuthor: qb.create('Author', {
178
+ data: {
179
+ name: 'John',
180
+ email: 'xx@localhost',
181
+ },
182
+ }),
183
+ createPost: qb.create('Post', {
184
+ data: {
185
+ publishedAt: 'now',
186
+ },
187
+ }),
188
+ }))
189
+ expect(result.data.createAuthor.ok).toBe(true)
190
+ expect(result.data.createPost.ok).toBe(true)
191
+ expect(calls).toHaveLength(1)
192
+ expect(calls[0].query).toMatchSnapshot(`
193
+ "mutation($MutationTransactionOptions_0: MutationTransactionOptions, $AuthorCreateInput_1: AuthorCreateInput!, $PostCreateInput_2: PostCreateInput!) {
200
194
  mut: transaction(options: $MutationTransactionOptions_0) {
201
195
  ok
202
196
  errorMessage
@@ -206,7 +200,17 @@ describe('mutations in trx', () => {
206
200
  validation {
207
201
  ... ValidationResult
208
202
  }
209
- mut: updateAuthor(by: $AuthorUniqueWhere_1, data: $AuthorUpdateInput_2) {
203
+ createAuthor(data: $AuthorCreateInput_1) {
204
+ ok
205
+ errorMessage
206
+ errors {
207
+ ... MutationError
208
+ }
209
+ validation {
210
+ ... ValidationResult
211
+ }
212
+ }
213
+ createPost(data: $PostCreateInput_2) {
210
214
  ok
211
215
  errorMessage
212
216
  errors {
@@ -250,854 +254,150 @@ describe('mutations in trx', () => {
250
254
  }
251
255
  "
252
256
  `)
253
- expect(calls[0].variables).toMatchInlineSnapshot(`
257
+ expect(calls[0].variables).toMatchSnapshot(`
254
258
  {
255
- "AuthorUniqueWhere_1": {
256
- "id": "ca7a9b84-efbb-435d-a063-da11f205335a",
257
- },
258
- "AuthorUpdateInput_2": {
259
+ "AuthorCreateInput_1": {
259
260
  "email": "xx@localhost",
260
261
  "name": "John",
261
262
  },
262
263
  "MutationTransactionOptions_0": {},
264
+ "PostCreateInput_2": {
265
+ "publishedAt": "now",
266
+ },
263
267
  }
264
268
  `)
265
269
  })
266
270
 
267
- test('delete', async () => {
271
+ test('mutation and query combo trx', async () => {
268
272
  const [client, calls] = createClient({
269
273
  mut: {
270
274
  ok: true,
271
- mut: {
275
+ createPost: {
272
276
  ok: true,
273
277
  },
274
- },
275
- })
276
- await client.mutate(qb.transaction(qb.delete('Author', {
277
- by: { id: 'ca7a9b84-efbb-435d-a063-da11f205335a' },
278
- })))
279
- expect(calls).toHaveLength(1)
280
- expect(calls[0].query).toMatchInlineSnapshot(`
281
- "mutation($MutationTransactionOptions_0: MutationTransactionOptions, $AuthorUniqueWhere_1: AuthorUniqueWhere!) {
282
- mut: transaction(options: $MutationTransactionOptions_0) {
283
- ok
284
- errorMessage
285
- errors {
286
- ... MutationError
287
- }
288
- validation {
289
- ... ValidationResult
290
- }
291
- mut: deleteAuthor(by: $AuthorUniqueWhere_1) {
292
- ok
293
- errorMessage
294
- errors {
295
- ... MutationError
296
- }
297
- }
298
- }
299
- }
300
- fragment MutationError on _MutationError {
301
- paths {
302
- ... on _FieldPathFragment {
303
- field
304
- }
305
- ... on _IndexPathFragment {
306
- index
307
- alias
308
- }
309
- }
310
- message
311
- type
312
- }
313
- fragment ValidationResult on _ValidationResult {
314
- valid
315
- errors {
316
- path {
317
- ... on _FieldPathFragment {
318
- field
319
- }
320
- ... on _IndexPathFragment {
321
- index
322
- alias
323
- }
324
- }
325
- message {
326
- text
327
- }
328
- }
329
- }
330
- "
331
- `)
332
- expect(calls[0].variables).toMatchInlineSnapshot(`
333
- {
334
- "AuthorUniqueWhere_1": {
335
- "id": "ca7a9b84-efbb-435d-a063-da11f205335a",
336
- },
337
- "MutationTransactionOptions_0": {},
338
- }
339
- `)
340
- })
341
-
342
- test('upsert', async () => {
343
- const [client, calls] = createClient({
344
- mut: {
345
- ok: true,
346
- mut: {
347
- ok: true,
348
- },
349
- },
350
- })
351
- await client.mutate(qb.transaction(qb.upsert('Author', {
352
- by: { id: 'ca7a9b84-efbb-435d-a063-da11f205335a' },
353
- create: {
354
- name: 'John',
355
- email: 'xx@localhost',
356
- },
357
- update: {
358
- name: 'John',
359
- email: 'xx@localhost',
360
- },
361
- })))
362
- expect(calls).toHaveLength(1)
363
- expect(calls[0].query).toMatchInlineSnapshot(`
364
- "mutation($MutationTransactionOptions_0: MutationTransactionOptions, $AuthorUniqueWhere_1: AuthorUniqueWhere!, $AuthorCreateInput_2: AuthorCreateInput!, $AuthorUpdateInput_3: AuthorUpdateInput!) {
365
- mut: transaction(options: $MutationTransactionOptions_0) {
366
- ok
367
- errorMessage
368
- errors {
369
- ... MutationError
370
- }
371
- validation {
372
- ... ValidationResult
373
- }
374
- mut: upsertAuthor(by: $AuthorUniqueWhere_1, create: $AuthorCreateInput_2, update: $AuthorUpdateInput_3) {
375
- ok
376
- errorMessage
377
- errors {
378
- ... MutationError
379
- }
380
- validation {
381
- ... ValidationResult
382
- }
383
- }
384
- }
385
- }
386
- fragment MutationError on _MutationError {
387
- paths {
388
- ... on _FieldPathFragment {
389
- field
390
- }
391
- ... on _IndexPathFragment {
392
- index
393
- alias
394
- }
395
- }
396
- message
397
- type
398
- }
399
- fragment ValidationResult on _ValidationResult {
400
- valid
401
- errors {
402
- path {
403
- ... on _FieldPathFragment {
404
- field
405
- }
406
- ... on _IndexPathFragment {
407
- index
408
- alias
409
- }
410
- }
411
- message {
412
- text
413
- }
414
- }
415
- }
416
- "
417
- `)
418
- expect(calls[0].variables).toMatchInlineSnapshot(`
419
- {
420
- "AuthorCreateInput_2": {
421
- "email": "xx@localhost",
422
- "name": "John",
423
- },
424
- "AuthorUniqueWhere_1": {
425
- "id": "ca7a9b84-efbb-435d-a063-da11f205335a",
426
- },
427
- "AuthorUpdateInput_3": {
428
- "email": "xx@localhost",
429
- "name": "John",
430
- },
431
- "MutationTransactionOptions_0": {},
432
- }
433
- `)
434
- })
435
-
436
- test('multiple mutations as array', async () => {
437
- const [client, calls] = createClient({
438
- mut: {
439
- ok: true,
440
- mut_0: {
441
- ok: true,
442
- },
443
- mut_1: {
444
- ok: true,
445
- },
446
- },
447
- })
448
- const result = await client.mutate(qb.transaction([
449
- qb.create('Author', {
450
- data: {
451
- name: 'John',
452
- email: 'xx@localhost',
453
- },
454
- }),
455
- qb.create('Author', {
456
- data: {
457
- name: 'John',
458
- email: 'xx@localhost',
459
- },
460
- }),
461
- ]))
462
- expect(result.ok).toBe(true)
463
- expect(result.data).toHaveLength(2)
464
- expect(result.data[0].ok).toBe(true)
465
- expect(result.data[1].ok).toBe(true)
466
- expect(calls).toHaveLength(1)
467
- expect(calls[0].query).toMatchInlineSnapshot(`
468
- "mutation($MutationTransactionOptions_0: MutationTransactionOptions, $AuthorCreateInput_1: AuthorCreateInput!, $AuthorCreateInput_2: AuthorCreateInput!) {
469
- mut: transaction(options: $MutationTransactionOptions_0) {
470
- ok
471
- errorMessage
472
- errors {
473
- ... MutationError
474
- }
475
- validation {
476
- ... ValidationResult
477
- }
478
- mut_0: createAuthor(data: $AuthorCreateInput_1) {
479
- ok
480
- errorMessage
481
- errors {
482
- ... MutationError
483
- }
484
- validation {
485
- ... ValidationResult
486
- }
487
- }
488
- mut_1: createAuthor(data: $AuthorCreateInput_2) {
489
- ok
490
- errorMessage
491
- errors {
492
- ... MutationError
493
- }
494
- validation {
495
- ... ValidationResult
496
- }
497
- }
498
- }
499
- }
500
- fragment MutationError on _MutationError {
501
- paths {
502
- ... on _FieldPathFragment {
503
- field
504
- }
505
- ... on _IndexPathFragment {
506
- index
507
- alias
508
- }
509
- }
510
- message
511
- type
512
- }
513
- fragment ValidationResult on _ValidationResult {
514
- valid
515
- errors {
516
- path {
517
- ... on _FieldPathFragment {
518
- field
519
- }
520
- ... on _IndexPathFragment {
521
- index
522
- alias
523
- }
524
- }
525
- message {
526
- text
527
- }
528
- }
529
- }
530
- "
531
- `)
532
- expect(calls[0].variables).toMatchInlineSnapshot(`
533
- {
534
- "AuthorCreateInput_1": {
535
- "email": "xx@localhost",
536
- "name": "John",
537
- },
538
- "AuthorCreateInput_2": {
539
- "email": "xx@localhost",
540
- "name": "John",
541
- },
542
- "MutationTransactionOptions_0": {},
543
- }
544
- `)
545
- })
546
-
547
- test('multiple named mutations trx', async () => {
548
- const [client, calls] = createClient({
549
- mut: {
550
- ok: true,
551
- createAuthor: {
552
- ok: true,
553
- },
554
- createPost: {
555
- ok: true,
556
- },
557
- },
558
- })
559
- const result = await client.mutate(qb.transaction({
560
- createAuthor: qb.create('Author', {
561
- data: {
562
- name: 'John',
563
- email: 'xx@localhost',
564
- },
565
- }),
566
- createPost: qb.create('Post', {
567
- data: {
568
- publishedAt: 'now',
569
- },
570
- }),
571
- }))
572
- expect(result.data.createAuthor.ok).toBe(true)
573
- expect(result.data.createPost.ok).toBe(true)
574
- expect(calls).toHaveLength(1)
575
- expect(calls[0].query).toMatchInlineSnapshot(`
576
- "mutation($MutationTransactionOptions_0: MutationTransactionOptions, $AuthorCreateInput_1: AuthorCreateInput!, $PostCreateInput_2: PostCreateInput!) {
577
- mut: transaction(options: $MutationTransactionOptions_0) {
578
- ok
579
- errorMessage
580
- errors {
581
- ... MutationError
582
- }
583
- validation {
584
- ... ValidationResult
585
- }
586
- createAuthor(data: $AuthorCreateInput_1) {
587
- ok
588
- errorMessage
589
- errors {
590
- ... MutationError
591
- }
592
- validation {
593
- ... ValidationResult
594
- }
595
- }
596
- createPost(data: $PostCreateInput_2) {
597
- ok
598
- errorMessage
599
- errors {
600
- ... MutationError
601
- }
602
- validation {
603
- ... ValidationResult
604
- }
605
- }
606
- }
607
- }
608
- fragment MutationError on _MutationError {
609
- paths {
610
- ... on _FieldPathFragment {
611
- field
612
- }
613
- ... on _IndexPathFragment {
614
- index
615
- alias
616
- }
617
- }
618
- message
619
- type
620
- }
621
- fragment ValidationResult on _ValidationResult {
622
- valid
623
- errors {
624
- path {
625
- ... on _FieldPathFragment {
626
- field
627
- }
628
- ... on _IndexPathFragment {
629
- index
630
- alias
631
- }
632
- }
633
- message {
634
- text
635
- }
636
- }
637
- }
638
- "
639
- `)
640
- expect(calls[0].variables).toMatchInlineSnapshot(`
641
- {
642
- "AuthorCreateInput_1": {
643
- "email": "xx@localhost",
644
- "name": "John",
645
- },
646
- "MutationTransactionOptions_0": {},
647
- "PostCreateInput_2": {
648
- "publishedAt": "now",
649
- },
650
- }
651
- `)
652
- })
653
-
654
- test('mutation and query combo trx', async () => {
655
- const [client, calls] = createClient({
656
- mut: {
657
- ok: true,
658
- createPost: {
659
- ok: true,
660
- },
661
- post: {
662
- value: {
663
- id: 'ca7a9b84-efbb-435d-a063-da11f205335a',
664
- publishedAt: 'now',
665
- },
666
- },
667
- },
668
- })
669
-
670
- const trx = qb.transaction({
671
- createPost: qb.create('Post', {
672
- data: {
673
- publishedAt: 'now',
674
- },
675
- }),
676
- post: qb.get('Post', {
677
- by: { id: 'ca7a9b84-efbb-435d-a063-da11f205335a' },
678
- }, it => it.$$()),
679
- })
680
- const result = await client.mutate(trx)
681
- expect(result.data.createPost.ok).toBe(true)
682
- expect(result.data.post?.publishedAt).toBe('now')
683
-
684
- expect(calls).toHaveLength(1)
685
- expect(calls[0].query).toMatchInlineSnapshot(`
686
- "mutation($MutationTransactionOptions_0: MutationTransactionOptions, $PostCreateInput_1: PostCreateInput!, $PostUniqueWhere_2: PostUniqueWhere!) {
687
- mut: transaction(options: $MutationTransactionOptions_0) {
688
- ok
689
- errorMessage
690
- errors {
691
- ... MutationError
692
- }
693
- validation {
694
- ... ValidationResult
695
- }
696
- createPost(data: $PostCreateInput_1) {
697
- ok
698
- errorMessage
699
- errors {
700
- ... MutationError
701
- }
702
- validation {
703
- ... ValidationResult
704
- }
705
- }
706
- post: query {
707
- value: getPost(by: $PostUniqueWhere_2) {
708
- id
709
- publishedAt
710
- }
711
- }
712
- }
713
- }
714
- fragment MutationError on _MutationError {
715
- paths {
716
- ... on _FieldPathFragment {
717
- field
718
- }
719
- ... on _IndexPathFragment {
720
- index
721
- alias
722
- }
723
- }
724
- message
725
- type
726
- }
727
- fragment ValidationResult on _ValidationResult {
728
- valid
729
- errors {
730
- path {
731
- ... on _FieldPathFragment {
732
- field
733
- }
734
- ... on _IndexPathFragment {
735
- index
736
- alias
737
- }
738
- }
739
- message {
740
- text
741
- }
742
- }
743
- }
744
- "
745
- `)
746
- expect(calls[0].variables).toMatchInlineSnapshot(`
747
- {
748
- "MutationTransactionOptions_0": {},
749
- "PostCreateInput_1": {
750
- "publishedAt": "now",
751
- },
752
- "PostUniqueWhere_2": {
753
- "id": "ca7a9b84-efbb-435d-a063-da11f205335a",
754
- },
755
- }
756
- `)
757
- })
758
-
759
- })
760
- describe('mutations without trx', () => {
761
- test('create', async () => {
762
- const [client, calls] = createClient({
763
- mut: {
764
- ok: true,
765
- },
766
- })
767
- const createAuthor = qb.create('Author', {
768
- data: {
769
- name: 'John',
770
- email: 'xx@localhost',
771
- },
772
- })
773
- const result = await client.mutate(createAuthor)
774
-
775
-
776
- expect(result.ok).toBe(true)
777
- expect(calls).toHaveLength(1)
778
- expect(calls[0].query).toMatchInlineSnapshot(`
779
- "mutation($AuthorCreateInput_0: AuthorCreateInput!) {
780
- mut: createAuthor(data: $AuthorCreateInput_0) {
781
- ok
782
- errorMessage
783
- errors {
784
- ... MutationError
785
- }
786
- validation {
787
- ... ValidationResult
788
- }
789
- }
790
- }
791
- fragment MutationError on _MutationError {
792
- paths {
793
- ... on _FieldPathFragment {
794
- field
795
- }
796
- ... on _IndexPathFragment {
797
- index
798
- alias
799
- }
800
- }
801
- message
802
- type
803
- }
804
- fragment ValidationResult on _ValidationResult {
805
- valid
806
- errors {
807
- path {
808
- ... on _FieldPathFragment {
809
- field
810
- }
811
- ... on _IndexPathFragment {
812
- index
813
- alias
814
- }
815
- }
816
- message {
817
- text
818
- }
819
- }
820
- }
821
- "
822
- `)
823
- expect(calls[0].variables).toMatchInlineSnapshot(`
824
- {
825
- "AuthorCreateInput_0": {
826
- "email": "xx@localhost",
827
- "name": "John",
828
- },
829
- }
830
- `)
278
+ post: {
279
+ value: {
280
+ id: 'ca7a9b84-efbb-435d-a063-da11f205335a',
281
+ publishedAt: 'now',
282
+ },
283
+ },
284
+ },
285
+ })
286
+
287
+ const trx = qb.transaction({
288
+ createPost: qb.create('Post', {
289
+ data: {
290
+ publishedAt: 'now',
291
+ },
292
+ }),
293
+ post: qb.get('Post', {
294
+ by: { id: 'ca7a9b84-efbb-435d-a063-da11f205335a' },
295
+ }, it => it.$$()),
296
+ })
297
+ const result = await client.mutate(trx)
298
+ expect(result.data.createPost.ok).toBe(true)
299
+ expect(result.data.post?.publishedAt).toBe('now')
300
+
301
+ expect(calls).toHaveLength(1)
302
+ expect(calls[0].query).toMatchSnapshot()
303
+ expect(calls[0].variables).toMatchSnapshot()
831
304
  })
832
305
 
833
- test('mutation with a node', async () => {
306
+ })
307
+ describe('mutations without trx', () => {
308
+ test('create', async () => {
834
309
  const [client, calls] = createClient({
835
310
  mut: {
836
311
  ok: true,
837
- node: { id: 'ca7a9b84-efbb-435d-a063-da11f205335a' },
838
312
  },
839
313
  })
840
- const result = await client.mutate(qb.create('Author', {
314
+ const createAuthor = qb.create('Author', {
841
315
  data: {
842
316
  name: 'John',
843
317
  email: 'xx@localhost',
844
318
  },
845
- }, it => it.$('id')))
319
+ })
320
+ const result = await client.mutate(createAuthor)
321
+
322
+
846
323
  expect(result.ok).toBe(true)
847
- expect(result.node?.id).toBe('ca7a9b84-efbb-435d-a063-da11f205335a')
848
324
  expect(calls).toHaveLength(1)
849
- expect(calls[0].query).toMatchInlineSnapshot(`
850
- "mutation($AuthorCreateInput_0: AuthorCreateInput!) {
851
- mut: createAuthor(data: $AuthorCreateInput_0) {
852
- ok
853
- errorMessage
854
- errors {
855
- ... MutationError
856
- }
857
- validation {
858
- ... ValidationResult
859
- }
860
- node {
861
- id
862
- }
863
- }
864
- }
865
- fragment MutationError on _MutationError {
866
- paths {
867
- ... on _FieldPathFragment {
868
- field
869
- }
870
- ... on _IndexPathFragment {
871
- index
872
- alias
873
- }
874
- }
875
- message
876
- type
877
- }
878
- fragment ValidationResult on _ValidationResult {
879
- valid
880
- errors {
881
- path {
882
- ... on _FieldPathFragment {
883
- field
884
- }
885
- ... on _IndexPathFragment {
886
- index
887
- alias
888
- }
889
- }
890
- message {
891
- text
892
- }
893
- }
894
- }
895
- "
896
- `)
897
- expect(calls[0].variables).toMatchInlineSnapshot(`
898
- {
899
- "AuthorCreateInput_0": {
900
- "email": "xx@localhost",
901
- "name": "John",
902
- },
903
- }
904
- `)
325
+ expect(calls[0].query).toMatchSnapshot()
326
+ expect(calls[0].variables).toMatchSnapshot()
905
327
  })
906
328
 
907
- test('update', async () => {
329
+ test('mutation with a node', async () => {
908
330
  const [client, calls] = createClient({
909
331
  mut: {
910
332
  ok: true,
333
+ node: { id: 'ca7a9b84-efbb-435d-a063-da11f205335a' },
911
334
  },
912
335
  })
913
- await client.mutate(qb.update('Author', {
914
- by: { id: 'ca7a9b84-efbb-435d-a063-da11f205335a' },
336
+ const result = await client.mutate(qb.create('Author', {
915
337
  data: {
916
338
  name: 'John',
917
339
  email: 'xx@localhost',
918
340
  },
919
- }))
920
- expect(calls).toHaveLength(1)
921
- expect(calls[0].query).toMatchInlineSnapshot(`
922
- "mutation($AuthorUniqueWhere_0: AuthorUniqueWhere!, $AuthorUpdateInput_1: AuthorUpdateInput!) {
923
- mut: updateAuthor(by: $AuthorUniqueWhere_0, data: $AuthorUpdateInput_1) {
924
- ok
925
- errorMessage
926
- errors {
927
- ... MutationError
928
- }
929
- validation {
930
- ... ValidationResult
931
- }
932
- }
933
- }
934
- fragment MutationError on _MutationError {
935
- paths {
936
- ... on _FieldPathFragment {
937
- field
938
- }
939
- ... on _IndexPathFragment {
940
- index
941
- alias
942
- }
943
- }
944
- message
945
- type
946
- }
947
- fragment ValidationResult on _ValidationResult {
948
- valid
949
- errors {
950
- path {
951
- ... on _FieldPathFragment {
952
- field
953
- }
954
- ... on _IndexPathFragment {
955
- index
956
- alias
957
- }
958
- }
959
- message {
960
- text
961
- }
962
- }
963
- }
964
- "
965
- `)
966
- expect(calls[0].variables).toMatchInlineSnapshot(`
967
- {
968
- "AuthorUniqueWhere_0": {
969
- "id": "ca7a9b84-efbb-435d-a063-da11f205335a",
970
- },
971
- "AuthorUpdateInput_1": {
972
- "email": "xx@localhost",
973
- "name": "John",
974
- },
975
- }
976
- `)
977
- })
978
-
979
- test('delete', async () => {
980
- const [client, calls] = createClient({
981
- mut: {
982
- ok: true,
983
- },
984
- })
985
- await client.mutate(qb.delete('Author', {
986
- by: { id: 'ca7a9b84-efbb-435d-a063-da11f205335a' },
987
- }))
341
+ }, it => it.$('id')))
342
+ expect(result.ok).toBe(true)
343
+ expect(result.node?.id).toBe('ca7a9b84-efbb-435d-a063-da11f205335a')
988
344
  expect(calls).toHaveLength(1)
989
- expect(calls[0].query).toMatchInlineSnapshot(`
990
- "mutation($AuthorUniqueWhere_0: AuthorUniqueWhere!) {
991
- mut: deleteAuthor(by: $AuthorUniqueWhere_0) {
992
- ok
993
- errorMessage
994
- errors {
995
- ... MutationError
996
- }
997
- }
998
- }
999
- fragment MutationError on _MutationError {
1000
- paths {
1001
- ... on _FieldPathFragment {
1002
- field
1003
- }
1004
- ... on _IndexPathFragment {
1005
- index
1006
- alias
1007
- }
1008
- }
1009
- message
1010
- type
1011
- }
1012
- "
1013
- `)
1014
- expect(calls[0].variables).toMatchInlineSnapshot(`
1015
- {
1016
- "AuthorUniqueWhere_0": {
1017
- "id": "ca7a9b84-efbb-435d-a063-da11f205335a",
1018
- },
1019
- }
1020
- `)
345
+ expect(calls[0].query).toMatchSnapshot()
346
+ expect(calls[0].variables).toMatchSnapshot()
1021
347
  })
1022
348
 
1023
- test('upsert', async () => {
349
+ test('update', async () => {
1024
350
  const [client, calls] = createClient({
1025
351
  mut: {
1026
352
  ok: true,
1027
353
  },
1028
354
  })
1029
- await client.mutate(qb.upsert('Author', {
355
+ await client.mutate(qb.update('Author', {
1030
356
  by: { id: 'ca7a9b84-efbb-435d-a063-da11f205335a' },
1031
- create: {
1032
- name: 'John',
1033
- email: 'xx@localhost',
1034
- },
1035
- update: {
1036
- name: 'John',
1037
- email: 'xx@localhost',
1038
- },
1039
- }))
1040
- expect(calls).toHaveLength(1)
1041
- expect(calls[0].query).toMatchInlineSnapshot(`
1042
- "mutation($AuthorUniqueWhere_0: AuthorUniqueWhere!, $AuthorCreateInput_1: AuthorCreateInput!, $AuthorUpdateInput_2: AuthorUpdateInput!) {
1043
- mut: upsertAuthor(by: $AuthorUniqueWhere_0, create: $AuthorCreateInput_1, update: $AuthorUpdateInput_2) {
1044
- ok
1045
- errorMessage
1046
- errors {
1047
- ... MutationError
1048
- }
1049
- validation {
1050
- ... ValidationResult
1051
- }
1052
- }
1053
- }
1054
- fragment MutationError on _MutationError {
1055
- paths {
1056
- ... on _FieldPathFragment {
1057
- field
1058
- }
1059
- ... on _IndexPathFragment {
1060
- index
1061
- alias
1062
- }
1063
- }
1064
- message
1065
- type
1066
- }
1067
- fragment ValidationResult on _ValidationResult {
1068
- valid
1069
- errors {
1070
- path {
1071
- ... on _FieldPathFragment {
1072
- field
1073
- }
1074
- ... on _IndexPathFragment {
1075
- index
1076
- alias
1077
- }
1078
- }
1079
- message {
1080
- text
1081
- }
1082
- }
1083
- }
1084
- "
1085
- `)
1086
- expect(calls[0].variables).toMatchInlineSnapshot(`
1087
- {
1088
- "AuthorCreateInput_1": {
1089
- "email": "xx@localhost",
1090
- "name": "John",
1091
- },
1092
- "AuthorUniqueWhere_0": {
1093
- "id": "ca7a9b84-efbb-435d-a063-da11f205335a",
1094
- },
1095
- "AuthorUpdateInput_2": {
1096
- "email": "xx@localhost",
1097
- "name": "John",
1098
- },
1099
- }
1100
- `)
357
+ data: {
358
+ name: 'John',
359
+ email: 'xx@localhost',
360
+ },
361
+ }))
362
+ expect(calls).toHaveLength(1)
363
+ expect(calls[0].query).toMatchSnapshot()
364
+ expect(calls[0].variables).toMatchSnapshot()
365
+ })
366
+
367
+ test('delete', async () => {
368
+ const [client, calls] = createClient({
369
+ mut: {
370
+ ok: true,
371
+ },
372
+ })
373
+ await client.mutate(qb.delete('Author', {
374
+ by: { id: 'ca7a9b84-efbb-435d-a063-da11f205335a' },
375
+ }))
376
+ expect(calls).toHaveLength(1)
377
+ expect(calls[0].query).toMatchSnapshot()
378
+ expect(calls[0].variables).toMatchSnapshot()
379
+ })
380
+
381
+ test('upsert', async () => {
382
+ const [client, calls] = createClient({
383
+ mut: {
384
+ ok: true,
385
+ },
386
+ })
387
+ await client.mutate(qb.upsert('Author', {
388
+ by: { id: 'ca7a9b84-efbb-435d-a063-da11f205335a' },
389
+ create: {
390
+ name: 'John',
391
+ email: 'xx@localhost',
392
+ },
393
+ update: {
394
+ name: 'John',
395
+ email: 'xx@localhost',
396
+ },
397
+ }))
398
+ expect(calls).toHaveLength(1)
399
+ expect(calls[0].query).toMatchSnapshot()
400
+ expect(calls[0].variables).toMatchSnapshot()
1101
401
  })
1102
402
 
1103
403
  test('multiple mutations as array', async () => {
@@ -1127,73 +427,8 @@ describe('mutations without trx', () => {
1127
427
  expect(result[0].ok).toBe(true)
1128
428
  expect(result[1].ok).toBe(true)
1129
429
  expect(calls).toHaveLength(1)
1130
- expect(calls[0].query).toMatchInlineSnapshot(`
1131
- "mutation($AuthorCreateInput_0: AuthorCreateInput!, $AuthorCreateInput_1: AuthorCreateInput!) {
1132
- mut_0: createAuthor(data: $AuthorCreateInput_0) {
1133
- ok
1134
- errorMessage
1135
- errors {
1136
- ... MutationError
1137
- }
1138
- validation {
1139
- ... ValidationResult
1140
- }
1141
- }
1142
- mut_1: createAuthor(data: $AuthorCreateInput_1) {
1143
- ok
1144
- errorMessage
1145
- errors {
1146
- ... MutationError
1147
- }
1148
- validation {
1149
- ... ValidationResult
1150
- }
1151
- }
1152
- }
1153
- fragment MutationError on _MutationError {
1154
- paths {
1155
- ... on _FieldPathFragment {
1156
- field
1157
- }
1158
- ... on _IndexPathFragment {
1159
- index
1160
- alias
1161
- }
1162
- }
1163
- message
1164
- type
1165
- }
1166
- fragment ValidationResult on _ValidationResult {
1167
- valid
1168
- errors {
1169
- path {
1170
- ... on _FieldPathFragment {
1171
- field
1172
- }
1173
- ... on _IndexPathFragment {
1174
- index
1175
- alias
1176
- }
1177
- }
1178
- message {
1179
- text
1180
- }
1181
- }
1182
- }
1183
- "
1184
- `)
1185
- expect(calls[0].variables).toMatchInlineSnapshot(`
1186
- {
1187
- "AuthorCreateInput_0": {
1188
- "email": "xx@localhost",
1189
- "name": "John",
1190
- },
1191
- "AuthorCreateInput_1": {
1192
- "email": "xx@localhost",
1193
- "name": "John",
1194
- },
1195
- }
1196
- `)
430
+ expect(calls[0].query).toMatchSnapshot()
431
+ expect(calls[0].variables).toMatchSnapshot()
1197
432
  })
1198
433
 
1199
434
  test('multiple named mutations', async () => {
@@ -1221,72 +456,8 @@ describe('mutations without trx', () => {
1221
456
  expect(result.createAuthor.ok).toBe(true)
1222
457
  expect(result.createPost.ok).toBe(true)
1223
458
  expect(calls).toHaveLength(1)
1224
- expect(calls[0].query).toMatchInlineSnapshot(`
1225
- "mutation($AuthorCreateInput_0: AuthorCreateInput!, $PostCreateInput_1: PostCreateInput!) {
1226
- createAuthor(data: $AuthorCreateInput_0) {
1227
- ok
1228
- errorMessage
1229
- errors {
1230
- ... MutationError
1231
- }
1232
- validation {
1233
- ... ValidationResult
1234
- }
1235
- }
1236
- createPost(data: $PostCreateInput_1) {
1237
- ok
1238
- errorMessage
1239
- errors {
1240
- ... MutationError
1241
- }
1242
- validation {
1243
- ... ValidationResult
1244
- }
1245
- }
1246
- }
1247
- fragment MutationError on _MutationError {
1248
- paths {
1249
- ... on _FieldPathFragment {
1250
- field
1251
- }
1252
- ... on _IndexPathFragment {
1253
- index
1254
- alias
1255
- }
1256
- }
1257
- message
1258
- type
1259
- }
1260
- fragment ValidationResult on _ValidationResult {
1261
- valid
1262
- errors {
1263
- path {
1264
- ... on _FieldPathFragment {
1265
- field
1266
- }
1267
- ... on _IndexPathFragment {
1268
- index
1269
- alias
1270
- }
1271
- }
1272
- message {
1273
- text
1274
- }
1275
- }
1276
- }
1277
- "
1278
- `)
1279
- expect(calls[0].variables).toMatchInlineSnapshot(`
1280
- {
1281
- "AuthorCreateInput_0": {
1282
- "email": "xx@localhost",
1283
- "name": "John",
1284
- },
1285
- "PostCreateInput_1": {
1286
- "publishedAt": "now",
1287
- },
1288
- }
1289
- `)
459
+ expect(calls[0].query).toMatchSnapshot()
460
+ expect(calls[0].variables).toMatchSnapshot()
1290
461
  })
1291
462
 
1292
463
  test('mutation and query combo', async () => {
@@ -1316,67 +487,8 @@ describe('mutations without trx', () => {
1316
487
  expect(result.post?.publishedAt).toBe('now')
1317
488
 
1318
489
  expect(calls).toHaveLength(1)
1319
- expect(calls[0].query).toMatchInlineSnapshot(`
1320
- "mutation($PostCreateInput_0: PostCreateInput!, $PostUniqueWhere_1: PostUniqueWhere!) {
1321
- createPost(data: $PostCreateInput_0) {
1322
- ok
1323
- errorMessage
1324
- errors {
1325
- ... MutationError
1326
- }
1327
- validation {
1328
- ... ValidationResult
1329
- }
1330
- }
1331
- post: query {
1332
- value: getPost(by: $PostUniqueWhere_1) {
1333
- id
1334
- publishedAt
1335
- }
1336
- }
1337
- }
1338
- fragment MutationError on _MutationError {
1339
- paths {
1340
- ... on _FieldPathFragment {
1341
- field
1342
- }
1343
- ... on _IndexPathFragment {
1344
- index
1345
- alias
1346
- }
1347
- }
1348
- message
1349
- type
1350
- }
1351
- fragment ValidationResult on _ValidationResult {
1352
- valid
1353
- errors {
1354
- path {
1355
- ... on _FieldPathFragment {
1356
- field
1357
- }
1358
- ... on _IndexPathFragment {
1359
- index
1360
- alias
1361
- }
1362
- }
1363
- message {
1364
- text
1365
- }
1366
- }
1367
- }
1368
- "
1369
- `)
1370
- expect(calls[0].variables).toMatchInlineSnapshot(`
1371
- {
1372
- "PostCreateInput_0": {
1373
- "publishedAt": "now",
1374
- },
1375
- "PostUniqueWhere_1": {
1376
- "id": "ca7a9b84-efbb-435d-a063-da11f205335a",
1377
- },
1378
- }
1379
- `)
490
+ expect(calls[0].query).toMatchSnapshot()
491
+ expect(calls[0].variables).toMatchSnapshot()
1380
492
  })
1381
493
 
1382
494
  test('update locale relation', async () => {
@@ -1402,75 +514,8 @@ describe('mutations without trx', () => {
1402
514
  }))
1403
515
  expect(result.ok).toBe(true)
1404
516
  expect(calls).toHaveLength(1)
1405
- expect(calls[0].query).toMatchInlineSnapshot(`
1406
- "mutation($PostUniqueWhere_0: PostUniqueWhere!, $PostUpdateInput_1: PostUpdateInput!) {
1407
- mut: updatePost(by: $PostUniqueWhere_0, data: $PostUpdateInput_1) {
1408
- ok
1409
- errorMessage
1410
- errors {
1411
- ... MutationError
1412
- }
1413
- validation {
1414
- ... ValidationResult
1415
- }
1416
- }
1417
- }
1418
- fragment MutationError on _MutationError {
1419
- paths {
1420
- ... on _FieldPathFragment {
1421
- field
1422
- }
1423
- ... on _IndexPathFragment {
1424
- index
1425
- alias
1426
- }
1427
- }
1428
- message
1429
- type
1430
- }
1431
- fragment ValidationResult on _ValidationResult {
1432
- valid
1433
- errors {
1434
- path {
1435
- ... on _FieldPathFragment {
1436
- field
1437
- }
1438
- ... on _IndexPathFragment {
1439
- index
1440
- alias
1441
- }
1442
- }
1443
- message {
1444
- text
1445
- }
1446
- }
1447
- }
1448
- "
1449
- `)
1450
- expect(calls[0].variables).toMatchInlineSnapshot(`
1451
- {
1452
- "PostUniqueWhere_0": {
1453
- "id": "ca7a9b84-efbb-435d-a063-da11f205335a",
1454
- },
1455
- "PostUpdateInput_1": {
1456
- "locales": [
1457
- {
1458
- "update": {
1459
- "by": {
1460
- "locale": {
1461
- "code": "cs",
1462
- },
1463
- },
1464
- "data": {
1465
- "title": "cs title",
1466
- },
1467
- },
1468
- },
1469
- ],
1470
- "publishedAt": "now",
1471
- },
1472
- }
1473
- `)
517
+ expect(calls[0].query).toMatchSnapshot()
518
+ expect(calls[0].variables).toMatchSnapshot()
1474
519
  })
1475
520
 
1476
521
  })