@contember/client-content 2.1.0-alpha.30 → 2.1.0-alpha.36
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 +23 -16
- package/src/ContentQueryBuilder.ts +44 -35
- package/src/MutationFailedError.ts +8 -6
- package/src/TypedContentQueryBuilder.ts +0 -4
- package/src/nodes/ContentEntitySelection.ts +19 -14
- package/src/nodes/TypedEntitySelection.ts +92 -48
- package/src/types/Input.ts +1 -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 +814 -878
- package/tests/cases/unit/__snapshots__/query.test.ts.snap +84 -77
- package/tests/cases/unit/mutation.test.ts +0 -4
- package/tests/cases/unit/query.test.ts +62 -67
- package/tests/cases/unit/types.test.ts +26 -28
- 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 -39
- package/dist/development/src/ContentClient.cjs.map +0 -1
- package/dist/development/src/ContentClient.js +0 -39
- 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/MutationFailedError.cjs +0 -11
- package/dist/development/src/MutationFailedError.cjs.map +0 -1
- package/dist/development/src/MutationFailedError.js +0 -11
- package/dist/development/src/MutationFailedError.js.map +0 -1
- package/dist/development/src/nodes/ContentEntitySelection.cjs +0 -219
- package/dist/development/src/nodes/ContentEntitySelection.cjs.map +0 -1
- package/dist/development/src/nodes/ContentEntitySelection.js +0 -219
- 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 -39
- package/dist/production/src/ContentClient.cjs.map +0 -1
- package/dist/production/src/ContentClient.js +0 -39
- 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/MutationFailedError.cjs +0 -11
- package/dist/production/src/MutationFailedError.cjs.map +0 -1
- package/dist/production/src/MutationFailedError.js +0 -11
- package/dist/production/src/MutationFailedError.js.map +0 -1
- package/dist/production/src/nodes/ContentEntitySelection.cjs +0 -219
- package/dist/production/src/nodes/ContentEntitySelection.cjs.map +0 -1
- package/dist/production/src/nodes/ContentEntitySelection.js +0 -219
- 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 -27
- 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/MutationFailedError.d.ts +0 -13
- package/dist/types/MutationFailedError.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 -62
- 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 -54
- 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 -60
- 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,138 +1,134 @@
|
|
|
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
|
+
}
|
|
100
104
|
}
|
|
101
105
|
"
|
|
102
106
|
`;
|
|
103
107
|
|
|
104
|
-
exports[`queries
|
|
108
|
+
exports[`queries top level list transform 1`] = `
|
|
105
109
|
[
|
|
106
110
|
{
|
|
107
111
|
"query":
|
|
108
|
-
"query
|
|
109
|
-
|
|
112
|
+
"query {
|
|
113
|
+
authors: listAuthor {
|
|
110
114
|
id
|
|
111
115
|
name
|
|
112
116
|
email
|
|
113
|
-
posts {
|
|
114
|
-
id
|
|
115
|
-
publishedAt
|
|
116
|
-
}
|
|
117
117
|
}
|
|
118
118
|
}
|
|
119
119
|
"
|
|
120
120
|
,
|
|
121
|
-
"variables": {
|
|
122
|
-
"AuthorUniqueWhere_0": {
|
|
123
|
-
"id": "123",
|
|
124
|
-
},
|
|
125
|
-
},
|
|
121
|
+
"variables": {},
|
|
126
122
|
},
|
|
127
123
|
]
|
|
128
124
|
`;
|
|
129
125
|
|
|
130
|
-
exports[`queries top level
|
|
126
|
+
exports[`queries top level get transform 1`] = `
|
|
131
127
|
[
|
|
132
128
|
{
|
|
133
129
|
"query":
|
|
134
|
-
"query {
|
|
135
|
-
|
|
130
|
+
"query($AuthorUniqueWhere_0: AuthorUniqueWhere!) {
|
|
131
|
+
author: getAuthor(by: $AuthorUniqueWhere_0) {
|
|
136
132
|
id
|
|
137
133
|
name
|
|
138
134
|
email
|
|
@@ -140,12 +136,16 @@ exports[`queries top level list transform 1`] = `
|
|
|
140
136
|
}
|
|
141
137
|
"
|
|
142
138
|
,
|
|
143
|
-
"variables": {
|
|
139
|
+
"variables": {
|
|
140
|
+
"AuthorUniqueWhere_0": {
|
|
141
|
+
"id": "123",
|
|
142
|
+
},
|
|
143
|
+
},
|
|
144
144
|
},
|
|
145
145
|
]
|
|
146
146
|
`;
|
|
147
147
|
|
|
148
|
-
exports[`queries
|
|
148
|
+
exports[`queries nested has-many transform 1`] = `
|
|
149
149
|
[
|
|
150
150
|
{
|
|
151
151
|
"query":
|
|
@@ -154,6 +154,11 @@ exports[`queries top level get transform 1`] = `
|
|
|
154
154
|
id
|
|
155
155
|
name
|
|
156
156
|
email
|
|
157
|
+
posts {
|
|
158
|
+
id
|
|
159
|
+
publishedAt
|
|
160
|
+
status
|
|
161
|
+
}
|
|
157
162
|
}
|
|
158
163
|
}
|
|
159
164
|
"
|
|
@@ -175,6 +180,7 @@ exports[`queries nested has-one transform 1`] = `
|
|
|
175
180
|
post: getPost(by: $PostUniqueWhere_0) {
|
|
176
181
|
id
|
|
177
182
|
publishedAt
|
|
183
|
+
status
|
|
178
184
|
author {
|
|
179
185
|
id
|
|
180
186
|
name
|
|
@@ -201,6 +207,7 @@ exports[`queries nested has-many-by transform 1`] = `
|
|
|
201
207
|
post: getPost(by: $PostUniqueWhere_0) {
|
|
202
208
|
id
|
|
203
209
|
publishedAt
|
|
210
|
+
status
|
|
204
211
|
localesByLocale(by: $PostLocalesByLocaleUniqueWhere_1) {
|
|
205
212
|
id
|
|
206
213
|
title
|
|
@@ -22,7 +22,6 @@ describe('mutations in trx', () => {
|
|
|
22
22
|
}))
|
|
23
23
|
const result = await client.mutate(createAuthor)
|
|
24
24
|
|
|
25
|
-
|
|
26
25
|
expect(result.data.ok).toBe(true)
|
|
27
26
|
expect(calls).toHaveLength(1)
|
|
28
27
|
expect(calls[0].query).toMatchSnapshot()
|
|
@@ -303,7 +302,6 @@ describe('mutations in trx', () => {
|
|
|
303
302
|
expect(calls[0].query).toMatchSnapshot()
|
|
304
303
|
expect(calls[0].variables).toMatchSnapshot()
|
|
305
304
|
})
|
|
306
|
-
|
|
307
305
|
})
|
|
308
306
|
describe('mutations without trx', () => {
|
|
309
307
|
test('create', async () => {
|
|
@@ -320,7 +318,6 @@ describe('mutations without trx', () => {
|
|
|
320
318
|
})
|
|
321
319
|
const result = await client.mutate(createAuthor)
|
|
322
320
|
|
|
323
|
-
|
|
324
321
|
expect(result.ok).toBe(true)
|
|
325
322
|
expect(calls).toHaveLength(1)
|
|
326
323
|
expect(calls[0].query).toMatchSnapshot()
|
|
@@ -541,7 +538,6 @@ describe('mutations without trx', () => {
|
|
|
541
538
|
expect(calls[0].variables).toMatchSnapshot()
|
|
542
539
|
})
|
|
543
540
|
|
|
544
|
-
|
|
545
541
|
test('mutate or fail - ok', async () => {
|
|
546
542
|
const [client, calls] = createClient({
|
|
547
543
|
mut: {
|
|
@@ -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: [
|
|
@@ -266,13 +262,13 @@ describe('queries', () => {
|
|
|
266
262
|
},
|
|
267
263
|
})
|
|
268
264
|
const result = await client.query({
|
|
269
|
-
author: qb.get('Author', { by: { id: '123' } }, it =>
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
265
|
+
author: qb.get('Author', { by: { id: '123' } }, it =>
|
|
266
|
+
it
|
|
267
|
+
.$$()
|
|
268
|
+
.transform(it => ({
|
|
269
|
+
...it,
|
|
270
|
+
label: `${it.name} (${it.email})`,
|
|
271
|
+
}))),
|
|
276
272
|
})
|
|
277
273
|
expect(result as any).toStrictEqual({
|
|
278
274
|
author: {
|
|
@@ -285,7 +281,6 @@ describe('queries', () => {
|
|
|
285
281
|
expect(calls).toMatchSnapshot()
|
|
286
282
|
})
|
|
287
283
|
|
|
288
|
-
|
|
289
284
|
test('nested has-many transform', async () => {
|
|
290
285
|
const [client, calls] = createClient({
|
|
291
286
|
author: {
|
|
@@ -302,13 +297,14 @@ describe('queries', () => {
|
|
|
302
297
|
},
|
|
303
298
|
})
|
|
304
299
|
const result = await client.query({
|
|
305
|
-
author: qb.get('Author', { by: { id: '123' } }, it =>
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
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
|
+
})))),
|
|
312
308
|
})
|
|
313
309
|
expect(result as any).toStrictEqual({
|
|
314
310
|
author: {
|
|
@@ -330,7 +326,6 @@ describe('queries', () => {
|
|
|
330
326
|
expect(calls).toMatchSnapshot()
|
|
331
327
|
})
|
|
332
328
|
|
|
333
|
-
|
|
334
329
|
test('nested has-one transform', async () => {
|
|
335
330
|
const [client, calls] = createClient({
|
|
336
331
|
post: {
|
|
@@ -341,19 +336,19 @@ describe('queries', () => {
|
|
|
341
336
|
},
|
|
342
337
|
},
|
|
343
338
|
})
|
|
344
|
-
const author = qb.fragment('Author', it =>
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
339
|
+
const author = qb.fragment('Author', it =>
|
|
340
|
+
it
|
|
341
|
+
.$$()
|
|
342
|
+
.transform(it => ({
|
|
343
|
+
...it,
|
|
344
|
+
label: `${it.name} (${it.email})`,
|
|
345
|
+
})))
|
|
351
346
|
|
|
352
347
|
const result = await client.query({
|
|
353
|
-
post: qb.get('Post', { by: { id: '123' } }, it =>
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
348
|
+
post: qb.get('Post', { by: { id: '123' } }, it =>
|
|
349
|
+
it
|
|
350
|
+
.$$()
|
|
351
|
+
.$('author', author)),
|
|
357
352
|
})
|
|
358
353
|
expect(result as any).toStrictEqual({
|
|
359
354
|
post: {
|
|
@@ -368,7 +363,6 @@ describe('queries', () => {
|
|
|
368
363
|
expect(calls).toMatchSnapshot()
|
|
369
364
|
})
|
|
370
365
|
|
|
371
|
-
|
|
372
366
|
test('nested has-many-by transform', async () => {
|
|
373
367
|
const [client, calls] = createClient({
|
|
374
368
|
post: {
|
|
@@ -379,13 +373,14 @@ describe('queries', () => {
|
|
|
379
373
|
},
|
|
380
374
|
})
|
|
381
375
|
const result = await client.query({
|
|
382
|
-
post: qb.get('Post', { by: { id: '123' } }, it =>
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
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
|
+
})))),
|
|
389
384
|
})
|
|
390
385
|
expect(result as any).toStrictEqual({
|
|
391
386
|
post: {
|
|
@@ -415,21 +410,22 @@ describe('queries', () => {
|
|
|
415
410
|
},
|
|
416
411
|
})
|
|
417
412
|
const result = await client.query({
|
|
418
|
-
author: qb.get('Author', { by: { id: '123' } }, it =>
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
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
|
+
}))),
|
|
433
429
|
})
|
|
434
430
|
expect(result as any).toStrictEqual({
|
|
435
431
|
author: {
|
|
@@ -476,5 +472,4 @@ describe('queries', () => {
|
|
|
476
472
|
expect(calls[0].query).toMatchSnapshot()
|
|
477
473
|
expect(calls[0].variables).toStrictEqual({})
|
|
478
474
|
})
|
|
479
|
-
|
|
480
475
|
})
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/* eslint-disable @typescript-eslint/ban-ts-comment */
|
|
2
2
|
import { describe, expect, test } from 'bun:test'
|
|
3
3
|
import { ContentClientInput } from '../../../src'
|
|
4
|
-
import { ContemberClientEntities, FragmentOf, FragmentType, queryBuilder } from '../../client'
|
|
4
|
+
import { ContemberClientEntities, FragmentOf, FragmentType, PostStatus, queryBuilder } from '../../client'
|
|
5
5
|
import { expectTypeOf } from 'expect-type'
|
|
6
6
|
|
|
7
7
|
const qb = queryBuilder
|
|
@@ -75,10 +75,11 @@ describe('ts types', () => {
|
|
|
75
75
|
test('has one field on fragment type', async () => {
|
|
76
76
|
const fragment = qb.fragment('Post', it => it.$('author', it => it.$$().$('posts', it => it.$('id'))))
|
|
77
77
|
type fragmentType = FragmentType<typeof fragment>
|
|
78
|
-
expectTypeOf<fragmentType>().toEqualTypeOf<
|
|
78
|
+
expectTypeOf<fragmentType>().toEqualTypeOf<
|
|
79
|
+
{ author: ({ id: string; name: string | null; email: string | null } & { posts: { id: string }[] }) | null }
|
|
80
|
+
>()
|
|
79
81
|
})
|
|
80
82
|
|
|
81
|
-
|
|
82
83
|
test('has one without arg', async () => {
|
|
83
84
|
qb.list('Post', {}, it => it.$('author', it => it.$$()))
|
|
84
85
|
})
|
|
@@ -88,13 +89,13 @@ describe('ts types', () => {
|
|
|
88
89
|
})
|
|
89
90
|
|
|
90
91
|
test('has one with invalid arg', async () => {
|
|
91
|
-
qb.list('Post', {}, it =>
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
92
|
+
qb.list('Post', {}, it =>
|
|
93
|
+
it
|
|
94
|
+
.$(
|
|
95
|
+
'author', // @ts-expect-error
|
|
96
|
+
{ filter: { foo: { eq: 'xx' } } },
|
|
97
|
+
it => it.$$(),
|
|
98
|
+
))
|
|
98
99
|
})
|
|
99
100
|
|
|
100
101
|
test('has many without arg', async () => {
|
|
@@ -102,36 +103,33 @@ describe('ts types', () => {
|
|
|
102
103
|
})
|
|
103
104
|
|
|
104
105
|
test('has many with arg', async () => {
|
|
105
|
-
qb.list('Post', {}, it => it.$('locales', { filter: { locale: { code: { eq: 'cs' } } } },
|
|
106
|
+
qb.list('Post', {}, it => it.$('locales', { filter: { locale: { code: { eq: 'cs' } } } }, it => it.$$()))
|
|
106
107
|
})
|
|
107
108
|
|
|
108
109
|
test('has many with invalid arg', async () => {
|
|
109
|
-
qb.list('Post', {}, it =>
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
110
|
+
qb.list('Post', {}, it =>
|
|
111
|
+
it
|
|
112
|
+
.$(
|
|
113
|
+
'locales', // @ts-expect-error
|
|
114
|
+
{ filter: { locale: { eq: 'cs' } } },
|
|
115
|
+
it => it.$$(),
|
|
116
|
+
))
|
|
116
117
|
})
|
|
117
118
|
|
|
118
119
|
test('reduced has may', async () => {
|
|
119
|
-
qb.list('Post', {}, it => it.$('localesByLocale', { by: { locale: { code: 'cs' } } },
|
|
120
|
+
qb.list('Post', {}, it => it.$('localesByLocale', { by: { locale: { code: 'cs' } } }, it => it.$$()))
|
|
120
121
|
})
|
|
121
122
|
|
|
122
123
|
test('reduced has may - invalid "by"', async () => {
|
|
123
|
-
qb.list('Post',
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
// @ts-expect-error
|
|
124
|
+
qb.list('Post', {}, it =>
|
|
125
|
+
it
|
|
126
|
+
.$(
|
|
127
|
+
'localesByLocale', // @ts-expect-error
|
|
128
128
|
{ by: { locale: {} } },
|
|
129
129
|
qb.fragment('PostLocale'),
|
|
130
|
-
)
|
|
131
|
-
)
|
|
130
|
+
))
|
|
132
131
|
})
|
|
133
132
|
|
|
134
|
-
|
|
135
133
|
test('invalid field', async () => {
|
|
136
134
|
expect(() => {
|
|
137
135
|
qb.list(
|
|
@@ -146,6 +144,6 @@ describe('ts types', () => {
|
|
|
146
144
|
test('omit', async () => {
|
|
147
145
|
const fragment = qb.fragment('Post', it => it.$$().omit('publishedAt'))
|
|
148
146
|
type fragmentType = FragmentType<typeof fragment>
|
|
149
|
-
expectTypeOf<fragmentType>().toEqualTypeOf<{ id: string }>()
|
|
147
|
+
expectTypeOf<fragmentType>().toEqualTypeOf<{ id: string; status: PostStatus | null }>()
|
|
150
148
|
})
|
|
151
149
|
})
|
package/tests/client/entities.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { PostStatus } from './enums'
|
|
1
2
|
|
|
2
3
|
export type JSONPrimitive = string | number | boolean | null
|
|
3
4
|
export type JSONValue = JSONPrimitive | JSONObject | JSONArray
|
|
@@ -47,6 +48,7 @@ export type Post <OverRelation extends string | never = never> = {
|
|
|
47
48
|
columns: {
|
|
48
49
|
id: string
|
|
49
50
|
publishedAt: string | null
|
|
51
|
+
status: PostStatus | null
|
|
50
52
|
}
|
|
51
53
|
hasOne: {
|
|
52
54
|
author: Author
|