@contember/client-content 1.3.0-alpha.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (57) hide show
  1. package/dist/types/ContentClient.d.ts +18 -0
  2. package/dist/types/ContentClient.d.ts.map +1 -0
  3. package/dist/types/ContentQueryBuilder.d.ts +25 -0
  4. package/dist/types/ContentQueryBuilder.d.ts.map +1 -0
  5. package/dist/types/TypedContentQueryBuilder.d.ts +21 -0
  6. package/dist/types/TypedContentQueryBuilder.d.ts.map +1 -0
  7. package/dist/types/index.d.ts +6 -0
  8. package/dist/types/index.d.ts.map +1 -0
  9. package/dist/types/nodes/ContentEntitySelection.d.ts +51 -0
  10. package/dist/types/nodes/ContentEntitySelection.d.ts.map +1 -0
  11. package/dist/types/nodes/ContentOperation.d.ts +30 -0
  12. package/dist/types/nodes/ContentOperation.d.ts.map +1 -0
  13. package/dist/types/nodes/TypedEntitySelection.d.ts +42 -0
  14. package/dist/types/nodes/TypedEntitySelection.d.ts.map +1 -0
  15. package/dist/types/nodes/index.d.ts +4 -0
  16. package/dist/types/nodes/index.d.ts.map +1 -0
  17. package/dist/types/tsconfig.tsbuildinfo +1 -0
  18. package/dist/types/types/Input.d.ts +141 -0
  19. package/dist/types/types/Input.d.ts.map +1 -0
  20. package/dist/types/types/Result.d.ts +39 -0
  21. package/dist/types/types/Result.d.ts.map +1 -0
  22. package/dist/types/types/Schema.d.ts +43 -0
  23. package/dist/types/types/Schema.d.ts.map +1 -0
  24. package/dist/types/types/index.d.ts +4 -0
  25. package/dist/types/types/index.d.ts.map +1 -0
  26. package/dist/types/utils/ContentOperationSet.d.ts +13 -0
  27. package/dist/types/utils/ContentOperationSet.d.ts.map +1 -0
  28. package/dist/types/utils/createListArgs.d.ts +9 -0
  29. package/dist/types/utils/createListArgs.d.ts.map +1 -0
  30. package/dist/types/utils/createMutationOperationSet.d.ts +4 -0
  31. package/dist/types/utils/createMutationOperationSet.d.ts.map +1 -0
  32. package/dist/types/utils/createQueryOperationSet.d.ts +4 -0
  33. package/dist/types/utils/createQueryOperationSet.d.ts.map +1 -0
  34. package/dist/types/utils/createTypedArgs.d.ts +3 -0
  35. package/dist/types/utils/createTypedArgs.d.ts.map +1 -0
  36. package/dist/types/utils/mutationFragments.d.ts +3 -0
  37. package/dist/types/utils/mutationFragments.d.ts.map +1 -0
  38. package/package.json +48 -0
  39. package/src/ContentClient.ts +42 -0
  40. package/src/ContentQueryBuilder.ts +200 -0
  41. package/src/TypedContentQueryBuilder.ts +76 -0
  42. package/src/index.ts +5 -0
  43. package/src/nodes/ContentEntitySelection.ts +240 -0
  44. package/src/nodes/ContentOperation.ts +23 -0
  45. package/src/nodes/TypedEntitySelection.ts +107 -0
  46. package/src/nodes/index.ts +3 -0
  47. package/src/tsconfig.json +14 -0
  48. package/src/types/Input.ts +213 -0
  49. package/src/types/Result.ts +43 -0
  50. package/src/types/Schema.ts +49 -0
  51. package/src/types/index.ts +3 -0
  52. package/src/utils/ContentOperationSet.ts +11 -0
  53. package/src/utils/createListArgs.ts +23 -0
  54. package/src/utils/createMutationOperationSet.ts +42 -0
  55. package/src/utils/createQueryOperationSet.ts +20 -0
  56. package/src/utils/createTypedArgs.ts +15 -0
  57. package/src/utils/mutationFragments.ts +52 -0
@@ -0,0 +1,23 @@
1
+ import { GraphQlFieldTypedArgs, GraphQlSelectionSet } from '@contember/graphql-builder'
2
+
3
+ export class ContentOperation<TValue, TType extends 'query' | 'mutation'> {
4
+ /**
5
+ * @internal
6
+ */
7
+ constructor(
8
+ /** @internal */
9
+ public readonly type: TType,
10
+ /** @internal */
11
+ public readonly fieldName: string,
12
+ /** @internal */
13
+ public readonly args: GraphQlFieldTypedArgs = {},
14
+ /** @internal */
15
+ public readonly selection?: GraphQlSelectionSet,
16
+ /** @internal */
17
+ public readonly parse: (value: any) => TValue = it => it as TValue,
18
+ ) {
19
+ }
20
+ }
21
+
22
+ export type ContentQuery<TValue> = ContentOperation<TValue, 'query'>
23
+ export type ContentMutation<TValue> = ContentOperation<TValue, 'mutation'>
@@ -0,0 +1,107 @@
1
+ import { EntityTypeLike, SchemaTypeLike } from '../types/Schema'
2
+ import { ContentClientInput } from '../types'
3
+
4
+ export type TypedEntitySelectionCallback<
5
+ TSchema extends SchemaTypeLike,
6
+ EntityName extends string,
7
+ TEntity extends EntityTypeLike,
8
+ TValue
9
+ > = (select: TypedEntitySelection<TSchema, EntityName, TEntity, {}>) => TypedEntitySelection<TSchema, EntityName, TEntity, TValue>
10
+
11
+ export interface TypedEntitySelection<TSchema extends SchemaTypeLike, TEntityName extends string, TEntity extends EntityTypeLike, TValue> {
12
+
13
+ $$(): TypedEntitySelection<TSchema, TEntityName, TEntity, TValue & {
14
+ [key in keyof TEntity['columns']]: TEntity['columns'][key]
15
+ }>
16
+
17
+ $<
18
+ TKey extends (keyof TEntity['columns']) & string,
19
+ TAlias extends string | null = null
20
+ >(
21
+ name: TKey,
22
+ args?: {as?: TAlias},
23
+ ): TypedEntitySelection<TSchema, TEntityName, TEntity, TValue & {
24
+ [key in TAlias extends null ? TKey : TAlias]: TEntity['columns'][key]
25
+ }>
26
+
27
+ $<
28
+ TNestedValue,
29
+ TNestedKey extends keyof TEntity['hasMany'] & string,
30
+ TAlias extends string | null = null,
31
+ >(
32
+ name: TNestedKey,
33
+ args: ContentClientInput.HasManyRelationInput<TEntity['hasMany'][TNestedKey]> & { as?: TAlias },
34
+ fields:
35
+ | TypedEntitySelectionCallback<TSchema, TEntity['hasMany'][TNestedKey]['name'], TEntity['hasMany'][TNestedKey], TNestedValue>
36
+ | TypedEntitySelection<TSchema, TEntity['hasMany'][TNestedKey]['name'], TEntity['hasMany'][TNestedKey], TNestedValue>,
37
+ ): TypedEntitySelection<TSchema, TEntityName, TEntity, TValue & {
38
+ [key in TAlias extends null ? TNestedKey : TAlias]: TNestedValue[]
39
+ }>
40
+
41
+ $<
42
+ TNestedValue,
43
+ TNestedKey extends keyof TEntity['hasMany'] & string,
44
+ TAlias extends string | null = null,
45
+ >(
46
+ name: TNestedKey,
47
+ fields:
48
+ | TypedEntitySelectionCallback<TSchema, TEntity['hasMany'][TNestedKey]['name'], TEntity['hasMany'][TNestedKey], TNestedValue>
49
+ | TypedEntitySelection<TSchema, TEntity['hasMany'][TNestedKey]['name'], TEntity['hasMany'][TNestedKey], TNestedValue>,
50
+ ): TypedEntitySelection<TSchema, TEntityName, TEntity, TValue & {
51
+ [key in TAlias extends null ? TNestedKey : TAlias]: TNestedValue[]
52
+ }>
53
+
54
+ $<
55
+ TNestedValue,
56
+ TNestedKey extends keyof TEntity['hasManyBy'] & string,
57
+ TAlias extends string | null = null,
58
+ >(
59
+ name: TNestedKey,
60
+ args: ContentClientInput.HasManyByRelationInput<TEntity['hasManyBy'][TNestedKey]['entity'], TEntity['hasManyBy'][TNestedKey]['by']> & { as?: TAlias },
61
+ fields:
62
+ | TypedEntitySelectionCallback<TSchema, TEntity['hasManyBy'][TNestedKey]['entity']['name'], TEntity['hasManyBy'][TNestedKey]['entity'], TNestedValue>
63
+ | TypedEntitySelection<TSchema, TEntity['hasManyBy'][TNestedKey]['entity']['name'], TEntity['hasManyBy'][TNestedKey]['entity'], TNestedValue>,
64
+ ): TypedEntitySelection<TSchema, TEntityName, TEntity, TValue & {
65
+ [key in TAlias extends null ? TNestedKey : TAlias]: null | TNestedValue
66
+ }>
67
+
68
+ $<
69
+ TNestedValue,
70
+ TNestedKey extends keyof TEntity['hasManyBy'] & string,
71
+ TAlias extends string | null = null,
72
+ >(
73
+ name: TNestedKey,
74
+ fields:
75
+ | TypedEntitySelectionCallback<TSchema, TEntity['hasManyBy'][TNestedKey]['entity']['name'], TEntity['hasManyBy'][TNestedKey]['entity'], TNestedValue>
76
+ | TypedEntitySelection<TSchema, TEntity['hasManyBy'][TNestedKey]['entity']['name'], TEntity['hasManyBy'][TNestedKey]['entity'], TNestedValue>,
77
+ ): TypedEntitySelection<TSchema, TEntityName, TEntity, TValue & {
78
+ [key in TAlias extends null ? TNestedKey : TAlias]: null | TNestedValue
79
+ }>
80
+
81
+ $<
82
+ TNestedValue extends { [K in string]: unknown },
83
+ TNestedKey extends keyof TEntity['hasOne'] & string,
84
+ TAlias extends string | null = null,
85
+ >(
86
+ name: TNestedKey,
87
+ args: ContentClientInput.HasOneRelationInput<TEntity['hasOne'][TNestedKey]> & { as?: TAlias },
88
+ fields:
89
+ | TypedEntitySelectionCallback<TSchema, TEntity['hasOne'][TNestedKey]['name'], TEntity['hasOne'][TNestedKey], TNestedValue>
90
+ | TypedEntitySelection<TSchema, TEntity['hasOne'][TNestedKey]['name'], TEntity['hasOne'][TNestedKey], TNestedValue>,
91
+ ): TypedEntitySelection<TSchema, TEntityName, TEntity, TValue & {
92
+ [key in TAlias extends null ? TNestedKey : TAlias]: TNestedValue | null
93
+ }>
94
+
95
+ $<
96
+ TNestedValue extends { [K in string]: unknown },
97
+ TNestedKey extends keyof TEntity['hasOne'] & string,
98
+ TAlias extends string | null = null,
99
+ >(
100
+ name: TNestedKey,
101
+ fields:
102
+ | TypedEntitySelectionCallback<TSchema, TEntity['hasOne'][TNestedKey]['name'], TEntity['hasOne'][TNestedKey], TNestedValue>
103
+ | TypedEntitySelection<TSchema, TEntity['hasOne'][TNestedKey]['name'], TEntity['hasOne'][TNestedKey], TNestedValue>,
104
+ ): TypedEntitySelection<TSchema, TEntityName, TEntity, TValue & {
105
+ [key in TAlias extends null ? TNestedKey : TAlias]: TNestedValue | null
106
+ }>
107
+ }
@@ -0,0 +1,3 @@
1
+ export * from './ContentEntitySelection'
2
+ export * from './ContentOperation'
3
+ export * from './TypedEntitySelection'
@@ -0,0 +1,14 @@
1
+ {
2
+ "extends": "../../../tsconfig.settings.json",
3
+ "compilerOptions": {
4
+ "outDir": "../dist/types"
5
+ },
6
+ "references": [
7
+ {
8
+ "path": "../../graphql-builder/src"
9
+ },
10
+ {
11
+ "path": "../../graphql-client/src"
12
+ }
13
+ ]
14
+ }
@@ -0,0 +1,213 @@
1
+ import { Input, JSONObject } from '@contember/schema'
2
+ import { EntityTypeLike } from './Schema'
3
+
4
+
5
+ export namespace ContentClientInput {
6
+ export type ConnectRelationInput<TEntity extends EntityTypeLike> = {
7
+ readonly connect: UniqueWhere<TEntity>
8
+ }
9
+
10
+ export type CreateRelationInput<TEntity extends EntityTypeLike> = {
11
+ readonly create: CreateDataInput<TEntity>
12
+ }
13
+
14
+ export type ConnectOrCreateInput<TEntity extends EntityTypeLike> = {
15
+ readonly connect: UniqueWhere<TEntity>
16
+ readonly create: CreateDataInput<TEntity>
17
+ }
18
+
19
+ export type ConnectOrCreateRelationInput<TEntity extends EntityTypeLike> = {
20
+ readonly connectOrCreate: ConnectOrCreateInput<TEntity>
21
+ }
22
+
23
+ export type DisconnectSpecifiedRelationInput<TEntity extends EntityTypeLike> = {
24
+ readonly disconnect: UniqueWhere<TEntity>
25
+ }
26
+
27
+ export type DeleteSpecifiedRelationInput<TEntity extends EntityTypeLike> = {
28
+ readonly delete: UniqueWhere<TEntity>
29
+ }
30
+
31
+ export type UpdateSpecifiedRelationInput<TEntity extends EntityTypeLike> = {
32
+ readonly update: {
33
+ readonly by: UniqueWhere<TEntity>
34
+ readonly data: UpdateDataInput<TEntity>
35
+ }
36
+ }
37
+
38
+ export type UpsertSpecifiedRelationInput<TEntity extends EntityTypeLike> = {
39
+ readonly upsert: {
40
+ readonly by: UniqueWhere<TEntity>
41
+ readonly update: UpdateDataInput<TEntity>
42
+ readonly create: CreateDataInput<TEntity>
43
+ }
44
+ }
45
+
46
+ export type DisconnectRelationInput = {
47
+ readonly disconnect: true
48
+ }
49
+
50
+ export type UpdateRelationInput<TEntity extends EntityTypeLike> = {
51
+ readonly update: UpdateDataInput<TEntity>
52
+ }
53
+
54
+ export type DeleteRelationInput = {
55
+ readonly delete: true
56
+ }
57
+
58
+ export type UpsertRelationInput<TEntity extends EntityTypeLike> = {
59
+ readonly upsert: {
60
+ readonly update: UpdateDataInput<TEntity>
61
+ readonly create: CreateDataInput<TEntity>
62
+ }
63
+ }
64
+
65
+ export type CreateDataInput<TEntity extends EntityTypeLike> =
66
+ & {
67
+ readonly [key in keyof TEntity['columns']]?: TEntity['columns'][key]['tsType']
68
+ }
69
+ & {
70
+ readonly [key in keyof TEntity['hasMany']]?: CreateManyRelationInput<TEntity['hasMany'][key]>
71
+ }
72
+ & {
73
+ readonly [key in keyof TEntity['hasOne']]?: CreateOneRelationInput<TEntity['hasOne'][key]>
74
+ }
75
+
76
+ export type CreateOneRelationInput<TEntity extends EntityTypeLike> =
77
+ | ConnectRelationInput<TEntity>
78
+ | CreateRelationInput<TEntity>
79
+ | ConnectOrCreateRelationInput<TEntity>
80
+
81
+ export type CreateManyRelationInput<TEntity extends EntityTypeLike> = readonly CreateOneRelationInput<TEntity>[]
82
+
83
+ export type UpdateDataInput<TEntity extends EntityTypeLike> =
84
+ & {
85
+ readonly [key in keyof TEntity['columns']]?: TEntity['columns'][key]['tsType']
86
+ }
87
+ & {
88
+ readonly [key in keyof TEntity['hasMany']]?: UpdateManyRelationInput<TEntity['hasMany'][key]>
89
+ }
90
+ & {
91
+ readonly [key in keyof TEntity['hasOne']]?: UpdateOneRelationInput<TEntity['hasOne'][key]>
92
+ }
93
+
94
+ export type UpdateInput<TEntity extends EntityTypeLike> = {
95
+ readonly by: UniqueWhere<TEntity>
96
+ readonly filter?: Where<TEntity>
97
+ readonly data: UpdateDataInput<TEntity>
98
+ }
99
+
100
+ export type UpsertInput<TEntity extends EntityTypeLike> = {
101
+ readonly by: UniqueWhere<TEntity>
102
+ readonly filter?: Where<TEntity>
103
+ readonly update: UpdateDataInput<TEntity>
104
+ readonly create: CreateDataInput<TEntity>
105
+ }
106
+
107
+ export type CreateInput<TEntity extends EntityTypeLike> = {
108
+ readonly data: CreateDataInput<TEntity>
109
+ }
110
+
111
+ export type DeleteInput<TEntity extends EntityTypeLike> = {
112
+ readonly by: UniqueWhere<TEntity>
113
+ readonly filter?: Where<TEntity>
114
+ }
115
+
116
+ export type UniqueQueryInput<TEntity extends EntityTypeLike> = {
117
+ readonly by: UniqueWhere<TEntity>
118
+ readonly filter?: Where<TEntity>
119
+ }
120
+
121
+ export type ListQueryInput<TEntity extends EntityTypeLike> = {
122
+ readonly filter?: Where<TEntity>
123
+ readonly orderBy?: readonly OrderBy<TEntity>[]
124
+ readonly offset?: number
125
+ readonly limit?: number
126
+ }
127
+
128
+ export type PaginationQueryInput<TEntity extends EntityTypeLike> = {
129
+ readonly filter?: Where<TEntity>
130
+ readonly orderBy?: readonly OrderBy<TEntity>[]
131
+ readonly skip?: number
132
+ readonly first?: number
133
+ }
134
+
135
+ export type HasOneRelationInput<TEntity extends EntityTypeLike> = {
136
+ readonly filter?: Where<TEntity>
137
+ }
138
+
139
+ export type HasManyByRelationInput<TEntity extends EntityTypeLike, TUnique extends JSONObject> = {
140
+ readonly by: TUnique
141
+ readonly filter?: Where<TEntity>
142
+ }
143
+
144
+ export type HasManyRelationInput<TEntity extends EntityTypeLike> = ListQueryInput<TEntity>
145
+ export type HasManyRelationPaginateInput<TEntity extends EntityTypeLike> = PaginationQueryInput<TEntity>
146
+
147
+
148
+ export type UpdateOneRelationInput<TEntity extends EntityTypeLike> =
149
+ | CreateRelationInput<TEntity>
150
+ | ConnectRelationInput<TEntity>
151
+ | ConnectOrCreateRelationInput<TEntity>
152
+ | DeleteRelationInput
153
+ | DisconnectRelationInput
154
+ | UpdateRelationInput<TEntity>
155
+ | UpsertRelationInput<TEntity>
156
+
157
+ export type UpdateManyRelationInputItem<TEntity extends EntityTypeLike> =
158
+ | CreateRelationInput<TEntity>
159
+ | ConnectRelationInput<TEntity>
160
+ | ConnectOrCreateRelationInput<TEntity>
161
+ | DeleteSpecifiedRelationInput<TEntity>
162
+ | DisconnectSpecifiedRelationInput<TEntity>
163
+ | UpdateSpecifiedRelationInput<TEntity>
164
+ | UpsertSpecifiedRelationInput<TEntity>
165
+
166
+
167
+ export type UpdateManyRelationInput<TEntity extends EntityTypeLike> = Array<UpdateManyRelationInputItem<TEntity>>
168
+
169
+
170
+ export type FieldOrderBy<TEntity extends EntityTypeLike> =
171
+ & {
172
+ readonly [key in keyof TEntity['columns']]?: `${Input.OrderDirection}` | null
173
+ }
174
+ & {
175
+ readonly [key in keyof TEntity['hasMany']]?: FieldOrderBy<TEntity['hasMany'][key]> | null
176
+ }
177
+ & {
178
+ readonly [key in keyof TEntity['hasOne']]?: FieldOrderBy<TEntity['hasOne'][key]> | null
179
+ }
180
+
181
+ export type OrderBy<TEntity extends EntityTypeLike> =
182
+ & {
183
+ readonly _random?: boolean
184
+ readonly _randomSeeded?: number
185
+ }
186
+ & FieldOrderBy<TEntity>
187
+
188
+
189
+ export type UniqueWhere<TEntity extends EntityTypeLike> = TEntity['unique']
190
+
191
+
192
+ export type Where<TEntity extends EntityTypeLike> =
193
+ & {
194
+ readonly and?: (readonly (Where<TEntity>)[]) | null
195
+ readonly or?: (readonly (Where<TEntity>)[]) | null
196
+ readonly not?: Where<TEntity> | null
197
+ }
198
+ & {
199
+ readonly [key in keyof TEntity['columns']]?: Input.Condition<TEntity['columns'][key]> | null
200
+ }
201
+ & {
202
+ readonly [key in keyof TEntity['hasMany']]?: Where<TEntity['hasMany'][key]> | null
203
+ }
204
+ & {
205
+ readonly [key in keyof TEntity['hasOne']]?: Where<TEntity['hasOne'][key]> | null
206
+ }
207
+
208
+
209
+ export type AnyOrderBy = Input.OrderBy<`${Input.OrderDirection}`>[]
210
+ export type AnyListQueryInput =
211
+ & Omit<Input.ListQueryInput, 'orderBy'>
212
+ & { readonly orderBy?: AnyOrderBy }
213
+ }
@@ -0,0 +1,43 @@
1
+ import { Result } from '@contember/schema'
2
+
3
+ export type TransactionResult<V> = {
4
+ readonly ok: boolean
5
+ readonly errorMessage: string | null
6
+ readonly errors: MutationError[]
7
+ readonly validation: ValidationResult
8
+ readonly data: V
9
+ }
10
+
11
+ export type MutationResult<Value = unknown> = {
12
+ readonly ok: boolean
13
+ readonly errorMessage: string | null
14
+ readonly errors: MutationError[]
15
+ readonly node: Value | null
16
+ readonly validation?: ValidationResult
17
+ }
18
+
19
+ export type ValidationResult = {
20
+ readonly valid: boolean
21
+ readonly errors: ValidationError[]
22
+ }
23
+
24
+ export type ValidationError = {
25
+ readonly path: Path
26
+ readonly message: { text: string }
27
+ }
28
+
29
+ export type MutationError = {
30
+ readonly paths: Path[]
31
+ readonly message: string
32
+ readonly type: Result.ExecutionErrorType
33
+ }
34
+
35
+ export type Path = Array<FieldPath | IndexPath>
36
+
37
+ export type FieldPath = {
38
+ readonly field: string
39
+ }
40
+ export type IndexPath = {
41
+ readonly index: number
42
+ readonly alias: string | null
43
+ }
@@ -0,0 +1,49 @@
1
+ import { JSONObject } from '@contember/schema'
2
+
3
+ export type SchemaEntityNames<Name extends string> = {
4
+ readonly name: Name
5
+ readonly scalars: string[]
6
+ readonly fields: {
7
+ readonly [fieldName: string]:
8
+ | {
9
+ readonly type: 'column'
10
+ }
11
+ | {
12
+ readonly type: 'many' | 'one'
13
+ readonly entity: string
14
+ }
15
+ }
16
+ }
17
+
18
+ export type SchemaNames = {
19
+ entities: {
20
+ [entityName: string]: SchemaEntityNames<string>
21
+ }
22
+ }
23
+
24
+ export type EntityTypeLike = {
25
+ name: string
26
+ unique: JSONObject
27
+ columns: {
28
+ [columnName: string]: any
29
+ }
30
+ hasOne: {
31
+ [relationName: string]: EntityTypeLike
32
+ }
33
+ hasMany: {
34
+ [relationName: string]: EntityTypeLike
35
+ }
36
+ hasManyBy: {
37
+ [relationName: string]: {
38
+ entity: EntityTypeLike
39
+ by: JSONObject
40
+ }
41
+ }
42
+ }
43
+
44
+ export type SchemaTypeLike = {
45
+ entities: {
46
+ [entityName: string]: EntityTypeLike
47
+ }
48
+ }
49
+
@@ -0,0 +1,3 @@
1
+ export * from './Input'
2
+ export * from './Result'
3
+ export * from './Schema'
@@ -0,0 +1,11 @@
1
+ import { GraphQlSelectionSet } from '@contember/graphql-builder'
2
+
3
+ export class ContentOperationSet<TValue> {
4
+ constructor(
5
+ /** @internal */
6
+ public readonly selection: GraphQlSelectionSet,
7
+ /** @internal */
8
+ public readonly parse: (value: any) => TValue = it => it as TValue,
9
+ ) {
10
+ }
11
+ }
@@ -0,0 +1,23 @@
1
+ import { SchemaEntityNames } from '../types'
2
+ import { GraphQlFieldTypedArgs } from '@contember/graphql-builder'
3
+
4
+ export const createListArgs = (entity: SchemaEntityNames<string>, args: { filter?: any, orderBy?: any, limit?: number, offset?: number }, type: 'list' | 'paginate' = 'list'): GraphQlFieldTypedArgs => {
5
+ return {
6
+ filter: {
7
+ graphQlType: `${entity.name}Where`,
8
+ value: args.filter,
9
+ },
10
+ orderBy: {
11
+ graphQlType: `[${entity.name}OrderBy!]`,
12
+ value: args.orderBy,
13
+ },
14
+ [type === 'list' ? 'limit' : 'first']: {
15
+ graphQlType: 'Int',
16
+ value: args.limit,
17
+ },
18
+ [type === 'list' ? 'offset' : 'skip']: {
19
+ graphQlType: 'Int',
20
+ value: args.offset,
21
+ },
22
+ }
23
+ }
@@ -0,0 +1,42 @@
1
+ import { ContentMutation, ContentOperation, ContentQuery } from '../nodes'
2
+ import { GraphQlField } from '@contember/graphql-builder'
3
+ import { ContentOperationSet } from './ContentOperationSet'
4
+
5
+ export const createMutationOperationSet = (
6
+ input:
7
+ | Record<string, ContentMutation<any> | ContentQuery<any>>
8
+ | ContentMutation<any>
9
+ | ContentMutation<any>[],
10
+ ): ContentOperationSet<any> => {
11
+
12
+ if (input instanceof ContentOperation) {
13
+ return new ContentOperationSet(
14
+ [new GraphQlField('mut', input.fieldName, input.args, input.selection)],
15
+ it => input.parse(it.mut),
16
+ )
17
+ }
18
+
19
+ if (Array.isArray(input)) {
20
+ return new ContentOperationSet(
21
+ input.map((mut, i) => new GraphQlField('mut_' + i++, mut.fieldName, mut.args, mut.selection)),
22
+ data => input.map((mut, i) => mut.parse(data['mut_' + i] ?? null)),
23
+ )
24
+ }
25
+
26
+ return new ContentOperationSet(
27
+ Object.entries(input).map(([alias, mutation]) => {
28
+ if (mutation.type === 'query') {
29
+ return new GraphQlField(alias, 'query', {}, [
30
+ new GraphQlField('value', mutation.fieldName, mutation.args, mutation.selection),
31
+ ])
32
+ }
33
+ return new GraphQlField(alias, mutation.fieldName, mutation.args, mutation.selection)
34
+ }),
35
+ res => Object.fromEntries(Object.entries(input).map(([alias, mutation]) => {
36
+ if (mutation.type === 'query') {
37
+ return [alias, mutation.parse(res[alias]?.value ?? null)]
38
+ }
39
+ return [alias, mutation.parse(res[alias] ?? null)]
40
+ })),
41
+ )
42
+ }
@@ -0,0 +1,20 @@
1
+ import { ContentOperation, ContentQuery } from '../nodes'
2
+ import { ContentOperationSet } from './ContentOperationSet'
3
+ import { GraphQlField } from '@contember/graphql-builder'
4
+
5
+ export const createQueryOperationSet = (
6
+ input: Record<string, ContentQuery<any>> | ContentQuery<any>,
7
+ ): ContentOperationSet<any> => {
8
+
9
+ if (input instanceof ContentOperation) {
10
+ return new ContentOperationSet(
11
+ [new GraphQlField('value', input.fieldName, input.args, input.selection)],
12
+ it => input.parse(it.value),
13
+ )
14
+ }
15
+
16
+ return new ContentOperationSet(
17
+ Object.entries(input).map(([alias, query]) => new GraphQlField(alias, query.fieldName, query.args, query.selection)),
18
+ res => Object.fromEntries(Object.entries(input).map(([alias, query]) => [alias, query.parse(res[alias] ?? null)])),
19
+ )
20
+ }
@@ -0,0 +1,15 @@
1
+ import { GraphQlFieldTypedArgs } from '@contember/graphql-builder'
2
+
3
+ export const createTypedArgs = <TArgs extends Record<string, any>>(
4
+ args: TArgs,
5
+ types: { [key in keyof TArgs]: string },
6
+ ): GraphQlFieldTypedArgs => {
7
+ const typedArgs: GraphQlFieldTypedArgs = {}
8
+ for (const key in args) {
9
+ typedArgs[key] = {
10
+ graphQlType: types[key],
11
+ value: args[key],
12
+ }
13
+ }
14
+ return typedArgs
15
+ }
@@ -0,0 +1,52 @@
1
+ import { GraphQlField, GraphQlFragment, GraphQlFragmentSpread, GraphQlInlineFragment } from '@contember/graphql-builder'
2
+
3
+ export const mutationFragments: Record<string, GraphQlFragment> = {
4
+ MutationError: new GraphQlFragment('MutationError', '_MutationError', [
5
+ new GraphQlField(null, 'paths', {}, [
6
+ new GraphQlInlineFragment('_FieldPathFragment', [
7
+ new GraphQlField(null, 'field'),
8
+ ]),
9
+ new GraphQlInlineFragment('_IndexPathFragment', [
10
+ new GraphQlField(null, 'index'),
11
+ new GraphQlField(null, 'alias'),
12
+ ]),
13
+ ]),
14
+ new GraphQlField(null, 'message'),
15
+ new GraphQlField(null, 'type'),
16
+ ]),
17
+ TransactionResult: new GraphQlFragment('TransactionResult', 'TransactionResult', [
18
+ new GraphQlField(null, 'ok'),
19
+ new GraphQlField(null, 'errorMessage'),
20
+ new GraphQlField(null, 'errors', {}, [
21
+ new GraphQlField(null, 'paths', {}, [
22
+ new GraphQlInlineFragment('_FieldPathFragment', [
23
+ new GraphQlField(null, 'field'),
24
+ ]),
25
+ new GraphQlInlineFragment('_IndexPathFragment', [
26
+ new GraphQlField(null, 'index'),
27
+ new GraphQlField(null, 'alias'),
28
+ ]),
29
+ ]),
30
+ ]),
31
+ new GraphQlField(null, 'validation', {}, [
32
+ new GraphQlFragmentSpread('ValidationResult'),
33
+ ]),
34
+ ]),
35
+ ValidationResult: new GraphQlFragment('ValidationResult', '_ValidationResult', [
36
+ new GraphQlField(null, 'valid'),
37
+ new GraphQlField(null, 'errors', {}, [
38
+ new GraphQlField(null, 'path', {}, [
39
+ new GraphQlInlineFragment('_FieldPathFragment', [
40
+ new GraphQlField(null, 'field'),
41
+ ]),
42
+ new GraphQlInlineFragment('_IndexPathFragment', [
43
+ new GraphQlField(null, 'index'),
44
+ new GraphQlField(null, 'alias'),
45
+ ]),
46
+ ]),
47
+ new GraphQlField(null, 'message', {}, [
48
+ new GraphQlField(null, 'text'),
49
+ ]),
50
+ ]),
51
+ ]),
52
+ }