@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.
- package/package.json +6 -6
- package/src/ContentClient.ts +36 -9
- package/src/ContentQueryBuilder.ts +44 -35
- package/src/MutationFailedError.ts +19 -0
- package/src/TypedContentQueryBuilder.ts +0 -4
- package/src/nodes/ContentEntitySelection.ts +35 -17
- package/src/nodes/TypedEntitySelection.ts +96 -48
- package/src/types/Input.ts +1 -9
- package/src/types/Result.ts +41 -9
- package/src/types/Schema.ts +0 -1
- package/src/utils/createListArgs.ts +5 -1
- package/src/utils/createMutationOperationSet.ts +9 -7
- package/src/utils/createQueryOperationSet.ts +0 -1
- package/tests/cases/unit/__snapshots__/mutation.test.ts.snap +952 -818
- package/tests/cases/unit/__snapshots__/query.test.ts.snap +200 -60
- package/tests/cases/unit/mutation.test.ts +48 -3
- package/tests/cases/unit/query.test.ts +91 -66
- package/tests/cases/unit/types.test.ts +31 -27
- package/tests/client/entities.ts +2 -0
- package/tests/client/enums.ts +5 -0
- package/tests/client/names.ts +129 -117
- package/tests/generate.ts +0 -1
- package/tests/lib.ts +0 -1
- package/tests/schema.ts +1 -2
- package/dist/development/index.cjs +0 -13
- package/dist/development/index.cjs.map +0 -1
- package/dist/development/index.js +0 -13
- package/dist/development/index.js.map +0 -1
- package/dist/development/src/ContentClient.cjs +0 -27
- package/dist/development/src/ContentClient.cjs.map +0 -1
- package/dist/development/src/ContentClient.js +0 -27
- package/dist/development/src/ContentClient.js.map +0 -1
- package/dist/development/src/ContentQueryBuilder.cjs +0 -175
- package/dist/development/src/ContentQueryBuilder.cjs.map +0 -1
- package/dist/development/src/ContentQueryBuilder.js +0 -175
- package/dist/development/src/ContentQueryBuilder.js.map +0 -1
- package/dist/development/src/nodes/ContentEntitySelection.cjs +0 -207
- package/dist/development/src/nodes/ContentEntitySelection.cjs.map +0 -1
- package/dist/development/src/nodes/ContentEntitySelection.js +0 -207
- package/dist/development/src/nodes/ContentEntitySelection.js.map +0 -1
- package/dist/development/src/nodes/ContentOperation.cjs +0 -16
- package/dist/development/src/nodes/ContentOperation.cjs.map +0 -1
- package/dist/development/src/nodes/ContentOperation.js +0 -16
- package/dist/development/src/nodes/ContentOperation.js.map +0 -1
- package/dist/development/src/utils/ContentOperationSet.cjs +0 -10
- package/dist/development/src/utils/ContentOperationSet.cjs.map +0 -1
- package/dist/development/src/utils/ContentOperationSet.js +0 -10
- package/dist/development/src/utils/ContentOperationSet.js.map +0 -1
- package/dist/development/src/utils/createListArgs.cjs +0 -24
- package/dist/development/src/utils/createListArgs.cjs.map +0 -1
- package/dist/development/src/utils/createListArgs.js +0 -24
- package/dist/development/src/utils/createListArgs.js.map +0 -1
- package/dist/development/src/utils/createMutationOperationSet.cjs +0 -37
- package/dist/development/src/utils/createMutationOperationSet.cjs.map +0 -1
- package/dist/development/src/utils/createMutationOperationSet.js +0 -37
- package/dist/development/src/utils/createMutationOperationSet.js.map +0 -1
- package/dist/development/src/utils/createQueryOperationSet.cjs +0 -19
- package/dist/development/src/utils/createQueryOperationSet.cjs.map +0 -1
- package/dist/development/src/utils/createQueryOperationSet.js +0 -19
- package/dist/development/src/utils/createQueryOperationSet.js.map +0 -1
- package/dist/development/src/utils/createTypedArgs.cjs +0 -17
- package/dist/development/src/utils/createTypedArgs.cjs.map +0 -1
- package/dist/development/src/utils/createTypedArgs.js +0 -17
- package/dist/development/src/utils/createTypedArgs.js.map +0 -1
- package/dist/development/src/utils/mutationFragments.cjs +0 -55
- package/dist/development/src/utils/mutationFragments.cjs.map +0 -1
- package/dist/development/src/utils/mutationFragments.js +0 -55
- package/dist/development/src/utils/mutationFragments.js.map +0 -1
- package/dist/production/index.cjs +0 -13
- package/dist/production/index.cjs.map +0 -1
- package/dist/production/index.js +0 -13
- package/dist/production/index.js.map +0 -1
- package/dist/production/src/ContentClient.cjs +0 -27
- package/dist/production/src/ContentClient.cjs.map +0 -1
- package/dist/production/src/ContentClient.js +0 -27
- package/dist/production/src/ContentClient.js.map +0 -1
- package/dist/production/src/ContentQueryBuilder.cjs +0 -175
- package/dist/production/src/ContentQueryBuilder.cjs.map +0 -1
- package/dist/production/src/ContentQueryBuilder.js +0 -175
- package/dist/production/src/ContentQueryBuilder.js.map +0 -1
- package/dist/production/src/nodes/ContentEntitySelection.cjs +0 -207
- package/dist/production/src/nodes/ContentEntitySelection.cjs.map +0 -1
- package/dist/production/src/nodes/ContentEntitySelection.js +0 -207
- package/dist/production/src/nodes/ContentEntitySelection.js.map +0 -1
- package/dist/production/src/nodes/ContentOperation.cjs +0 -16
- package/dist/production/src/nodes/ContentOperation.cjs.map +0 -1
- package/dist/production/src/nodes/ContentOperation.js +0 -16
- package/dist/production/src/nodes/ContentOperation.js.map +0 -1
- package/dist/production/src/utils/ContentOperationSet.cjs +0 -10
- package/dist/production/src/utils/ContentOperationSet.cjs.map +0 -1
- package/dist/production/src/utils/ContentOperationSet.js +0 -10
- package/dist/production/src/utils/ContentOperationSet.js.map +0 -1
- package/dist/production/src/utils/createListArgs.cjs +0 -24
- package/dist/production/src/utils/createListArgs.cjs.map +0 -1
- package/dist/production/src/utils/createListArgs.js +0 -24
- package/dist/production/src/utils/createListArgs.js.map +0 -1
- package/dist/production/src/utils/createMutationOperationSet.cjs +0 -37
- package/dist/production/src/utils/createMutationOperationSet.cjs.map +0 -1
- package/dist/production/src/utils/createMutationOperationSet.js +0 -37
- package/dist/production/src/utils/createMutationOperationSet.js.map +0 -1
- package/dist/production/src/utils/createQueryOperationSet.cjs +0 -19
- package/dist/production/src/utils/createQueryOperationSet.cjs.map +0 -1
- package/dist/production/src/utils/createQueryOperationSet.js +0 -19
- package/dist/production/src/utils/createQueryOperationSet.js.map +0 -1
- package/dist/production/src/utils/createTypedArgs.cjs +0 -17
- package/dist/production/src/utils/createTypedArgs.cjs.map +0 -1
- package/dist/production/src/utils/createTypedArgs.js +0 -17
- package/dist/production/src/utils/createTypedArgs.js.map +0 -1
- package/dist/production/src/utils/mutationFragments.cjs +0 -55
- package/dist/production/src/utils/mutationFragments.cjs.map +0 -1
- package/dist/production/src/utils/mutationFragments.js +0 -55
- package/dist/production/src/utils/mutationFragments.js.map +0 -1
- package/dist/types/ContentClient.d.ts +0 -17
- package/dist/types/ContentClient.d.ts.map +0 -1
- package/dist/types/ContentQueryBuilder.d.ts +0 -27
- package/dist/types/ContentQueryBuilder.d.ts.map +0 -1
- package/dist/types/TypedContentQueryBuilder.d.ts +0 -21
- package/dist/types/TypedContentQueryBuilder.d.ts.map +0 -1
- package/dist/types/index.d.ts +0 -7
- package/dist/types/index.d.ts.map +0 -1
- package/dist/types/nodes/ContentEntitySelection.d.ts +0 -61
- package/dist/types/nodes/ContentEntitySelection.d.ts.map +0 -1
- package/dist/types/nodes/ContentOperation.d.ts +0 -30
- package/dist/types/nodes/ContentOperation.d.ts.map +0 -1
- package/dist/types/nodes/TypedEntitySelection.d.ts +0 -53
- package/dist/types/nodes/TypedEntitySelection.d.ts.map +0 -1
- package/dist/types/nodes/index.d.ts +0 -4
- package/dist/types/nodes/index.d.ts.map +0 -1
- package/dist/types/tsconfig.tsbuildinfo +0 -1
- package/dist/types/types/Input.d.ts +0 -201
- package/dist/types/types/Input.d.ts.map +0 -1
- package/dist/types/types/Result.d.ts +0 -39
- package/dist/types/types/Result.d.ts.map +0 -1
- package/dist/types/types/Schema.d.ts +0 -46
- package/dist/types/types/Schema.d.ts.map +0 -1
- package/dist/types/types/index.d.ts +0 -4
- package/dist/types/types/index.d.ts.map +0 -1
- package/dist/types/utils/ContentOperationSet.d.ts +0 -13
- package/dist/types/utils/ContentOperationSet.d.ts.map +0 -1
- package/dist/types/utils/createListArgs.d.ts +0 -9
- package/dist/types/utils/createListArgs.d.ts.map +0 -1
- package/dist/types/utils/createMutationOperationSet.d.ts +0 -4
- package/dist/types/utils/createMutationOperationSet.d.ts.map +0 -1
- package/dist/types/utils/createQueryOperationSet.d.ts +0 -4
- package/dist/types/utils/createQueryOperationSet.d.ts.map +0 -1
- package/dist/types/utils/createTypedArgs.d.ts +0 -3
- package/dist/types/utils/createTypedArgs.d.ts.map +0 -1
- package/dist/types/utils/mutationFragments.d.ts +0 -3
- package/dist/types/utils/mutationFragments.d.ts.map +0 -1
|
@@ -1,102 +1,242 @@
|
|
|
1
|
-
// Bun Snapshot v1, https://
|
|
1
|
+
// Bun Snapshot v1, https://bun.sh/docs/test/snapshots
|
|
2
2
|
|
|
3
3
|
exports[`queries list 1`] = `
|
|
4
4
|
"query {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
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
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
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
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
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
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
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
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
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
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
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
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
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
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
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 =>
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
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 =>
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
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 =>
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
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 =>
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
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 =>
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
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 =>
|
|
351
|
-
|
|
352
|
-
|
|
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 =>
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
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 =>
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
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
|
})
|