@contember/client-content 2.0.0-alpha.6 → 2.0.0-alpha.9

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 (153) hide show
  1. package/api-extractor.json +3 -0
  2. package/dist/development/index.cjs +5 -5
  3. package/dist/development/index.js +5 -5
  4. package/dist/development/src/ContentClient.cjs.map +1 -0
  5. package/dist/development/src/ContentClient.js.map +1 -0
  6. package/dist/development/src/ContentQueryBuilder.cjs.map +1 -0
  7. package/dist/development/src/ContentQueryBuilder.js.map +1 -0
  8. package/dist/development/src/nodes/ContentEntitySelection.cjs.map +1 -0
  9. package/dist/development/src/nodes/ContentEntitySelection.js.map +1 -0
  10. package/dist/development/src/nodes/ContentOperation.cjs.map +1 -0
  11. package/dist/development/src/nodes/ContentOperation.js.map +1 -0
  12. package/dist/development/src/utils/ContentOperationSet.cjs.map +1 -0
  13. package/dist/development/src/utils/ContentOperationSet.js.map +1 -0
  14. package/dist/development/src/utils/createListArgs.cjs.map +1 -0
  15. package/dist/development/src/utils/createListArgs.js.map +1 -0
  16. package/dist/development/src/utils/createMutationOperationSet.cjs.map +1 -0
  17. package/dist/development/src/utils/createMutationOperationSet.js.map +1 -0
  18. package/dist/development/src/utils/createQueryOperationSet.cjs.map +1 -0
  19. package/dist/development/src/utils/createQueryOperationSet.js.map +1 -0
  20. package/dist/development/src/utils/createTypedArgs.cjs.map +1 -0
  21. package/dist/development/src/utils/createTypedArgs.js.map +1 -0
  22. package/dist/development/src/utils/mutationFragments.cjs.map +1 -0
  23. package/dist/development/src/utils/mutationFragments.js.map +1 -0
  24. package/dist/production/index.cjs +5 -5
  25. package/dist/production/index.js +5 -5
  26. package/dist/production/src/ContentClient.cjs.map +1 -0
  27. package/dist/production/src/ContentClient.js.map +1 -0
  28. package/dist/production/src/ContentQueryBuilder.cjs.map +1 -0
  29. package/dist/production/src/ContentQueryBuilder.js.map +1 -0
  30. package/dist/production/src/nodes/ContentEntitySelection.cjs.map +1 -0
  31. package/dist/production/src/nodes/ContentEntitySelection.js.map +1 -0
  32. package/dist/production/src/nodes/ContentOperation.cjs.map +1 -0
  33. package/dist/production/src/nodes/ContentOperation.js.map +1 -0
  34. package/dist/production/src/utils/ContentOperationSet.cjs.map +1 -0
  35. package/dist/production/src/utils/ContentOperationSet.js.map +1 -0
  36. package/dist/production/src/utils/createListArgs.cjs.map +1 -0
  37. package/dist/production/src/utils/createListArgs.js.map +1 -0
  38. package/dist/production/src/utils/createMutationOperationSet.cjs.map +1 -0
  39. package/dist/production/src/utils/createMutationOperationSet.js.map +1 -0
  40. package/dist/production/src/utils/createQueryOperationSet.cjs.map +1 -0
  41. package/dist/production/src/utils/createQueryOperationSet.js.map +1 -0
  42. package/dist/production/src/utils/createTypedArgs.cjs.map +1 -0
  43. package/dist/production/src/utils/createTypedArgs.js.map +1 -0
  44. package/dist/production/src/utils/mutationFragments.cjs.map +1 -0
  45. package/dist/production/src/utils/mutationFragments.js.map +1 -0
  46. package/dist/types/nodes/ContentEntitySelection.d.ts.map +1 -1
  47. package/dist/types/nodes/ContentOperation.d.ts.map +1 -1
  48. package/dist/types/nodes/TypedEntitySelection.d.ts.map +1 -1
  49. package/dist/types/tsconfig.tsbuildinfo +1 -1
  50. package/dist/types/utils/createListArgs.d.ts +1 -1
  51. package/dist/types/utils/createListArgs.d.ts.map +1 -1
  52. package/dist/types/utils/createMutationOperationSet.d.ts.map +1 -1
  53. package/dist/types/utils/createQueryOperationSet.d.ts.map +1 -1
  54. package/dist/types/utils/createTypedArgs.d.ts.map +1 -1
  55. package/package.json +9 -16
  56. package/src/ContentQueryBuilder.ts +1 -1
  57. package/src/nodes/TypedEntitySelection.ts +1 -1
  58. package/src/tsconfig.json +3 -0
  59. package/src/utils/createListArgs.ts +1 -1
  60. package/tests/cases/unit/mutation.test.ts +1476 -0
  61. package/tests/cases/unit/query.test.ts +519 -0
  62. package/tests/cases/unit/types.test.ts +144 -0
  63. package/tests/client/entities.ts +108 -0
  64. package/tests/client/enums.ts +1 -0
  65. package/tests/client/index.ts +17 -0
  66. package/tests/client/names.ts +116 -0
  67. package/tests/generate.ts +13 -0
  68. package/tests/lib.ts +16 -0
  69. package/tests/schema.ts +37 -0
  70. package/tests/tsconfig.json +13 -0
  71. package/tsconfig.json +8 -0
  72. package/tsdoc.json +6 -0
  73. package/vitest.config.ts +3 -0
  74. package/dist/development/ContentClient.cjs.map +0 -1
  75. package/dist/development/ContentClient.js.map +0 -1
  76. package/dist/development/ContentQueryBuilder.cjs.map +0 -1
  77. package/dist/development/ContentQueryBuilder.js.map +0 -1
  78. package/dist/development/nodes/ContentEntitySelection.cjs.map +0 -1
  79. package/dist/development/nodes/ContentEntitySelection.js.map +0 -1
  80. package/dist/development/nodes/ContentOperation.cjs.map +0 -1
  81. package/dist/development/nodes/ContentOperation.js.map +0 -1
  82. package/dist/development/utils/ContentOperationSet.cjs.map +0 -1
  83. package/dist/development/utils/ContentOperationSet.js.map +0 -1
  84. package/dist/development/utils/createListArgs.cjs.map +0 -1
  85. package/dist/development/utils/createListArgs.js.map +0 -1
  86. package/dist/development/utils/createMutationOperationSet.cjs.map +0 -1
  87. package/dist/development/utils/createMutationOperationSet.js.map +0 -1
  88. package/dist/development/utils/createQueryOperationSet.cjs.map +0 -1
  89. package/dist/development/utils/createQueryOperationSet.js.map +0 -1
  90. package/dist/development/utils/createTypedArgs.cjs.map +0 -1
  91. package/dist/development/utils/createTypedArgs.js.map +0 -1
  92. package/dist/development/utils/mutationFragments.cjs.map +0 -1
  93. package/dist/development/utils/mutationFragments.js.map +0 -1
  94. package/dist/production/ContentClient.cjs.map +0 -1
  95. package/dist/production/ContentClient.js.map +0 -1
  96. package/dist/production/ContentQueryBuilder.cjs.map +0 -1
  97. package/dist/production/ContentQueryBuilder.js.map +0 -1
  98. package/dist/production/nodes/ContentEntitySelection.cjs.map +0 -1
  99. package/dist/production/nodes/ContentEntitySelection.js.map +0 -1
  100. package/dist/production/nodes/ContentOperation.cjs.map +0 -1
  101. package/dist/production/nodes/ContentOperation.js.map +0 -1
  102. package/dist/production/utils/ContentOperationSet.cjs.map +0 -1
  103. package/dist/production/utils/ContentOperationSet.js.map +0 -1
  104. package/dist/production/utils/createListArgs.cjs.map +0 -1
  105. package/dist/production/utils/createListArgs.js.map +0 -1
  106. package/dist/production/utils/createMutationOperationSet.cjs.map +0 -1
  107. package/dist/production/utils/createMutationOperationSet.js.map +0 -1
  108. package/dist/production/utils/createQueryOperationSet.cjs.map +0 -1
  109. package/dist/production/utils/createQueryOperationSet.js.map +0 -1
  110. package/dist/production/utils/createTypedArgs.cjs.map +0 -1
  111. package/dist/production/utils/createTypedArgs.js.map +0 -1
  112. package/dist/production/utils/mutationFragments.cjs.map +0 -1
  113. package/dist/production/utils/mutationFragments.js.map +0 -1
  114. /package/dist/development/{ContentClient.cjs → src/ContentClient.cjs} +0 -0
  115. /package/dist/development/{ContentClient.js → src/ContentClient.js} +0 -0
  116. /package/dist/development/{ContentQueryBuilder.cjs → src/ContentQueryBuilder.cjs} +0 -0
  117. /package/dist/development/{ContentQueryBuilder.js → src/ContentQueryBuilder.js} +0 -0
  118. /package/dist/development/{nodes → src/nodes}/ContentEntitySelection.cjs +0 -0
  119. /package/dist/development/{nodes → src/nodes}/ContentEntitySelection.js +0 -0
  120. /package/dist/development/{nodes → src/nodes}/ContentOperation.cjs +0 -0
  121. /package/dist/development/{nodes → src/nodes}/ContentOperation.js +0 -0
  122. /package/dist/development/{utils → src/utils}/ContentOperationSet.cjs +0 -0
  123. /package/dist/development/{utils → src/utils}/ContentOperationSet.js +0 -0
  124. /package/dist/development/{utils → src/utils}/createListArgs.cjs +0 -0
  125. /package/dist/development/{utils → src/utils}/createListArgs.js +0 -0
  126. /package/dist/development/{utils → src/utils}/createMutationOperationSet.cjs +0 -0
  127. /package/dist/development/{utils → src/utils}/createMutationOperationSet.js +0 -0
  128. /package/dist/development/{utils → src/utils}/createQueryOperationSet.cjs +0 -0
  129. /package/dist/development/{utils → src/utils}/createQueryOperationSet.js +0 -0
  130. /package/dist/development/{utils → src/utils}/createTypedArgs.cjs +0 -0
  131. /package/dist/development/{utils → src/utils}/createTypedArgs.js +0 -0
  132. /package/dist/development/{utils → src/utils}/mutationFragments.cjs +0 -0
  133. /package/dist/development/{utils → src/utils}/mutationFragments.js +0 -0
  134. /package/dist/production/{ContentClient.cjs → src/ContentClient.cjs} +0 -0
  135. /package/dist/production/{ContentClient.js → src/ContentClient.js} +0 -0
  136. /package/dist/production/{ContentQueryBuilder.cjs → src/ContentQueryBuilder.cjs} +0 -0
  137. /package/dist/production/{ContentQueryBuilder.js → src/ContentQueryBuilder.js} +0 -0
  138. /package/dist/production/{nodes → src/nodes}/ContentEntitySelection.cjs +0 -0
  139. /package/dist/production/{nodes → src/nodes}/ContentEntitySelection.js +0 -0
  140. /package/dist/production/{nodes → src/nodes}/ContentOperation.cjs +0 -0
  141. /package/dist/production/{nodes → src/nodes}/ContentOperation.js +0 -0
  142. /package/dist/production/{utils → src/utils}/ContentOperationSet.cjs +0 -0
  143. /package/dist/production/{utils → src/utils}/ContentOperationSet.js +0 -0
  144. /package/dist/production/{utils → src/utils}/createListArgs.cjs +0 -0
  145. /package/dist/production/{utils → src/utils}/createListArgs.js +0 -0
  146. /package/dist/production/{utils → src/utils}/createMutationOperationSet.cjs +0 -0
  147. /package/dist/production/{utils → src/utils}/createMutationOperationSet.js +0 -0
  148. /package/dist/production/{utils → src/utils}/createQueryOperationSet.cjs +0 -0
  149. /package/dist/production/{utils → src/utils}/createQueryOperationSet.js +0 -0
  150. /package/dist/production/{utils → src/utils}/createTypedArgs.cjs +0 -0
  151. /package/dist/production/{utils → src/utils}/createTypedArgs.js +0 -0
  152. /package/dist/production/{utils → src/utils}/mutationFragments.cjs +0 -0
  153. /package/dist/production/{utils → src/utils}/mutationFragments.js +0 -0
@@ -0,0 +1,1476 @@
1
+ import { describe, expect, test } from 'vitest'
2
+ import { createClient } from '../../lib'
3
+ import { queryBuilder } from '../../client'
4
+
5
+ const qb = queryBuilder
6
+ describe('mutations in trx', () => {
7
+ test('create trx', async () => {
8
+ const [client, calls] = createClient({
9
+ mut: {
10
+ ok: true,
11
+ mut: {
12
+ ok: true,
13
+ },
14
+ },
15
+ })
16
+ const createAuthor = qb.transaction(qb.create('Author', {
17
+ data: {
18
+ name: 'John',
19
+ email: 'xx@localhost',
20
+ },
21
+ }))
22
+ const result = await client.mutate(createAuthor)
23
+
24
+
25
+ expect(result.data.ok).toBe(true)
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
+ `)
91
+ })
92
+
93
+ test('mutation with a node', async () => {
94
+ const [client, calls] = createClient({
95
+ mut: {
96
+ ok: true,
97
+ mut: {
98
+ ok: true,
99
+ node: { id: 'ca7a9b84-efbb-435d-a063-da11f205335a' },
100
+ },
101
+ },
102
+ })
103
+ const result = await client.mutate(qb.transaction(qb.create('Author', {
104
+ data: {
105
+ name: 'John',
106
+ email: 'xx@localhost',
107
+ },
108
+ }, it => it.$('id'))))
109
+ expect(result.ok).toBe(true)
110
+ expect(result.data?.node?.id).toBe('ca7a9b84-efbb-435d-a063-da11f205335a')
111
+ 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
+ `)
179
+ })
180
+
181
+ test('update', async () => {
182
+ const [client, calls] = createClient({
183
+ mut: {
184
+ ok: true,
185
+ mut: {
186
+ ok: true,
187
+ },
188
+ },
189
+ })
190
+ await client.mutate(qb.transaction(qb.update('Author', {
191
+ by: { id: 'ca7a9b84-efbb-435d-a063-da11f205335a' },
192
+ data: {
193
+ name: 'John',
194
+ email: 'xx@localhost',
195
+ },
196
+ })))
197
+ expect(calls).toHaveLength(1)
198
+ expect(calls[0].query).toMatchInlineSnapshot(`
199
+ "mutation($MutationTransactionOptions_0: MutationTransactionOptions, $AuthorUniqueWhere_1: AuthorUniqueWhere!, $AuthorUpdateInput_2: AuthorUpdateInput!) {
200
+ mut: transaction(options: $MutationTransactionOptions_0) {
201
+ ok
202
+ errorMessage
203
+ errors {
204
+ ... MutationError
205
+ }
206
+ validation {
207
+ ... ValidationResult
208
+ }
209
+ mut: updateAuthor(by: $AuthorUniqueWhere_1, data: $AuthorUpdateInput_2) {
210
+ ok
211
+ errorMessage
212
+ errors {
213
+ ... MutationError
214
+ }
215
+ validation {
216
+ ... ValidationResult
217
+ }
218
+ }
219
+ }
220
+ }
221
+ fragment MutationError on _MutationError {
222
+ paths {
223
+ ... on _FieldPathFragment {
224
+ field
225
+ }
226
+ ... on _IndexPathFragment {
227
+ index
228
+ alias
229
+ }
230
+ }
231
+ message
232
+ type
233
+ }
234
+ fragment ValidationResult on _ValidationResult {
235
+ valid
236
+ errors {
237
+ path {
238
+ ... on _FieldPathFragment {
239
+ field
240
+ }
241
+ ... on _IndexPathFragment {
242
+ index
243
+ alias
244
+ }
245
+ }
246
+ message {
247
+ text
248
+ }
249
+ }
250
+ }
251
+ "
252
+ `)
253
+ expect(calls[0].variables).toMatchInlineSnapshot(`
254
+ {
255
+ "AuthorUniqueWhere_1": {
256
+ "id": "ca7a9b84-efbb-435d-a063-da11f205335a",
257
+ },
258
+ "AuthorUpdateInput_2": {
259
+ "email": "xx@localhost",
260
+ "name": "John",
261
+ },
262
+ "MutationTransactionOptions_0": {},
263
+ }
264
+ `)
265
+ })
266
+
267
+ test('delete', async () => {
268
+ const [client, calls] = createClient({
269
+ mut: {
270
+ ok: true,
271
+ mut: {
272
+ ok: true,
273
+ },
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
+ `)
831
+ })
832
+
833
+ test('mutation with a node', async () => {
834
+ const [client, calls] = createClient({
835
+ mut: {
836
+ ok: true,
837
+ node: { id: 'ca7a9b84-efbb-435d-a063-da11f205335a' },
838
+ },
839
+ })
840
+ const result = await client.mutate(qb.create('Author', {
841
+ data: {
842
+ name: 'John',
843
+ email: 'xx@localhost',
844
+ },
845
+ }, it => it.$('id')))
846
+ expect(result.ok).toBe(true)
847
+ expect(result.node?.id).toBe('ca7a9b84-efbb-435d-a063-da11f205335a')
848
+ 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
+ `)
905
+ })
906
+
907
+ test('update', async () => {
908
+ const [client, calls] = createClient({
909
+ mut: {
910
+ ok: true,
911
+ },
912
+ })
913
+ await client.mutate(qb.update('Author', {
914
+ by: { id: 'ca7a9b84-efbb-435d-a063-da11f205335a' },
915
+ data: {
916
+ name: 'John',
917
+ email: 'xx@localhost',
918
+ },
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
+ }))
988
+ 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
+ `)
1021
+ })
1022
+
1023
+ test('upsert', async () => {
1024
+ const [client, calls] = createClient({
1025
+ mut: {
1026
+ ok: true,
1027
+ },
1028
+ })
1029
+ await client.mutate(qb.upsert('Author', {
1030
+ 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
+ `)
1101
+ })
1102
+
1103
+ test('multiple mutations as array', async () => {
1104
+ const [client, calls] = createClient({
1105
+ mut_0: {
1106
+ ok: true,
1107
+ },
1108
+ mut_1: {
1109
+ ok: true,
1110
+ },
1111
+ })
1112
+ const result = await client.mutate([
1113
+ qb.create('Author', {
1114
+ data: {
1115
+ name: 'John',
1116
+ email: 'xx@localhost',
1117
+ },
1118
+ }),
1119
+ qb.create('Author', {
1120
+ data: {
1121
+ name: 'John',
1122
+ email: 'xx@localhost',
1123
+ },
1124
+ }),
1125
+ ])
1126
+ expect(result).toHaveLength(2)
1127
+ expect(result[0].ok).toBe(true)
1128
+ expect(result[1].ok).toBe(true)
1129
+ 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
+ `)
1197
+ })
1198
+
1199
+ test('multiple named mutations', async () => {
1200
+ const [client, calls] = createClient({
1201
+ createAuthor: {
1202
+ ok: true,
1203
+ },
1204
+ createPost: {
1205
+ ok: true,
1206
+ },
1207
+ })
1208
+ const result = await client.mutate({
1209
+ createAuthor: qb.create('Author', {
1210
+ data: {
1211
+ name: 'John',
1212
+ email: 'xx@localhost',
1213
+ },
1214
+ }),
1215
+ createPost: qb.create('Post', {
1216
+ data: {
1217
+ publishedAt: 'now',
1218
+ },
1219
+ }),
1220
+ })
1221
+ expect(result.createAuthor.ok).toBe(true)
1222
+ expect(result.createPost.ok).toBe(true)
1223
+ 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
+ `)
1290
+ })
1291
+
1292
+ test('mutation and query combo', async () => {
1293
+ const [client, calls] = createClient({
1294
+ createPost: {
1295
+ ok: true,
1296
+ },
1297
+ post: {
1298
+ value: {
1299
+ id: 'ca7a9b84-efbb-435d-a063-da11f205335a',
1300
+ publishedAt: 'now',
1301
+ },
1302
+ },
1303
+ })
1304
+
1305
+ const result = await client.mutate({
1306
+ createPost: qb.create('Post', {
1307
+ data: {
1308
+ publishedAt: 'now',
1309
+ },
1310
+ }),
1311
+ post: qb.get('Post', {
1312
+ by: { id: 'ca7a9b84-efbb-435d-a063-da11f205335a' },
1313
+ }, it => it.$$()),
1314
+ })
1315
+ expect(result.createPost.ok).toBe(true)
1316
+ expect(result.post?.publishedAt).toBe('now')
1317
+
1318
+ 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
+ `)
1380
+ })
1381
+
1382
+ test('update locale relation', async () => {
1383
+ const [client, calls] = createClient({
1384
+ mut: {
1385
+ ok: true,
1386
+ },
1387
+ })
1388
+
1389
+ const result = await client.mutate(qb.update('Post', {
1390
+ by: { id: 'ca7a9b84-efbb-435d-a063-da11f205335a' },
1391
+ data: {
1392
+ publishedAt: 'now',
1393
+ locales: [{
1394
+ update: {
1395
+ by: { locale: { code: 'cs' } },
1396
+ data: {
1397
+ title: 'cs title',
1398
+ },
1399
+ },
1400
+ }],
1401
+ },
1402
+ }))
1403
+ expect(result.ok).toBe(true)
1404
+ 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
+ `)
1474
+ })
1475
+
1476
+ })