@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
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@contember/client-content",
|
|
3
3
|
"license": "Apache-2.0",
|
|
4
|
-
"version": "2.1.0-alpha.
|
|
4
|
+
"version": "2.1.0-alpha.35",
|
|
5
5
|
"main": "./dist/production/index.js",
|
|
6
6
|
"exports": {
|
|
7
7
|
".": {
|
|
@@ -29,17 +29,17 @@
|
|
|
29
29
|
"ae:test": "api-extractor run"
|
|
30
30
|
},
|
|
31
31
|
"dependencies": {
|
|
32
|
-
"@contember/graphql-builder": "
|
|
33
|
-
"@contember/graphql-client": "
|
|
34
|
-
"@contember/schema": "
|
|
32
|
+
"@contember/graphql-builder": "workspace:*",
|
|
33
|
+
"@contember/graphql-client": "workspace:*",
|
|
34
|
+
"@contember/schema": "workspace:*"
|
|
35
35
|
},
|
|
36
36
|
"devDependencies": {
|
|
37
|
-
"@contember/client-content-generator": "
|
|
37
|
+
"@contember/client-content-generator": "workspace:*",
|
|
38
38
|
"expect-type": "^1.1.0"
|
|
39
39
|
},
|
|
40
40
|
"repository": {
|
|
41
41
|
"type": "git",
|
|
42
|
-
"url": "https://github.com/contember/
|
|
42
|
+
"url": "git+https://github.com/contember/contember.git",
|
|
43
43
|
"directory": "packages/client-content"
|
|
44
44
|
}
|
|
45
45
|
}
|
package/src/ContentClient.ts
CHANGED
|
@@ -4,10 +4,10 @@ import { GraphQlQueryPrinter } from '@contember/graphql-builder'
|
|
|
4
4
|
import { ContentMutation, ContentQuery } from './nodes'
|
|
5
5
|
import { createMutationOperationSet } from './utils/createMutationOperationSet'
|
|
6
6
|
import { createQueryOperationSet } from './utils/createQueryOperationSet'
|
|
7
|
+
import { MutationError, ValidationResult } from './types'
|
|
8
|
+
import { MutationFailedError } from './MutationFailedError'
|
|
7
9
|
|
|
8
|
-
|
|
9
|
-
export type QueryExecutorOptions =
|
|
10
|
-
& GraphQlClientRequestOptions
|
|
10
|
+
export type QueryExecutorOptions = GraphQlClientRequestOptions
|
|
11
11
|
|
|
12
12
|
export class ContentClient {
|
|
13
13
|
constructor(
|
|
@@ -15,9 +15,11 @@ export class ContentClient {
|
|
|
15
15
|
) {
|
|
16
16
|
}
|
|
17
17
|
|
|
18
|
-
|
|
19
18
|
public async query<Value>(query: ContentQuery<Value>, options?: QueryExecutorOptions): Promise<Value>
|
|
20
|
-
public async query<Values extends Record<string, any>>(
|
|
19
|
+
public async query<Values extends Record<string, any>>(
|
|
20
|
+
queries: { [K in keyof Values]: ContentQuery<Values[K]> },
|
|
21
|
+
options?: QueryExecutorOptions,
|
|
22
|
+
): Promise<Values>
|
|
21
23
|
public async query(queries: Record<string, ContentQuery<any>> | ContentQuery<any>, options?: QueryExecutorOptions): Promise<any> {
|
|
22
24
|
const printer = new GraphQlQueryPrinter()
|
|
23
25
|
const operationSet = createQueryOperationSet(queries)
|
|
@@ -26,10 +28,16 @@ export class ContentClient {
|
|
|
26
28
|
return operationSet.parse(result)
|
|
27
29
|
}
|
|
28
30
|
|
|
29
|
-
public async mutate<Value>(mutation: ContentMutation<Value>, options?: QueryExecutorOptions
|
|
30
|
-
public async mutate<Value>(mutations: ContentMutation<Value>[], options?: QueryExecutorOptions
|
|
31
|
-
public async mutate<Values extends Record<string, any>>(
|
|
32
|
-
|
|
31
|
+
public async mutate<Value>(mutation: ContentMutation<Value>, options?: QueryExecutorOptions): Promise<Value>
|
|
32
|
+
public async mutate<Value>(mutations: ContentMutation<Value>[], options?: QueryExecutorOptions): Promise<Value[]>
|
|
33
|
+
public async mutate<Values extends Record<string, any>>(
|
|
34
|
+
mutations: { [K in keyof Values]: ContentMutation<Values[K]> | ContentQuery<Values[K]> },
|
|
35
|
+
options?: QueryExecutorOptions,
|
|
36
|
+
): Promise<Values>
|
|
37
|
+
public async mutate(
|
|
38
|
+
input: Record<string, ContentMutation<any> | ContentQuery<any>> | ContentMutation<any> | ContentMutation<any>[],
|
|
39
|
+
options?: QueryExecutorOptions,
|
|
40
|
+
): Promise<any> {
|
|
33
41
|
const operationSet = createMutationOperationSet(input)
|
|
34
42
|
|
|
35
43
|
const printer = new GraphQlQueryPrinter()
|
|
@@ -38,4 +46,23 @@ export class ContentClient {
|
|
|
38
46
|
|
|
39
47
|
return operationSet.parse(result)
|
|
40
48
|
}
|
|
49
|
+
|
|
50
|
+
public async mutateOrThrow<
|
|
51
|
+
Value extends {
|
|
52
|
+
readonly ok: boolean
|
|
53
|
+
readonly errorMessage: string | null
|
|
54
|
+
readonly errors: MutationError[]
|
|
55
|
+
readonly validation: ValidationResult
|
|
56
|
+
},
|
|
57
|
+
>(mutation: ContentMutation<Value>, options?: QueryExecutorOptions): Promise<Value & { readonly ok: true; readonly errorMessage: null }> {
|
|
58
|
+
const result = await this.mutate(mutation, options)
|
|
59
|
+
if (!result.ok) {
|
|
60
|
+
throw new MutationFailedError(
|
|
61
|
+
result.errorMessage ?? 'Unknown error',
|
|
62
|
+
mutation as ContentMutation<Value & { readonly ok: false; readonly errorMessage: string }>,
|
|
63
|
+
result as Value & { readonly ok: false; readonly errorMessage: string },
|
|
64
|
+
)
|
|
65
|
+
}
|
|
66
|
+
return result as Value & { readonly ok: true; readonly errorMessage: null }
|
|
67
|
+
}
|
|
41
68
|
}
|
|
@@ -1,5 +1,12 @@
|
|
|
1
1
|
import { ContentClientInput, MutationResult, SchemaNames, TransactionResult } from './types'
|
|
2
|
-
import {
|
|
2
|
+
import {
|
|
3
|
+
ContentEntitySelection,
|
|
4
|
+
ContentEntitySelectionCallback,
|
|
5
|
+
ContentEntitySelectionContext,
|
|
6
|
+
ContentMutation,
|
|
7
|
+
ContentOperation,
|
|
8
|
+
ContentQuery,
|
|
9
|
+
} from './nodes'
|
|
3
10
|
import { createListArgs } from './utils/createListArgs'
|
|
4
11
|
import { createTypedArgs } from './utils/createTypedArgs'
|
|
5
12
|
import { Input } from '@contember/schema'
|
|
@@ -21,7 +28,6 @@ export class ContentQueryBuilder {
|
|
|
21
28
|
constructor(private readonly schema: SchemaNames) {
|
|
22
29
|
}
|
|
23
30
|
|
|
24
|
-
|
|
25
31
|
public fragment(name: string, fieldsCallback?: ContentEntitySelectionCallback): ContentEntitySelection {
|
|
26
32
|
const context = this.createContext(name)
|
|
27
33
|
|
|
@@ -32,8 +38,6 @@ export class ContentQueryBuilder {
|
|
|
32
38
|
return fieldsCallback(entitySelection)
|
|
33
39
|
}
|
|
34
40
|
|
|
35
|
-
|
|
36
|
-
|
|
37
41
|
public count(name: string, args: Pick<ContentClientInput.AnyListQueryInput, 'filter'>): ContentQuery<number> {
|
|
38
42
|
const context = this.createContext(name)
|
|
39
43
|
const fieldName = `paginate${name}`
|
|
@@ -51,7 +55,6 @@ export class ContentQueryBuilder {
|
|
|
51
55
|
})
|
|
52
56
|
}
|
|
53
57
|
|
|
54
|
-
|
|
55
58
|
public list(name: string, args: ContentClientInput.AnyListQueryInput, fields: EntitySelectionOrCallback): ContentQuery<any[]> {
|
|
56
59
|
const context = this.createContext(name)
|
|
57
60
|
const fieldName = `list${name}`
|
|
@@ -61,15 +64,16 @@ export class ContentQueryBuilder {
|
|
|
61
64
|
return new ContentOperation('query', fieldName, typedArgs, selection.selectionSet, it => {
|
|
62
65
|
const transformFn = selection.transformFn
|
|
63
66
|
if (transformFn) {
|
|
64
|
-
return it.map((el: any) =>
|
|
65
|
-
|
|
66
|
-
|
|
67
|
+
return it.map((el: any) =>
|
|
68
|
+
transformFn(el, {
|
|
69
|
+
rootValue: it,
|
|
70
|
+
})
|
|
71
|
+
)
|
|
67
72
|
}
|
|
68
73
|
return it
|
|
69
74
|
})
|
|
70
75
|
}
|
|
71
76
|
|
|
72
|
-
|
|
73
77
|
public get(name: string, args: Input.UniqueQueryInput, fields: EntitySelectionOrCallback): ContentQuery<Record<string, unknown> | null> {
|
|
74
78
|
const context = this.createContext(name)
|
|
75
79
|
const fieldName = `get${name}`
|
|
@@ -89,9 +93,7 @@ export class ContentQueryBuilder {
|
|
|
89
93
|
})
|
|
90
94
|
}
|
|
91
95
|
|
|
92
|
-
|
|
93
96
|
public create(name: string, args: Input.CreateInput, fields?: EntitySelectionOrCallback): ContentMutation<MutationResult> {
|
|
94
|
-
|
|
95
97
|
const entity = this.getEntity(name)
|
|
96
98
|
const typedArgs = createTypedArgs(args, {
|
|
97
99
|
data: `${entity.name}CreateInput!`,
|
|
@@ -101,7 +103,6 @@ export class ContentQueryBuilder {
|
|
|
101
103
|
}
|
|
102
104
|
|
|
103
105
|
public update(name: string, args: Input.UpdateInput, fields?: EntitySelectionOrCallback): ContentMutation<MutationResult> {
|
|
104
|
-
|
|
105
106
|
const entity = this.getEntity(name)
|
|
106
107
|
const typedArgs = createTypedArgs(args, {
|
|
107
108
|
data: `${entity.name}UpdateInput!`,
|
|
@@ -111,9 +112,7 @@ export class ContentQueryBuilder {
|
|
|
111
112
|
return this.createMutationOperation(name, 'update', typedArgs, fields)
|
|
112
113
|
}
|
|
113
114
|
|
|
114
|
-
|
|
115
115
|
public upsert(name: string, args: Input.UpsertInput, fields?: EntitySelectionOrCallback): ContentMutation<MutationResult> {
|
|
116
|
-
|
|
117
116
|
const entity = this.getEntity(name)
|
|
118
117
|
const typedArgs = createTypedArgs(args, {
|
|
119
118
|
update: `${entity.name}UpdateInput!`,
|
|
@@ -124,9 +123,7 @@ export class ContentQueryBuilder {
|
|
|
124
123
|
return this.createMutationOperation(name, 'upsert', typedArgs, fields)
|
|
125
124
|
}
|
|
126
125
|
|
|
127
|
-
|
|
128
126
|
public delete(name: string, args: Input.UniqueQueryInput, fields?: EntitySelectionOrCallback): ContentMutation<MutationResult> {
|
|
129
|
-
|
|
130
127
|
const entity = this.getEntity(name)
|
|
131
128
|
const typedArgs = createTypedArgs(args, {
|
|
132
129
|
by: `${entity.name}UniqueWhere!`,
|
|
@@ -135,9 +132,12 @@ export class ContentQueryBuilder {
|
|
|
135
132
|
return this.createMutationOperation(name, 'delete', typedArgs, fields)
|
|
136
133
|
}
|
|
137
134
|
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
135
|
+
private createMutationOperation(
|
|
136
|
+
name: string,
|
|
137
|
+
operation: MutationOperation,
|
|
138
|
+
args: GraphQlFieldTypedArgs,
|
|
139
|
+
fields?: EntitySelectionOrCallback,
|
|
140
|
+
): ContentMutation<MutationResult> {
|
|
141
141
|
const context = this.createContext(name)
|
|
142
142
|
const fieldName = `${operation}${name}`
|
|
143
143
|
const nodeSelection = fields ? this.resolveSelection(fields, context) : undefined
|
|
@@ -149,9 +149,11 @@ export class ContentQueryBuilder {
|
|
|
149
149
|
}
|
|
150
150
|
return {
|
|
151
151
|
...it,
|
|
152
|
-
node: it.node
|
|
153
|
-
|
|
154
|
-
|
|
152
|
+
node: it.node
|
|
153
|
+
? nodeSelection.transformFn(it.node, {
|
|
154
|
+
rootValue: it.node,
|
|
155
|
+
})
|
|
156
|
+
: null,
|
|
155
157
|
}
|
|
156
158
|
})
|
|
157
159
|
}
|
|
@@ -169,15 +171,21 @@ export class ContentQueryBuilder {
|
|
|
169
171
|
...this.createMutationSelection('transaction'),
|
|
170
172
|
...combined.selection,
|
|
171
173
|
]
|
|
172
|
-
return new ContentOperation<TransactionResult<any>, 'mutation'>(
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
174
|
+
return new ContentOperation<TransactionResult<any>, 'mutation'>(
|
|
175
|
+
'mutation',
|
|
176
|
+
'transaction',
|
|
177
|
+
transactionArgs,
|
|
178
|
+
items,
|
|
179
|
+
({ ok, errorMessage, errors, validation, ...data }) => {
|
|
180
|
+
return {
|
|
181
|
+
ok,
|
|
182
|
+
errorMessage,
|
|
183
|
+
errors,
|
|
184
|
+
validation,
|
|
185
|
+
data: combined.parse(data),
|
|
186
|
+
}
|
|
187
|
+
},
|
|
188
|
+
)
|
|
181
189
|
}
|
|
182
190
|
|
|
183
191
|
private createMutationSelection(operation: MutationOperation, selection?: GraphQlSelectionSet): GraphQlSelectionSet {
|
|
@@ -189,9 +197,11 @@ export class ContentQueryBuilder {
|
|
|
189
197
|
]),
|
|
190
198
|
]
|
|
191
199
|
if (operation !== 'delete') {
|
|
192
|
-
items.push(
|
|
193
|
-
new
|
|
194
|
-
|
|
200
|
+
items.push(
|
|
201
|
+
new GraphQlField(null, 'validation', {}, [
|
|
202
|
+
new GraphQlFragmentSpread('ValidationResult'),
|
|
203
|
+
]),
|
|
204
|
+
)
|
|
195
205
|
}
|
|
196
206
|
if (selection) {
|
|
197
207
|
items.push(new GraphQlField(null, 'node', {}, selection))
|
|
@@ -199,7 +209,6 @@ export class ContentQueryBuilder {
|
|
|
199
209
|
return items
|
|
200
210
|
}
|
|
201
211
|
|
|
202
|
-
|
|
203
212
|
private resolveSelection(
|
|
204
213
|
fields: EntitySelectionOrCallback,
|
|
205
214
|
context: ContentEntitySelectionContext<string>,
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { MutationError, ValidationResult } from './types'
|
|
2
|
+
import { ContentMutation } from './nodes'
|
|
3
|
+
|
|
4
|
+
export class MutationFailedError<
|
|
5
|
+
Value extends {
|
|
6
|
+
readonly ok: false
|
|
7
|
+
readonly errorMessage: string
|
|
8
|
+
readonly errors: MutationError[]
|
|
9
|
+
readonly validation: ValidationResult
|
|
10
|
+
},
|
|
11
|
+
> extends Error {
|
|
12
|
+
constructor(
|
|
13
|
+
message: string,
|
|
14
|
+
public readonly request: ContentMutation<Value>,
|
|
15
|
+
public readonly result: Value,
|
|
16
|
+
) {
|
|
17
|
+
super(message)
|
|
18
|
+
}
|
|
19
|
+
}
|
|
@@ -2,14 +2,11 @@ import { ContentClientInput, MutationResult, SchemaTypeLike, TransactionResult }
|
|
|
2
2
|
import { ContentMutation, ContentQuery, TypedEntitySelection, TypedEntitySelectionCallback } from './nodes'
|
|
3
3
|
import { MutationTransactionOptions } from './ContentQueryBuilder'
|
|
4
4
|
|
|
5
|
-
|
|
6
5
|
export type TypedContentEntitySelectionOrCallback<TSchema extends SchemaTypeLike, TEntityName extends keyof TSchema['entities'] & string, TValue> =
|
|
7
6
|
| TypedEntitySelection<TSchema, TEntityName, TSchema['entities'][TEntityName], TValue>
|
|
8
7
|
| TypedEntitySelectionCallback<TSchema, TEntityName, TSchema['entities'][TEntityName], TValue>
|
|
9
8
|
|
|
10
|
-
|
|
11
9
|
export interface TypedContentQueryBuilder<TSchema extends SchemaTypeLike> {
|
|
12
|
-
|
|
13
10
|
fragment<EntityName extends keyof TSchema['entities'] & string>(
|
|
14
11
|
name: EntityName,
|
|
15
12
|
): TypedEntitySelection<TSchema, EntityName, TSchema['entities'][EntityName], {}>
|
|
@@ -73,4 +70,3 @@ export interface TypedContentQueryBuilder<TSchema extends SchemaTypeLike> {
|
|
|
73
70
|
options?: MutationTransactionOptions,
|
|
74
71
|
): ContentMutation<TransactionResult<Values>>
|
|
75
72
|
}
|
|
76
|
-
|
|
@@ -14,8 +14,12 @@ export type ContentEntitySelectionContext<Name extends string> = {
|
|
|
14
14
|
export type ContentEntitySelectionCallback = (select: ContentEntitySelection) => ContentEntitySelection
|
|
15
15
|
|
|
16
16
|
export type EntitySelectionCommonInput<Alias extends string | null = string | null> = { as?: Alias }
|
|
17
|
-
export type EntitySelectionManyArgs<Alias extends string | null = string | null> =
|
|
18
|
-
|
|
17
|
+
export type EntitySelectionManyArgs<Alias extends string | null = string | null> =
|
|
18
|
+
& ContentClientInput.AnyListQueryInput
|
|
19
|
+
& EntitySelectionCommonInput<Alias>
|
|
20
|
+
export type EntitySelectionManyByArgs<Alias extends string | null = string | null> =
|
|
21
|
+
& { by: Input.UniqueWhere; filter?: Input.Where }
|
|
22
|
+
& EntitySelectionCommonInput<Alias>
|
|
19
23
|
export type EntitySelectionOneArgs<Alias extends string | null = string | null> = { filter?: Input.Where } & EntitySelectionCommonInput<Alias>
|
|
20
24
|
export type EntitySelectionColumnArgs<Alias extends string | null = string | null> = EntitySelectionCommonInput<Alias>
|
|
21
25
|
|
|
@@ -27,13 +31,11 @@ export type EntitySelectionAnyArgs =
|
|
|
27
31
|
|
|
28
32
|
export type ContentEntitySelectionOrCallback = ContentEntitySelectionCallback | ContentEntitySelection
|
|
29
33
|
|
|
30
|
-
|
|
31
34
|
export type ContentTransformContext = {
|
|
32
35
|
rootValue: unknown
|
|
33
36
|
}
|
|
34
37
|
|
|
35
38
|
export class ContentEntitySelection {
|
|
36
|
-
|
|
37
39
|
/**
|
|
38
40
|
* @internal
|
|
39
41
|
*/
|
|
@@ -47,14 +49,17 @@ export class ContentEntitySelection {
|
|
|
47
49
|
) {
|
|
48
50
|
}
|
|
49
51
|
|
|
50
|
-
|
|
51
52
|
$(field: string, args?: EntitySelectionColumnArgs): ContentEntitySelection
|
|
52
53
|
$(field: string, args: EntitySelectionManyArgs, selection: ContentEntitySelectionOrCallback): ContentEntitySelection
|
|
53
54
|
$(field: string, args: EntitySelectionManyByArgs, selection: ContentEntitySelectionOrCallback): ContentEntitySelection
|
|
54
55
|
$(field: string, args: EntitySelectionOneArgs, selection: ContentEntitySelectionOrCallback): ContentEntitySelection
|
|
55
56
|
$(field: string, selection: ContentEntitySelectionOrCallback): ContentEntitySelection
|
|
56
57
|
|
|
57
|
-
$(
|
|
58
|
+
$(
|
|
59
|
+
field: string,
|
|
60
|
+
argsOrSelection?: EntitySelectionAnyArgs | ContentEntitySelectionOrCallback,
|
|
61
|
+
selectionIn?: ContentEntitySelectionOrCallback,
|
|
62
|
+
): ContentEntitySelection {
|
|
58
63
|
const [args, selection] = typeof argsOrSelection === 'function' || argsOrSelection instanceof ContentEntitySelection
|
|
59
64
|
? [{}, argsOrSelection]
|
|
60
65
|
: [argsOrSelection ?? {}, selectionIn]
|
|
@@ -99,6 +104,19 @@ export class ContentEntitySelection {
|
|
|
99
104
|
return new ContentEntitySelection(this.context, nodes)
|
|
100
105
|
}
|
|
101
106
|
|
|
107
|
+
omit(...fields: string[]): ContentEntitySelection {
|
|
108
|
+
return new ContentEntitySelection(
|
|
109
|
+
this.context,
|
|
110
|
+
this.selectionSet.filter(it => {
|
|
111
|
+
if (!(it instanceof GraphQlField)) {
|
|
112
|
+
return true
|
|
113
|
+
}
|
|
114
|
+
const alias = it.alias ?? it.name
|
|
115
|
+
return !fields.includes(alias)
|
|
116
|
+
}),
|
|
117
|
+
)
|
|
118
|
+
}
|
|
119
|
+
|
|
102
120
|
meta(field: string, flags: ('readable' | 'updatable')[]): ContentEntitySelection {
|
|
103
121
|
const metaField = this.selectionSet.find((it): it is GraphQlField => it instanceof GraphQlField && it.name === '_meta')
|
|
104
122
|
const selectionWithoutMeta = metaField ? this.selectionSet.filter(it => it !== metaField) : this.selectionSet
|
|
@@ -117,11 +135,14 @@ export class ContentEntitySelection {
|
|
|
117
135
|
])
|
|
118
136
|
}
|
|
119
137
|
|
|
120
|
-
|
|
121
138
|
transform(transform: (value: any, context: ContentTransformContext) => any): ContentEntitySelection {
|
|
122
|
-
return new ContentEntitySelection(
|
|
123
|
-
|
|
124
|
-
|
|
139
|
+
return new ContentEntitySelection(
|
|
140
|
+
this.context,
|
|
141
|
+
this.selectionSet,
|
|
142
|
+
!this.transformFn ? transform : (value, ctx) => {
|
|
143
|
+
return transform(this.transformFn!(value, ctx), ctx)
|
|
144
|
+
},
|
|
145
|
+
)
|
|
125
146
|
}
|
|
126
147
|
|
|
127
148
|
private _column(
|
|
@@ -142,14 +163,13 @@ export class ContentEntitySelection {
|
|
|
142
163
|
return this.withField(field)
|
|
143
164
|
}
|
|
144
165
|
|
|
145
|
-
|
|
146
166
|
private _many(
|
|
147
167
|
name: string,
|
|
148
168
|
args: EntitySelectionManyArgs,
|
|
149
169
|
fields:
|
|
150
170
|
| ContentEntitySelectionCallback
|
|
151
171
|
| ContentEntitySelection,
|
|
152
|
-
): ContentEntitySelection{
|
|
172
|
+
): ContentEntitySelection {
|
|
153
173
|
const alias = args.as ?? name
|
|
154
174
|
const fieldInfo = this.context.entity.fields[name]
|
|
155
175
|
if (!fieldInfo) {
|
|
@@ -177,10 +197,9 @@ export class ContentEntitySelection {
|
|
|
177
197
|
if (!nestedTransform) {
|
|
178
198
|
return selectionWithField
|
|
179
199
|
}
|
|
180
|
-
return
|
|
200
|
+
return selectionWithField.withFieldTransform(alias, it => it.map(nestedTransform))
|
|
181
201
|
}
|
|
182
202
|
|
|
183
|
-
|
|
184
203
|
private _manyBy(
|
|
185
204
|
name: string,
|
|
186
205
|
args: EntitySelectionManyByArgs,
|
|
@@ -229,7 +248,7 @@ export class ContentEntitySelection {
|
|
|
229
248
|
if (!nestedTransform) {
|
|
230
249
|
return selectionWithField
|
|
231
250
|
}
|
|
232
|
-
return
|
|
251
|
+
return selectionWithField.withFieldTransform(alias, (it, ctx) => it !== null ? nestedTransform(it, ctx) : null)
|
|
233
252
|
}
|
|
234
253
|
|
|
235
254
|
private _one(
|
|
@@ -273,10 +292,9 @@ export class ContentEntitySelection {
|
|
|
273
292
|
if (!nestedTransform) {
|
|
274
293
|
return selectionWithField
|
|
275
294
|
}
|
|
276
|
-
return
|
|
295
|
+
return selectionWithField.withFieldTransform(alias, (it, ctx) => it !== null ? nestedTransform(it, ctx) : null)
|
|
277
296
|
}
|
|
278
297
|
|
|
279
|
-
|
|
280
298
|
private withField(field: GraphQlField) {
|
|
281
299
|
return new ContentEntitySelection(this.context, [
|
|
282
300
|
...this.selectionSet,
|
|
@@ -2,38 +2,49 @@ import { EntityTypeLike, SchemaTypeLike } from '../types'
|
|
|
2
2
|
import { ContentClientInput } from '../types'
|
|
3
3
|
import { ContentEntitySelectionContext } from './ContentEntitySelection'
|
|
4
4
|
|
|
5
|
-
|
|
6
5
|
export interface TypedEntitySelection<TSchema extends SchemaTypeLike, TEntityName extends string, TEntity extends EntityTypeLike, TValue> {
|
|
7
|
-
|
|
8
6
|
/** @internal */
|
|
9
7
|
readonly context: ContentEntitySelectionContext<TEntityName>
|
|
10
8
|
|
|
11
|
-
$$(): TypedEntitySelection<
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
9
|
+
$$(): TypedEntitySelection<
|
|
10
|
+
TSchema,
|
|
11
|
+
TEntityName,
|
|
12
|
+
TEntity,
|
|
13
|
+
& TValue
|
|
14
|
+
& {
|
|
15
|
+
[key in keyof TEntity['columns']]: TEntity['columns'][key]
|
|
16
|
+
}
|
|
17
|
+
>
|
|
15
18
|
|
|
16
19
|
transform<T>(cb: (value: TValue) => T): TypedEntitySelection<TSchema, TEntityName, TEntity, T>
|
|
17
20
|
|
|
18
21
|
$<
|
|
19
22
|
TNestedValue,
|
|
20
23
|
TKey extends (keyof TEntity['columns'] | keyof TEntity['hasMany'] | keyof TEntity['hasManyBy'] | keyof TEntity['hasOne']) & string,
|
|
21
|
-
TAlias extends string | null = null
|
|
24
|
+
TAlias extends string | null = null,
|
|
22
25
|
>(
|
|
23
26
|
name: TKey,
|
|
24
27
|
...args: TypedEntitySelectionParams<TSchema, TEntity, TKey, TNestedValue, TAlias>
|
|
25
|
-
): TypedEntitySelection<
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
28
|
+
): TypedEntitySelection<
|
|
29
|
+
TSchema,
|
|
30
|
+
TEntityName,
|
|
31
|
+
TEntity,
|
|
32
|
+
& TValue
|
|
33
|
+
& {
|
|
34
|
+
[key in TAlias extends null ? TKey : TAlias]: TypedEntitySelectionResult<TEntity, TKey, TNestedValue>
|
|
35
|
+
}
|
|
36
|
+
>
|
|
37
|
+
|
|
38
|
+
omit<TField extends keyof TValue>(
|
|
39
|
+
...fields: TField[]
|
|
40
|
+
): TypedEntitySelection<TSchema, TEntityName, TEntity, Omit<TValue, TField>>
|
|
29
41
|
|
|
30
42
|
meta<
|
|
31
|
-
TField extends (keyof TEntity['columns'] | keyof TEntity['hasMany'] | keyof TEntity['hasOne'])
|
|
43
|
+
TField extends (keyof TEntity['columns'] | keyof TEntity['hasMany'] | keyof TEntity['hasOne']),
|
|
32
44
|
>(
|
|
33
45
|
field: TField,
|
|
34
46
|
flags: ('readable' | 'updatable')[],
|
|
35
47
|
): TypedEntitySelection<TSchema, TEntityName, TEntity, TValue>
|
|
36
|
-
|
|
37
48
|
}
|
|
38
49
|
|
|
39
50
|
export type TypedEntitySelectionCallback<
|
|
@@ -43,75 +54,112 @@ export type TypedEntitySelectionCallback<
|
|
|
43
54
|
TValue,
|
|
44
55
|
> = (select: TypedEntitySelection<TSchema, EntityName, TEntity, {}>) => TypedEntitySelection<TSchema, EntityName, TEntity, TValue>
|
|
45
56
|
|
|
46
|
-
|
|
47
57
|
export type TypedHasManyArgs<TEntity extends EntityTypeLike, TKey extends keyof TEntity['hasMany'] & string, TAlias extends string | null = null> =
|
|
48
58
|
& ContentClientInput.HasManyRelationInput<TEntity['hasMany'][TKey]>
|
|
49
59
|
& { as?: TAlias }
|
|
50
60
|
|
|
51
|
-
export type TypedHasManyFields<
|
|
61
|
+
export type TypedHasManyFields<
|
|
62
|
+
TSchema extends SchemaTypeLike,
|
|
63
|
+
TEntity extends EntityTypeLike,
|
|
64
|
+
TKey extends keyof TEntity['hasMany'] & string,
|
|
65
|
+
TNestedValue,
|
|
66
|
+
> =
|
|
52
67
|
| TypedEntitySelectionCallback<TSchema, TEntity['hasMany'][TKey]['name'], TEntity['hasMany'][TKey], TNestedValue>
|
|
53
68
|
| TypedEntitySelection<TSchema, TEntity['hasMany'][TKey]['name'], TEntity['hasMany'][TKey], TNestedValue>
|
|
54
69
|
|
|
55
|
-
export type TypedHasManyParams<
|
|
70
|
+
export type TypedHasManyParams<
|
|
71
|
+
TSchema extends SchemaTypeLike,
|
|
72
|
+
TEntity extends EntityTypeLike,
|
|
73
|
+
TKey extends keyof TEntity['hasMany'] & string,
|
|
74
|
+
TNestedValue,
|
|
75
|
+
TAlias extends string | null = null,
|
|
76
|
+
> =
|
|
56
77
|
| [
|
|
57
|
-
|
|
58
|
-
|
|
78
|
+
args: TypedHasManyArgs<TEntity, TKey, TAlias>,
|
|
79
|
+
fields: TypedHasManyFields<TSchema, TEntity, TKey, TNestedValue>,
|
|
59
80
|
]
|
|
60
81
|
| [
|
|
61
|
-
|
|
82
|
+
fields: TypedHasManyFields<TSchema, TEntity, TKey, TNestedValue>,
|
|
62
83
|
]
|
|
63
84
|
|
|
64
|
-
|
|
65
|
-
|
|
85
|
+
export type TypedHasManyByArgs<
|
|
86
|
+
TEntity extends EntityTypeLike,
|
|
87
|
+
TKey extends keyof TEntity['hasManyBy'] & string,
|
|
88
|
+
TAlias extends string | null = null,
|
|
89
|
+
> =
|
|
66
90
|
& ContentClientInput.HasManyByRelationInput<TEntity['hasManyBy'][TKey]['entity'], TEntity['hasManyBy'][TKey]['by']>
|
|
67
91
|
& { as?: TAlias }
|
|
68
92
|
|
|
69
|
-
export type TypedHasManyByFields<
|
|
93
|
+
export type TypedHasManyByFields<
|
|
94
|
+
TSchema extends SchemaTypeLike,
|
|
95
|
+
TEntity extends EntityTypeLike,
|
|
96
|
+
TKey extends keyof TEntity['hasManyBy'] & string,
|
|
97
|
+
TNestedValue,
|
|
98
|
+
> =
|
|
70
99
|
| TypedEntitySelectionCallback<TSchema, TEntity['hasManyBy'][TKey]['entity']['name'], TEntity['hasManyBy'][TKey]['entity'], TNestedValue>
|
|
71
100
|
| TypedEntitySelection<TSchema, TEntity['hasManyBy'][TKey]['entity']['name'], TEntity['hasManyBy'][TKey]['entity'], TNestedValue>
|
|
72
101
|
|
|
73
|
-
export type TypedHasManyByParams<
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
102
|
+
export type TypedHasManyByParams<
|
|
103
|
+
TSchema extends SchemaTypeLike,
|
|
104
|
+
TEntity extends EntityTypeLike,
|
|
105
|
+
TKey extends keyof TEntity['hasManyBy'] & string,
|
|
106
|
+
TNestedValue,
|
|
107
|
+
TAlias extends string | null = null,
|
|
108
|
+
> = [
|
|
109
|
+
args: TypedHasManyByArgs<TEntity, TKey, TAlias>,
|
|
110
|
+
fields: TypedHasManyByFields<TSchema, TEntity, TKey, TNestedValue>,
|
|
111
|
+
]
|
|
79
112
|
|
|
80
113
|
export type TypedHasOneArgs<TEntity extends EntityTypeLike, TKey extends keyof TEntity['hasOne'] & string, TAlias extends string | null = null> =
|
|
81
114
|
& ContentClientInput.HasOneRelationInput<TEntity['hasOne'][TKey]>
|
|
82
115
|
& { as?: TAlias }
|
|
83
116
|
|
|
84
|
-
export type TypedHasOneFields<
|
|
117
|
+
export type TypedHasOneFields<
|
|
118
|
+
TSchema extends SchemaTypeLike,
|
|
119
|
+
TEntity extends EntityTypeLike,
|
|
120
|
+
TKey extends keyof TEntity['hasOne'] & string,
|
|
121
|
+
TNestedValue,
|
|
122
|
+
> =
|
|
85
123
|
| TypedEntitySelectionCallback<TSchema, TEntity['hasOne'][TKey]['name'], TEntity['hasOne'][TKey], TNestedValue>
|
|
86
124
|
| TypedEntitySelection<TSchema, TEntity['hasOne'][TKey]['name'], TEntity['hasOne'][TKey], TNestedValue>
|
|
87
125
|
|
|
88
|
-
export type TypedHasOneParams<
|
|
126
|
+
export type TypedHasOneParams<
|
|
127
|
+
TSchema extends SchemaTypeLike,
|
|
128
|
+
TEntity extends EntityTypeLike,
|
|
129
|
+
TKey extends keyof TEntity['hasOne'] & string,
|
|
130
|
+
TNestedValue,
|
|
131
|
+
TAlias extends string | null = null,
|
|
132
|
+
> =
|
|
89
133
|
| [
|
|
90
|
-
|
|
91
|
-
|
|
134
|
+
args: TypedHasOneArgs<TEntity, TKey, TAlias>,
|
|
135
|
+
fields: TypedHasOneFields<TSchema, TEntity, TKey, TNestedValue>,
|
|
92
136
|
]
|
|
93
137
|
| [
|
|
94
|
-
|
|
138
|
+
fields: TypedHasOneFields<TSchema, TEntity, TKey, TNestedValue>,
|
|
95
139
|
]
|
|
96
140
|
|
|
97
|
-
|
|
98
141
|
export type TypedColumnArgs<TAlias extends string | null = null> = { as?: TAlias }
|
|
99
142
|
export type TypedColumnParams<TAlias extends string | null = null> =
|
|
100
143
|
| [
|
|
101
|
-
|
|
144
|
+
args: TypedColumnArgs<TAlias>,
|
|
102
145
|
]
|
|
103
146
|
| []
|
|
104
147
|
|
|
105
|
-
export type TypedEntitySelectionParams<
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
TKey extends keyof TEntity['
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
148
|
+
export type TypedEntitySelectionParams<
|
|
149
|
+
TSchema extends SchemaTypeLike,
|
|
150
|
+
TEntity extends EntityTypeLike,
|
|
151
|
+
TKey extends string,
|
|
152
|
+
TNestedValue,
|
|
153
|
+
TAlias extends string | null = null,
|
|
154
|
+
> = TKey extends keyof TEntity['columns'] ? TypedColumnParams<TAlias>
|
|
155
|
+
: TKey extends keyof TEntity['hasMany'] ? TypedHasManyParams<TSchema, TEntity, TKey, TNestedValue, TAlias>
|
|
156
|
+
: TKey extends keyof TEntity['hasManyBy'] ? TypedHasManyByParams<TSchema, TEntity, TKey, TNestedValue, TAlias>
|
|
157
|
+
: TKey extends keyof TEntity['hasOne'] ? TypedHasOneParams<TSchema, TEntity, TKey, TNestedValue, TAlias>
|
|
158
|
+
: never
|
|
159
|
+
|
|
160
|
+
export type TypedEntitySelectionResult<TEntity extends EntityTypeLike, TKey extends string, TValue> = TKey extends keyof TEntity['columns']
|
|
161
|
+
? TEntity['columns'][TKey]
|
|
162
|
+
: TKey extends keyof TEntity['hasMany'] ? TValue[]
|
|
163
|
+
: TKey extends keyof TEntity['hasManyBy'] ? null | TValue
|
|
164
|
+
: TKey extends keyof TEntity['hasOne'] ? null | TValue
|
|
165
|
+
: never
|