@contember/client-content 2.1.0-alpha.3 → 2.1.0-alpha.35

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 (149) hide show
  1. package/package.json +6 -6
  2. package/src/ContentClient.ts +36 -9
  3. package/src/ContentQueryBuilder.ts +44 -35
  4. package/src/MutationFailedError.ts +19 -0
  5. package/src/TypedContentQueryBuilder.ts +0 -4
  6. package/src/nodes/ContentEntitySelection.ts +35 -17
  7. package/src/nodes/TypedEntitySelection.ts +96 -48
  8. package/src/types/Input.ts +1 -9
  9. package/src/types/Result.ts +41 -9
  10. package/src/types/Schema.ts +0 -1
  11. package/src/utils/createListArgs.ts +5 -1
  12. package/src/utils/createMutationOperationSet.ts +9 -7
  13. package/src/utils/createQueryOperationSet.ts +0 -1
  14. package/tests/cases/unit/__snapshots__/mutation.test.ts.snap +952 -818
  15. package/tests/cases/unit/__snapshots__/query.test.ts.snap +200 -60
  16. package/tests/cases/unit/mutation.test.ts +48 -3
  17. package/tests/cases/unit/query.test.ts +91 -66
  18. package/tests/cases/unit/types.test.ts +31 -27
  19. package/tests/client/entities.ts +2 -0
  20. package/tests/client/enums.ts +5 -0
  21. package/tests/client/names.ts +129 -117
  22. package/tests/generate.ts +0 -1
  23. package/tests/lib.ts +0 -1
  24. package/tests/schema.ts +1 -2
  25. package/dist/development/index.cjs +0 -13
  26. package/dist/development/index.cjs.map +0 -1
  27. package/dist/development/index.js +0 -13
  28. package/dist/development/index.js.map +0 -1
  29. package/dist/development/src/ContentClient.cjs +0 -27
  30. package/dist/development/src/ContentClient.cjs.map +0 -1
  31. package/dist/development/src/ContentClient.js +0 -27
  32. package/dist/development/src/ContentClient.js.map +0 -1
  33. package/dist/development/src/ContentQueryBuilder.cjs +0 -175
  34. package/dist/development/src/ContentQueryBuilder.cjs.map +0 -1
  35. package/dist/development/src/ContentQueryBuilder.js +0 -175
  36. package/dist/development/src/ContentQueryBuilder.js.map +0 -1
  37. package/dist/development/src/nodes/ContentEntitySelection.cjs +0 -207
  38. package/dist/development/src/nodes/ContentEntitySelection.cjs.map +0 -1
  39. package/dist/development/src/nodes/ContentEntitySelection.js +0 -207
  40. package/dist/development/src/nodes/ContentEntitySelection.js.map +0 -1
  41. package/dist/development/src/nodes/ContentOperation.cjs +0 -16
  42. package/dist/development/src/nodes/ContentOperation.cjs.map +0 -1
  43. package/dist/development/src/nodes/ContentOperation.js +0 -16
  44. package/dist/development/src/nodes/ContentOperation.js.map +0 -1
  45. package/dist/development/src/utils/ContentOperationSet.cjs +0 -10
  46. package/dist/development/src/utils/ContentOperationSet.cjs.map +0 -1
  47. package/dist/development/src/utils/ContentOperationSet.js +0 -10
  48. package/dist/development/src/utils/ContentOperationSet.js.map +0 -1
  49. package/dist/development/src/utils/createListArgs.cjs +0 -24
  50. package/dist/development/src/utils/createListArgs.cjs.map +0 -1
  51. package/dist/development/src/utils/createListArgs.js +0 -24
  52. package/dist/development/src/utils/createListArgs.js.map +0 -1
  53. package/dist/development/src/utils/createMutationOperationSet.cjs +0 -37
  54. package/dist/development/src/utils/createMutationOperationSet.cjs.map +0 -1
  55. package/dist/development/src/utils/createMutationOperationSet.js +0 -37
  56. package/dist/development/src/utils/createMutationOperationSet.js.map +0 -1
  57. package/dist/development/src/utils/createQueryOperationSet.cjs +0 -19
  58. package/dist/development/src/utils/createQueryOperationSet.cjs.map +0 -1
  59. package/dist/development/src/utils/createQueryOperationSet.js +0 -19
  60. package/dist/development/src/utils/createQueryOperationSet.js.map +0 -1
  61. package/dist/development/src/utils/createTypedArgs.cjs +0 -17
  62. package/dist/development/src/utils/createTypedArgs.cjs.map +0 -1
  63. package/dist/development/src/utils/createTypedArgs.js +0 -17
  64. package/dist/development/src/utils/createTypedArgs.js.map +0 -1
  65. package/dist/development/src/utils/mutationFragments.cjs +0 -55
  66. package/dist/development/src/utils/mutationFragments.cjs.map +0 -1
  67. package/dist/development/src/utils/mutationFragments.js +0 -55
  68. package/dist/development/src/utils/mutationFragments.js.map +0 -1
  69. package/dist/production/index.cjs +0 -13
  70. package/dist/production/index.cjs.map +0 -1
  71. package/dist/production/index.js +0 -13
  72. package/dist/production/index.js.map +0 -1
  73. package/dist/production/src/ContentClient.cjs +0 -27
  74. package/dist/production/src/ContentClient.cjs.map +0 -1
  75. package/dist/production/src/ContentClient.js +0 -27
  76. package/dist/production/src/ContentClient.js.map +0 -1
  77. package/dist/production/src/ContentQueryBuilder.cjs +0 -175
  78. package/dist/production/src/ContentQueryBuilder.cjs.map +0 -1
  79. package/dist/production/src/ContentQueryBuilder.js +0 -175
  80. package/dist/production/src/ContentQueryBuilder.js.map +0 -1
  81. package/dist/production/src/nodes/ContentEntitySelection.cjs +0 -207
  82. package/dist/production/src/nodes/ContentEntitySelection.cjs.map +0 -1
  83. package/dist/production/src/nodes/ContentEntitySelection.js +0 -207
  84. package/dist/production/src/nodes/ContentEntitySelection.js.map +0 -1
  85. package/dist/production/src/nodes/ContentOperation.cjs +0 -16
  86. package/dist/production/src/nodes/ContentOperation.cjs.map +0 -1
  87. package/dist/production/src/nodes/ContentOperation.js +0 -16
  88. package/dist/production/src/nodes/ContentOperation.js.map +0 -1
  89. package/dist/production/src/utils/ContentOperationSet.cjs +0 -10
  90. package/dist/production/src/utils/ContentOperationSet.cjs.map +0 -1
  91. package/dist/production/src/utils/ContentOperationSet.js +0 -10
  92. package/dist/production/src/utils/ContentOperationSet.js.map +0 -1
  93. package/dist/production/src/utils/createListArgs.cjs +0 -24
  94. package/dist/production/src/utils/createListArgs.cjs.map +0 -1
  95. package/dist/production/src/utils/createListArgs.js +0 -24
  96. package/dist/production/src/utils/createListArgs.js.map +0 -1
  97. package/dist/production/src/utils/createMutationOperationSet.cjs +0 -37
  98. package/dist/production/src/utils/createMutationOperationSet.cjs.map +0 -1
  99. package/dist/production/src/utils/createMutationOperationSet.js +0 -37
  100. package/dist/production/src/utils/createMutationOperationSet.js.map +0 -1
  101. package/dist/production/src/utils/createQueryOperationSet.cjs +0 -19
  102. package/dist/production/src/utils/createQueryOperationSet.cjs.map +0 -1
  103. package/dist/production/src/utils/createQueryOperationSet.js +0 -19
  104. package/dist/production/src/utils/createQueryOperationSet.js.map +0 -1
  105. package/dist/production/src/utils/createTypedArgs.cjs +0 -17
  106. package/dist/production/src/utils/createTypedArgs.cjs.map +0 -1
  107. package/dist/production/src/utils/createTypedArgs.js +0 -17
  108. package/dist/production/src/utils/createTypedArgs.js.map +0 -1
  109. package/dist/production/src/utils/mutationFragments.cjs +0 -55
  110. package/dist/production/src/utils/mutationFragments.cjs.map +0 -1
  111. package/dist/production/src/utils/mutationFragments.js +0 -55
  112. package/dist/production/src/utils/mutationFragments.js.map +0 -1
  113. package/dist/types/ContentClient.d.ts +0 -17
  114. package/dist/types/ContentClient.d.ts.map +0 -1
  115. package/dist/types/ContentQueryBuilder.d.ts +0 -27
  116. package/dist/types/ContentQueryBuilder.d.ts.map +0 -1
  117. package/dist/types/TypedContentQueryBuilder.d.ts +0 -21
  118. package/dist/types/TypedContentQueryBuilder.d.ts.map +0 -1
  119. package/dist/types/index.d.ts +0 -7
  120. package/dist/types/index.d.ts.map +0 -1
  121. package/dist/types/nodes/ContentEntitySelection.d.ts +0 -61
  122. package/dist/types/nodes/ContentEntitySelection.d.ts.map +0 -1
  123. package/dist/types/nodes/ContentOperation.d.ts +0 -30
  124. package/dist/types/nodes/ContentOperation.d.ts.map +0 -1
  125. package/dist/types/nodes/TypedEntitySelection.d.ts +0 -53
  126. package/dist/types/nodes/TypedEntitySelection.d.ts.map +0 -1
  127. package/dist/types/nodes/index.d.ts +0 -4
  128. package/dist/types/nodes/index.d.ts.map +0 -1
  129. package/dist/types/tsconfig.tsbuildinfo +0 -1
  130. package/dist/types/types/Input.d.ts +0 -201
  131. package/dist/types/types/Input.d.ts.map +0 -1
  132. package/dist/types/types/Result.d.ts +0 -39
  133. package/dist/types/types/Result.d.ts.map +0 -1
  134. package/dist/types/types/Schema.d.ts +0 -46
  135. package/dist/types/types/Schema.d.ts.map +0 -1
  136. package/dist/types/types/index.d.ts +0 -4
  137. package/dist/types/types/index.d.ts.map +0 -1
  138. package/dist/types/utils/ContentOperationSet.d.ts +0 -13
  139. package/dist/types/utils/ContentOperationSet.d.ts.map +0 -1
  140. package/dist/types/utils/createListArgs.d.ts +0 -9
  141. package/dist/types/utils/createListArgs.d.ts.map +0 -1
  142. package/dist/types/utils/createMutationOperationSet.d.ts +0 -4
  143. package/dist/types/utils/createMutationOperationSet.d.ts.map +0 -1
  144. package/dist/types/utils/createQueryOperationSet.d.ts +0 -4
  145. package/dist/types/utils/createQueryOperationSet.d.ts.map +0 -1
  146. package/dist/types/utils/createTypedArgs.d.ts +0 -3
  147. package/dist/types/utils/createTypedArgs.d.ts.map +0 -1
  148. package/dist/types/utils/mutationFragments.d.ts +0 -3
  149. package/dist/types/utils/mutationFragments.d.ts.map +0 -1
@@ -1,102 +1,242 @@
1
- // Bun Snapshot v1, https://goo.gl/fbAQLP
1
+ // Bun Snapshot v1, https://bun.sh/docs/test/snapshots
2
2
 
3
3
  exports[`queries list 1`] = `
4
4
  "query {
5
- \tauthors: listAuthor {
6
- \t\tid
7
- \t\tname
8
- \t\temail
9
- \t}
5
+ authors: listAuthor {
6
+ id
7
+ name
8
+ email
9
+ }
10
10
  }
11
11
  "
12
12
  `;
13
13
 
14
14
  exports[`queries multiple queries 1`] = `
15
15
  "query {
16
- \tauthors: listAuthor {
17
- \t\tid
18
- \t\tname
19
- \t\temail
20
- \t}
21
- \tposts: listPost {
22
- \t\tid
23
- \t\tpublishedAt
24
- \t}
16
+ authors: listAuthor {
17
+ id
18
+ name
19
+ email
20
+ }
21
+ posts: listPost {
22
+ id
23
+ publishedAt
24
+ status
25
+ }
25
26
  }
26
27
  "
27
28
  `;
28
29
 
29
30
  exports[`queries single query 1`] = `
30
31
  "query {
31
- \tvalue: listPost {
32
- \t\tid
33
- \t\tpublishedAt
34
- \t}
32
+ value: listPost {
33
+ id
34
+ publishedAt
35
+ status
36
+ }
35
37
  }
36
38
  "
37
39
  `;
38
40
 
39
41
  exports[`queries nested object 1`] = `
40
42
  "query {
41
- \tauthors: listAuthor {
42
- \t\tid
43
- \t\tname
44
- \t\temail
45
- \t\tposts {
46
- \t\t\tid
47
- \t\t\tpublishedAt
48
- \t\t\ttags {
49
- \t\t\t\tid
50
- \t\t\t\tname
51
- \t\t\t}
52
- \t\t}
53
- \t}
43
+ authors: listAuthor {
44
+ id
45
+ name
46
+ email
47
+ posts {
48
+ id
49
+ publishedAt
50
+ status
51
+ tags {
52
+ id
53
+ name
54
+ }
55
+ }
56
+ }
54
57
  }
55
58
  "
56
59
  `;
57
60
 
58
61
  exports[`queries nested object args 1`] = `
59
62
  "query($PostWhere_0: PostWhere, $Int_1: Int) {
60
- \tauthors: listAuthor {
61
- \t\tid
62
- \t\tname
63
- \t\temail
64
- \t\tposts(filter: $PostWhere_0, limit: $Int_1) {
65
- \t\t\tid
66
- \t\t\tpublishedAt
67
- \t\t}
68
- \t}
63
+ authors: listAuthor {
64
+ id
65
+ name
66
+ email
67
+ posts(filter: $PostWhere_0, limit: $Int_1) {
68
+ id
69
+ publishedAt
70
+ status
71
+ }
72
+ }
69
73
  }
70
74
  "
71
75
  `;
72
76
 
73
77
  exports[`queries list with args:
74
- \t\t\t"query($AuthorWhere_0: AuthorWhere, $AuthorOrderBy_1: [AuthorOrderBy!], $Int_2: Int, $Int_3: Int) {
75
- \t\t\t\tauthors: listAuthor(filter: $AuthorWhere_0, orderBy: $AuthorOrderBy_1, limit: $Int_2, offset: $Int_3) {
76
- \t\t\t\t\tid
77
- \t\t\t\t\tname
78
- \t\t\t\t\temail
79
- \t\t\t\t}
80
- \t\t\t}
81
- \t\t\t"
82
- \t\t 1`] = `
78
+ "query($AuthorWhere_0: AuthorWhere, $AuthorOrderBy_1: [AuthorOrderBy!], $Int_2: Int, $Int_3: Int) {
79
+ authors: listAuthor(filter: $AuthorWhere_0, orderBy: $AuthorOrderBy_1, limit: $Int_2, offset: $Int_3) {
80
+ id
81
+ name
82
+ email
83
+ }
84
+ }
85
+ "
86
+ 1`] = `
83
87
  "query($AuthorWhere_0: AuthorWhere, $AuthorOrderBy_1: [AuthorOrderBy!], $Int_2: Int, $Int_3: Int) {
84
- \tauthors: listAuthor(filter: $AuthorWhere_0, orderBy: $AuthorOrderBy_1, limit: $Int_2, offset: $Int_3) {
85
- \t\tid
86
- \t\tname
87
- \t\temail
88
- \t}
88
+ authors: listAuthor(filter: $AuthorWhere_0, orderBy: $AuthorOrderBy_1, limit: $Int_2, offset: $Int_3) {
89
+ id
90
+ name
91
+ email
92
+ }
89
93
  }
90
94
  "
91
95
  `;
92
96
 
93
97
  exports[`queries get by id 1`] = `
94
98
  "query($AuthorUniqueWhere_0: AuthorUniqueWhere!) {
95
- \tauthors: getAuthor(by: $AuthorUniqueWhere_0) {
96
- \t\tid
97
- \t\tname
98
- \t\temail
99
- \t}
99
+ authors: getAuthor(by: $AuthorUniqueWhere_0) {
100
+ id
101
+ name
102
+ email
103
+ }
104
+ }
105
+ "
106
+ `;
107
+
108
+ exports[`queries top level list transform 1`] = `
109
+ [
110
+ {
111
+ "query":
112
+ "query {
113
+ authors: listAuthor {
114
+ id
115
+ name
116
+ email
117
+ }
118
+ }
119
+ "
120
+ ,
121
+ "variables": {},
122
+ },
123
+ ]
124
+ `;
125
+
126
+ exports[`queries top level get transform 1`] = `
127
+ [
128
+ {
129
+ "query":
130
+ "query($AuthorUniqueWhere_0: AuthorUniqueWhere!) {
131
+ author: getAuthor(by: $AuthorUniqueWhere_0) {
132
+ id
133
+ name
134
+ email
135
+ }
136
+ }
137
+ "
138
+ ,
139
+ "variables": {
140
+ "AuthorUniqueWhere_0": {
141
+ "id": "123",
142
+ },
143
+ },
144
+ },
145
+ ]
146
+ `;
147
+
148
+ exports[`queries nested has-many transform 1`] = `
149
+ [
150
+ {
151
+ "query":
152
+ "query($AuthorUniqueWhere_0: AuthorUniqueWhere!) {
153
+ author: getAuthor(by: $AuthorUniqueWhere_0) {
154
+ id
155
+ name
156
+ email
157
+ posts {
158
+ id
159
+ publishedAt
160
+ status
161
+ }
162
+ }
163
+ }
164
+ "
165
+ ,
166
+ "variables": {
167
+ "AuthorUniqueWhere_0": {
168
+ "id": "123",
169
+ },
170
+ },
171
+ },
172
+ ]
173
+ `;
174
+
175
+ exports[`queries nested has-one transform 1`] = `
176
+ [
177
+ {
178
+ "query":
179
+ "query($PostUniqueWhere_0: PostUniqueWhere!) {
180
+ post: getPost(by: $PostUniqueWhere_0) {
181
+ id
182
+ publishedAt
183
+ status
184
+ author {
185
+ id
186
+ name
187
+ email
188
+ }
189
+ }
190
+ }
191
+ "
192
+ ,
193
+ "variables": {
194
+ "PostUniqueWhere_0": {
195
+ "id": "123",
196
+ },
197
+ },
198
+ },
199
+ ]
200
+ `;
201
+
202
+ exports[`queries nested has-many-by transform 1`] = `
203
+ [
204
+ {
205
+ "query":
206
+ "query($PostUniqueWhere_0: PostUniqueWhere!, $PostLocalesByLocaleUniqueWhere_1: PostLocalesByLocaleUniqueWhere!) {
207
+ post: getPost(by: $PostUniqueWhere_0) {
208
+ id
209
+ publishedAt
210
+ status
211
+ localesByLocale(by: $PostLocalesByLocaleUniqueWhere_1) {
212
+ id
213
+ title
214
+ content
215
+ }
216
+ }
217
+ }
218
+ "
219
+ ,
220
+ "variables": {
221
+ "PostLocalesByLocaleUniqueWhere_1": {
222
+ "locale": {
223
+ "code": "en",
224
+ },
225
+ },
226
+ "PostUniqueWhere_0": {
227
+ "id": "123",
228
+ },
229
+ },
230
+ },
231
+ ]
232
+ `;
233
+
234
+ exports[`queries omit 1`] = `
235
+ "query {
236
+ authors: listAuthor {
237
+ id
238
+ name
239
+ }
100
240
  }
101
241
  "
102
242
  `;
@@ -1,6 +1,7 @@
1
1
  import { describe, expect, test } from 'bun:test'
2
2
  import { createClient } from '../../lib'
3
3
  import { queryBuilder } from '../../client'
4
+ import { expectTypeOf } from 'expect-type'
4
5
 
5
6
  const qb = queryBuilder
6
7
  describe('mutations in trx', () => {
@@ -21,7 +22,6 @@ describe('mutations in trx', () => {
21
22
  }))
22
23
  const result = await client.mutate(createAuthor)
23
24
 
24
-
25
25
  expect(result.data.ok).toBe(true)
26
26
  expect(calls).toHaveLength(1)
27
27
  expect(calls[0].query).toMatchSnapshot()
@@ -302,7 +302,6 @@ describe('mutations in trx', () => {
302
302
  expect(calls[0].query).toMatchSnapshot()
303
303
  expect(calls[0].variables).toMatchSnapshot()
304
304
  })
305
-
306
305
  })
307
306
  describe('mutations without trx', () => {
308
307
  test('create', async () => {
@@ -319,7 +318,6 @@ describe('mutations without trx', () => {
319
318
  })
320
319
  const result = await client.mutate(createAuthor)
321
320
 
322
-
323
321
  expect(result.ok).toBe(true)
324
322
  expect(calls).toHaveLength(1)
325
323
  expect(calls[0].query).toMatchSnapshot()
@@ -518,4 +516,51 @@ describe('mutations without trx', () => {
518
516
  expect(calls[0].variables).toMatchSnapshot()
519
517
  })
520
518
 
519
+ test('mutate or fail - fail', async () => {
520
+ const [client, calls] = createClient({
521
+ mut: {
522
+ ok: false,
523
+ errorMessage: 'some error',
524
+ mut: {
525
+ ok: false,
526
+ },
527
+ },
528
+ })
529
+ const createAuthor = qb.transaction(qb.create('Author', {
530
+ data: {
531
+ name: 'John',
532
+ email: 'xx@localhost',
533
+ },
534
+ }))
535
+ expect(() => client.mutateOrThrow(createAuthor)).toThrow('some error')
536
+ expect(calls).toHaveLength(1)
537
+ expect(calls[0].query).toMatchSnapshot()
538
+ expect(calls[0].variables).toMatchSnapshot()
539
+ })
540
+
541
+ test('mutate or fail - ok', async () => {
542
+ const [client, calls] = createClient({
543
+ mut: {
544
+ ok: true,
545
+ errorMessage: null,
546
+ mut: {
547
+ ok: true,
548
+ },
549
+ },
550
+ })
551
+ const createAuthor = qb.transaction(qb.create('Author', {
552
+ data: {
553
+ name: 'John',
554
+ email: 'xx@localhost',
555
+ },
556
+ }))
557
+ const result = await client.mutateOrThrow(createAuthor)
558
+ expect(result.ok).toBe(true)
559
+ const ok = result.ok
560
+ expectTypeOf(ok).toEqualTypeOf<true>()
561
+
562
+ expect(calls).toHaveLength(1)
563
+ expect(calls[0].query).toMatchSnapshot()
564
+ expect(calls[0].variables).toMatchSnapshot()
565
+ })
521
566
  })
@@ -5,7 +5,6 @@ import OrderDirection = Input.OrderDirection
5
5
  import { queryBuilder } from '../../client'
6
6
 
7
7
  describe('queries', () => {
8
-
9
8
  const qb = queryBuilder
10
9
  test('list', async () => {
11
10
  const [client, calls] = createClient({
@@ -98,7 +97,6 @@ describe('queries', () => {
98
97
  expect(calls[0].variables).toEqual({})
99
98
  })
100
99
 
101
-
102
100
  test('single query', async () => {
103
101
  const [client, calls] = createClient({
104
102
  value: [
@@ -129,7 +127,6 @@ describe('queries', () => {
129
127
  expect(calls[0].variables).toEqual({})
130
128
  })
131
129
 
132
-
133
130
  test('nested object', async () => {
134
131
  const [client, calls] = createClient()
135
132
  await client.query({
@@ -142,10 +139,11 @@ describe('queries', () => {
142
139
  test('nested object args', async () => {
143
140
  const [client, calls] = createClient()
144
141
  await client.query({
145
- authors: qb.list('Author', {}, it => it.$$().$('posts', {
146
- limit: 10,
147
- filter: { tags: { name: { eq: 'foo' } } },
148
- }, it => it.$$())),
142
+ authors: qb.list('Author', {}, it =>
143
+ it.$$().$('posts', {
144
+ limit: 10,
145
+ filter: { tags: { name: { eq: 'foo' } } },
146
+ }, it => it.$$())),
149
147
  })
150
148
  expect(calls).toHaveLength(1)
151
149
  expect(calls[0].query).toMatchSnapshot()
@@ -161,7 +159,6 @@ describe('queries', () => {
161
159
  })
162
160
  })
163
161
 
164
-
165
162
  test('list with args', async () => {
166
163
  const [client, calls] = createClient()
167
164
  await client.query({
@@ -201,7 +198,6 @@ describe('queries', () => {
201
198
  )
202
199
  })
203
200
 
204
-
205
201
  test('get by id', async () => {
206
202
  const [client, calls] = createClient()
207
203
  const result = await client.query({
@@ -232,13 +228,13 @@ describe('queries', () => {
232
228
  ],
233
229
  })
234
230
  const result = await client.query({
235
- authors: qb.list('Author', {}, it => it
236
- .$$()
237
- .transform(it => ({
238
- ...it,
239
- label: `${it.name} (${it.email})`,
240
- })),
241
- ),
231
+ authors: qb.list('Author', {}, it =>
232
+ it
233
+ .$$()
234
+ .transform(it => ({
235
+ ...it,
236
+ label: `${it.name} (${it.email})`,
237
+ }))),
242
238
  })
243
239
  expect(result as any).toStrictEqual({
244
240
  authors: [
@@ -255,6 +251,7 @@ describe('queries', () => {
255
251
  ],
256
252
  })
257
253
  expect(calls).toHaveLength(1)
254
+ expect(calls).toMatchSnapshot()
258
255
  })
259
256
 
260
257
  test('top level get transform', async () => {
@@ -265,13 +262,13 @@ describe('queries', () => {
265
262
  },
266
263
  })
267
264
  const result = await client.query({
268
- author: qb.get('Author', { by: { id: '123' } }, it => it
269
- .$$()
270
- .transform(it => ({
271
- ...it,
272
- label: `${it.name} (${it.email})`,
273
- })),
274
- ),
265
+ author: qb.get('Author', { by: { id: '123' } }, it =>
266
+ it
267
+ .$$()
268
+ .transform(it => ({
269
+ ...it,
270
+ label: `${it.name} (${it.email})`,
271
+ }))),
275
272
  })
276
273
  expect(result as any).toStrictEqual({
277
274
  author: {
@@ -281,9 +278,9 @@ describe('queries', () => {
281
278
  },
282
279
  })
283
280
  expect(calls).toHaveLength(1)
281
+ expect(calls).toMatchSnapshot()
284
282
  })
285
283
 
286
-
287
284
  test('nested has-many transform', async () => {
288
285
  const [client, calls] = createClient({
289
286
  author: {
@@ -300,13 +297,14 @@ describe('queries', () => {
300
297
  },
301
298
  })
302
299
  const result = await client.query({
303
- author: qb.get('Author', { by: { id: '123' } }, it => it
304
- .$$()
305
- .$('posts', {}, it => it.$$().transform(it => ({
306
- ...it,
307
- publishYear: it.publishedAt ? new Date(it.publishedAt).getFullYear() : null,
308
- }))),
309
- ),
300
+ author: qb.get('Author', { by: { id: '123' } }, it =>
301
+ it
302
+ .$$()
303
+ .$('posts', {}, it =>
304
+ it.$$().transform(it => ({
305
+ ...it,
306
+ publishYear: it.publishedAt ? new Date(it.publishedAt).getFullYear() : null,
307
+ })))),
310
308
  })
311
309
  expect(result as any).toStrictEqual({
312
310
  author: {
@@ -325,9 +323,9 @@ describe('queries', () => {
325
323
  },
326
324
  })
327
325
  expect(calls).toHaveLength(1)
326
+ expect(calls).toMatchSnapshot()
328
327
  })
329
328
 
330
-
331
329
  test('nested has-one transform', async () => {
332
330
  const [client, calls] = createClient({
333
331
  post: {
@@ -338,19 +336,19 @@ describe('queries', () => {
338
336
  },
339
337
  },
340
338
  })
341
- const author = qb.fragment('Author', it => it
342
- .$$()
343
- .transform(it => ({
344
- ...it,
345
- label: `${it.name} (${it.email})`,
346
- })),
347
- )
339
+ const author = qb.fragment('Author', it =>
340
+ it
341
+ .$$()
342
+ .transform(it => ({
343
+ ...it,
344
+ label: `${it.name} (${it.email})`,
345
+ })))
348
346
 
349
347
  const result = await client.query({
350
- post: qb.get('Post', { by: { id: '123' } }, it => it
351
- .$$()
352
- .$('author', author),
353
- ),
348
+ post: qb.get('Post', { by: { id: '123' } }, it =>
349
+ it
350
+ .$$()
351
+ .$('author', author)),
354
352
  })
355
353
  expect(result as any).toStrictEqual({
356
354
  post: {
@@ -362,9 +360,9 @@ describe('queries', () => {
362
360
  },
363
361
  },
364
362
  })
363
+ expect(calls).toMatchSnapshot()
365
364
  })
366
365
 
367
-
368
366
  test('nested has-many-by transform', async () => {
369
367
  const [client, calls] = createClient({
370
368
  post: {
@@ -375,13 +373,14 @@ describe('queries', () => {
375
373
  },
376
374
  })
377
375
  const result = await client.query({
378
- post: qb.get('Post', { by: { id: '123' } }, it => it
379
- .$$()
380
- .$('localesByLocale', { by: { locale: { code: 'en' } } }, it => it.$$().transform(it => ({
381
- ...it,
382
- label: it.title?.toUpperCase(),
383
- }))),
384
- ),
376
+ post: qb.get('Post', { by: { id: '123' } }, it =>
377
+ it
378
+ .$$()
379
+ .$('localesByLocale', { by: { locale: { code: 'en' } } }, it =>
380
+ it.$$().transform(it => ({
381
+ ...it,
382
+ label: it.title?.toUpperCase(),
383
+ })))),
385
384
  })
386
385
  expect(result as any).toStrictEqual({
387
386
  post: {
@@ -392,6 +391,7 @@ describe('queries', () => {
392
391
  },
393
392
  },
394
393
  })
394
+ expect(calls).toMatchSnapshot()
395
395
  })
396
396
 
397
397
  test('multiple transforms', async () => {
@@ -410,21 +410,22 @@ describe('queries', () => {
410
410
  },
411
411
  })
412
412
  const result = await client.query({
413
- author: qb.get('Author', { by: { id: '123' } }, it => it
414
- .$$()
415
- .transform(it => ({
416
- ...it,
417
- value1: 'foo',
418
- }))
419
- .$('posts', {}, it => it.$$().transform(it => ({
420
- ...it,
421
- postLabel: 'foo bar',
422
- })))
423
- .transform(it => ({
424
- ...it,
425
- value2: 'bar',
426
- })),
427
- ),
413
+ author: qb.get('Author', { by: { id: '123' } }, it =>
414
+ it
415
+ .$$()
416
+ .transform(it => ({
417
+ ...it,
418
+ value1: 'foo',
419
+ }))
420
+ .$('posts', {}, it =>
421
+ it.$$().transform(it => ({
422
+ ...it,
423
+ postLabel: 'foo bar',
424
+ })))
425
+ .transform(it => ({
426
+ ...it,
427
+ value2: 'bar',
428
+ }))),
428
429
  })
429
430
  expect(result as any).toStrictEqual({
430
431
  author: {
@@ -447,4 +448,28 @@ describe('queries', () => {
447
448
  expect(calls).toHaveLength(1)
448
449
  })
449
450
 
451
+ test('omit', async () => {
452
+ const [client, calls] = createClient({
453
+ authors: [
454
+ {
455
+ id: '1',
456
+ name: 'John',
457
+ },
458
+ ],
459
+ })
460
+ const result = await client.query({
461
+ authors: qb.list('Author', {}, it => it.$$().omit('email').$('posts', {}, it => it.$$()).omit('posts')),
462
+ })
463
+ expect(result).toStrictEqual({
464
+ authors: [
465
+ {
466
+ id: '1',
467
+ name: 'John',
468
+ },
469
+ ],
470
+ })
471
+ expect(calls).toHaveLength(1)
472
+ expect(calls[0].query).toMatchSnapshot()
473
+ expect(calls[0].variables).toStrictEqual({})
474
+ })
450
475
  })