wabe 0.6.11 → 0.6.13

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 (162) hide show
  1. package/dist/authentication/Session.d.ts +10 -12
  2. package/dist/authentication/cookies.d.ts +1 -0
  3. package/dist/authentication/index.d.ts +1 -0
  4. package/dist/authentication/interface.d.ts +20 -0
  5. package/dist/authentication/security.d.ts +18 -0
  6. package/dist/database/DatabaseController.d.ts +57 -3
  7. package/dist/database/interface.d.ts +5 -0
  8. package/dist/file/interface.d.ts +23 -0
  9. package/dist/file/security.d.ts +6 -0
  10. package/dist/graphql/GraphQLSchema.d.ts +1 -1
  11. package/dist/graphql/resolvers.d.ts +1 -0
  12. package/dist/hooks/protected.d.ts +3 -0
  13. package/dist/hooks/virtualFields.d.ts +3 -0
  14. package/dist/index.js +1757 -818
  15. package/dist/schema/Schema.d.ts +66 -7
  16. package/dist/server/index.d.ts +2 -1
  17. package/dist/server/routes/index.d.ts +4 -1
  18. package/dist/utils/database.d.ts +1 -0
  19. package/dist/utils/export.d.ts +1 -0
  20. package/dist/utils/index.d.ts +1 -0
  21. package/package.json +7 -4
  22. package/bucket/b.txt +0 -1
  23. package/dev/index.ts +0 -215
  24. package/generated/schema.graphql +0 -1892
  25. package/generated/wabe.ts +0 -439
  26. package/src/authentication/OTP.test.ts +0 -69
  27. package/src/authentication/OTP.ts +0 -64
  28. package/src/authentication/Session.test.ts +0 -629
  29. package/src/authentication/Session.ts +0 -493
  30. package/src/authentication/defaultAuthentication.ts +0 -209
  31. package/src/authentication/index.ts +0 -3
  32. package/src/authentication/interface.ts +0 -155
  33. package/src/authentication/oauth/GitHub.test.ts +0 -91
  34. package/src/authentication/oauth/GitHub.ts +0 -121
  35. package/src/authentication/oauth/Google.test.ts +0 -91
  36. package/src/authentication/oauth/Google.ts +0 -101
  37. package/src/authentication/oauth/Oauth2Client.test.ts +0 -219
  38. package/src/authentication/oauth/Oauth2Client.ts +0 -135
  39. package/src/authentication/oauth/index.ts +0 -2
  40. package/src/authentication/oauth/utils.test.ts +0 -33
  41. package/src/authentication/oauth/utils.ts +0 -27
  42. package/src/authentication/providers/EmailOTP.test.ts +0 -127
  43. package/src/authentication/providers/EmailOTP.ts +0 -84
  44. package/src/authentication/providers/EmailPassword.test.ts +0 -176
  45. package/src/authentication/providers/EmailPassword.ts +0 -116
  46. package/src/authentication/providers/EmailPasswordSRP.test.ts +0 -208
  47. package/src/authentication/providers/EmailPasswordSRP.ts +0 -179
  48. package/src/authentication/providers/GitHub.ts +0 -24
  49. package/src/authentication/providers/Google.ts +0 -24
  50. package/src/authentication/providers/OAuth.test.ts +0 -185
  51. package/src/authentication/providers/OAuth.ts +0 -106
  52. package/src/authentication/providers/PhonePassword.test.ts +0 -176
  53. package/src/authentication/providers/PhonePassword.ts +0 -115
  54. package/src/authentication/providers/QRCodeOTP.test.ts +0 -77
  55. package/src/authentication/providers/QRCodeOTP.ts +0 -58
  56. package/src/authentication/providers/index.ts +0 -6
  57. package/src/authentication/resolvers/refreshResolver.test.ts +0 -30
  58. package/src/authentication/resolvers/refreshResolver.ts +0 -19
  59. package/src/authentication/resolvers/signInWithResolver.inte.test.ts +0 -59
  60. package/src/authentication/resolvers/signInWithResolver.test.ts +0 -293
  61. package/src/authentication/resolvers/signInWithResolver.ts +0 -92
  62. package/src/authentication/resolvers/signOutResolver.test.ts +0 -38
  63. package/src/authentication/resolvers/signOutResolver.ts +0 -18
  64. package/src/authentication/resolvers/signUpWithResolver.test.ts +0 -180
  65. package/src/authentication/resolvers/signUpWithResolver.ts +0 -65
  66. package/src/authentication/resolvers/verifyChallenge.test.ts +0 -133
  67. package/src/authentication/resolvers/verifyChallenge.ts +0 -62
  68. package/src/authentication/roles.test.ts +0 -49
  69. package/src/authentication/roles.ts +0 -40
  70. package/src/authentication/utils.test.ts +0 -97
  71. package/src/authentication/utils.ts +0 -39
  72. package/src/cache/InMemoryCache.test.ts +0 -62
  73. package/src/cache/InMemoryCache.ts +0 -45
  74. package/src/cron/index.test.ts +0 -17
  75. package/src/cron/index.ts +0 -43
  76. package/src/database/DatabaseController.test.ts +0 -613
  77. package/src/database/DatabaseController.ts +0 -1007
  78. package/src/database/index.test.ts +0 -1372
  79. package/src/database/index.ts +0 -9
  80. package/src/database/interface.ts +0 -302
  81. package/src/email/DevAdapter.ts +0 -7
  82. package/src/email/EmailController.test.ts +0 -29
  83. package/src/email/EmailController.ts +0 -13
  84. package/src/email/index.ts +0 -2
  85. package/src/email/interface.ts +0 -36
  86. package/src/email/templates/sendOtpCode.ts +0 -120
  87. package/src/file/FileController.ts +0 -28
  88. package/src/file/FileDevAdapter.ts +0 -51
  89. package/src/file/hookDeleteFile.ts +0 -25
  90. package/src/file/hookReadFile.ts +0 -66
  91. package/src/file/hookUploadFile.ts +0 -50
  92. package/src/file/index.test.ts +0 -932
  93. package/src/file/index.ts +0 -2
  94. package/src/file/interface.ts +0 -39
  95. package/src/graphql/GraphQLSchema.test.ts +0 -4408
  96. package/src/graphql/GraphQLSchema.ts +0 -880
  97. package/src/graphql/index.ts +0 -2
  98. package/src/graphql/parseGraphqlSchema.ts +0 -85
  99. package/src/graphql/parser.test.ts +0 -203
  100. package/src/graphql/parser.ts +0 -542
  101. package/src/graphql/pointerAndRelationFunction.ts +0 -191
  102. package/src/graphql/resolvers.ts +0 -442
  103. package/src/graphql/tests/aggregation.test.ts +0 -1115
  104. package/src/graphql/tests/e2e.test.ts +0 -590
  105. package/src/graphql/tests/scalars.test.ts +0 -250
  106. package/src/graphql/types.ts +0 -227
  107. package/src/hooks/HookObject.test.ts +0 -122
  108. package/src/hooks/HookObject.ts +0 -165
  109. package/src/hooks/authentication.ts +0 -67
  110. package/src/hooks/createUser.test.ts +0 -77
  111. package/src/hooks/createUser.ts +0 -10
  112. package/src/hooks/defaultFields.test.ts +0 -176
  113. package/src/hooks/defaultFields.ts +0 -32
  114. package/src/hooks/deleteSession.test.ts +0 -181
  115. package/src/hooks/deleteSession.ts +0 -20
  116. package/src/hooks/hashFieldHook.test.ts +0 -152
  117. package/src/hooks/hashFieldHook.ts +0 -89
  118. package/src/hooks/index.test.ts +0 -258
  119. package/src/hooks/index.ts +0 -414
  120. package/src/hooks/permissions.test.ts +0 -412
  121. package/src/hooks/permissions.ts +0 -93
  122. package/src/hooks/protected.test.ts +0 -551
  123. package/src/hooks/protected.ts +0 -60
  124. package/src/hooks/searchableFields.test.ts +0 -147
  125. package/src/hooks/searchableFields.ts +0 -86
  126. package/src/hooks/session.test.ts +0 -134
  127. package/src/hooks/session.ts +0 -76
  128. package/src/hooks/setEmail.test.ts +0 -216
  129. package/src/hooks/setEmail.ts +0 -33
  130. package/src/hooks/setupAcl.test.ts +0 -618
  131. package/src/hooks/setupAcl.ts +0 -25
  132. package/src/index.ts +0 -9
  133. package/src/schema/Schema.test.ts +0 -482
  134. package/src/schema/Schema.ts +0 -757
  135. package/src/schema/defaultResolvers.ts +0 -93
  136. package/src/schema/index.ts +0 -1
  137. package/src/schema/resolvers/meResolver.test.ts +0 -62
  138. package/src/schema/resolvers/meResolver.ts +0 -10
  139. package/src/schema/resolvers/resetPassword.test.ts +0 -341
  140. package/src/schema/resolvers/resetPassword.ts +0 -63
  141. package/src/schema/resolvers/sendEmail.test.ts +0 -118
  142. package/src/schema/resolvers/sendEmail.ts +0 -21
  143. package/src/schema/resolvers/sendOtpCode.test.ts +0 -141
  144. package/src/schema/resolvers/sendOtpCode.ts +0 -52
  145. package/src/security.test.ts +0 -3434
  146. package/src/server/defaultSessionHandler.test.ts +0 -62
  147. package/src/server/defaultSessionHandler.ts +0 -105
  148. package/src/server/generateCodegen.ts +0 -433
  149. package/src/server/index.test.ts +0 -532
  150. package/src/server/index.ts +0 -334
  151. package/src/server/interface.ts +0 -11
  152. package/src/server/routes/authHandler.ts +0 -169
  153. package/src/server/routes/index.ts +0 -39
  154. package/src/utils/crypto.test.ts +0 -41
  155. package/src/utils/crypto.ts +0 -105
  156. package/src/utils/export.ts +0 -11
  157. package/src/utils/helper.ts +0 -204
  158. package/src/utils/index.test.ts +0 -11
  159. package/src/utils/index.ts +0 -189
  160. package/src/utils/preload.ts +0 -8
  161. package/src/utils/testHelper.ts +0 -116
  162. package/tsconfig.json +0 -32
@@ -1,880 +0,0 @@
1
- import {
2
- GraphQLEnumType,
3
- type GraphQLFieldConfig,
4
- GraphQLID,
5
- GraphQLInputObjectType,
6
- GraphQLInt,
7
- GraphQLList,
8
- GraphQLNonNull,
9
- GraphQLObjectType,
10
- type GraphQLOutputType,
11
- GraphQLScalarType,
12
- GraphQLBoolean,
13
- GraphQLString,
14
- } from 'graphql'
15
- import { pluralize } from 'wabe-pluralize'
16
- import type { WabeTypes } from '..'
17
- import type {
18
- ClassInterface,
19
- MutationResolver,
20
- QueryResolver,
21
- Schema,
22
- SchemaFields,
23
- } from '../schema'
24
- import { firstLetterInLowerCase } from '../utils'
25
- import type { DevWabeTypes } from '../utils/helper'
26
- import { GraphqlParser, type GraphqlParserFactory } from './parser'
27
- import {
28
- mutationToCreateMultipleObjects,
29
- mutationToCreateObject,
30
- mutationToDeleteMultipleObjects,
31
- mutationToDeleteObject,
32
- mutationToUpdateMultipleObjects,
33
- mutationToUpdateObject,
34
- queryForMultipleObject,
35
- queryForOneObject,
36
- } from './resolvers'
37
- import { DateScalarType, FileScalarType, IdWhereInput, SearchWhereInput } from './types'
38
-
39
- type AllPossibleObject =
40
- | 'object'
41
- | 'inputObject'
42
- | 'whereInputObject'
43
- | 'connectionObject'
44
- | 'pointerInputObject'
45
- | 'relationInputObject'
46
- | 'updateInputObject'
47
- | 'createInputObject'
48
- | 'orderEnumType'
49
-
50
- export type AllObjects = Record<string, Partial<Record<AllPossibleObject, any>>>
51
-
52
- export class GraphQLSchema {
53
- private schemas: Schema<DevWabeTypes>
54
-
55
- private allObjects: AllObjects
56
-
57
- constructor(schemas: Schema<any>) {
58
- this.schemas = schemas
59
- this.allObjects = {}
60
- }
61
-
62
- createSchema() {
63
- if (!this.schemas) throw new Error('Schema not found')
64
-
65
- const scalars = this.createScalars()
66
- const enums = this.createEnums()
67
-
68
- const classes = this.schemas.schema.classes || []
69
-
70
- const graphqlParser = GraphqlParser({ scalars, enums })
71
-
72
- classes.map((wabeClass) => this.createCompleteObject(graphqlParser, wabeClass))
73
-
74
- const queriesMutationAndObjects = classes.reduce(
75
- (acc, current) => {
76
- const className = current.name.replace(' ', '')
77
-
78
- const currentObject = this.allObjects[className]
79
-
80
- if (!currentObject) throw new Error('Object not found')
81
-
82
- const {
83
- object,
84
- inputObject,
85
- pointerInputObject,
86
- relationInputObject,
87
- createInputObject,
88
- updateInputObject,
89
- whereInputObject,
90
- connectionObject,
91
- orderEnumType,
92
- } = currentObject
93
-
94
- // Queries
95
- const defaultQueries = this.createDefaultQueries({
96
- className,
97
- whereInputType: whereInputObject,
98
- object,
99
- connectionObject,
100
- orderEnumType,
101
- })
102
-
103
- const defaultMutations = this.createDefaultMutations({
104
- className,
105
- whereInputType: whereInputObject,
106
- object,
107
- connectionObject,
108
- defaultUpdateInputType: updateInputObject,
109
- defaultCreateInputType: createInputObject,
110
- orderEnumType,
111
- })
112
-
113
- const defaultQueriesKeys = Object.keys(defaultQueries)
114
- const defaultMutationsKeys = Object.keys(defaultMutations)
115
-
116
- // Loop to avoid O(n)² complexity of spread on accumulator
117
- for (const key in defaultQueriesKeys) {
118
- // @ts-expect-error
119
- acc.queries[defaultQueriesKeys[key]] =
120
- // @ts-expect-error
121
- defaultQueries[defaultQueriesKeys[key]]
122
- }
123
-
124
- for (const key in defaultMutationsKeys) {
125
- // @ts-expect-error
126
- acc.mutations[defaultMutationsKeys[key]] =
127
- // @ts-expect-error
128
- defaultMutations[defaultMutationsKeys[key]]
129
- }
130
-
131
- acc.objects.push(object)
132
- acc.objects.push(inputObject)
133
- acc.objects.push(pointerInputObject)
134
- acc.objects.push(relationInputObject)
135
-
136
- return acc
137
- },
138
- {
139
- queries: {},
140
- mutations: {},
141
- objects: [...this.createFileObjects()],
142
- } as {
143
- queries: Record<string, GraphQLFieldConfig<any, any, any>>
144
- mutations: Record<string, GraphQLFieldConfig<any, any, any>>
145
- objects: Array<GraphQLObjectType | GraphQLInputObjectType>
146
- },
147
- )
148
-
149
- const customQueries = this.createCustomQueries({
150
- resolvers: this.schemas.schema.resolvers?.queries || {},
151
- graphqlParser,
152
- })
153
- const customQueriesKeys = Object.keys(customQueries)
154
-
155
- for (const key in customQueriesKeys) {
156
- // @ts-expect-error
157
- queriesMutationAndObjects.queries[customQueriesKeys[key]] =
158
- // @ts-expect-error
159
- customQueries[customQueriesKeys[key]]
160
- }
161
-
162
- // Mutations
163
- const customMutations = this.createCustomMutations({
164
- resolvers: this.schemas.schema.resolvers?.mutations || {},
165
- graphqlParser,
166
- })
167
- const customMutationsKeys = Object.keys(customMutations)
168
-
169
- for (const key in customMutationsKeys) {
170
- // @ts-expect-error
171
- queriesMutationAndObjects.mutations[customMutationsKeys[key]] =
172
- // @ts-expect-error
173
- customMutations[customMutationsKeys[key]]
174
- }
175
-
176
- return {
177
- queries: queriesMutationAndObjects.queries,
178
- mutations: queriesMutationAndObjects.mutations,
179
- scalars,
180
- enums,
181
- objects: queriesMutationAndObjects.objects,
182
- }
183
- }
184
-
185
- createFileObjects() {
186
- const fileInfoObject = new GraphQLObjectType({
187
- name: 'FileInfo',
188
- description: 'Object containing information about the file',
189
- fields: () => ({
190
- name: { type: GraphQLString },
191
- url: { type: GraphQLString },
192
- urlGeneratedAt: {
193
- type: DateScalarType,
194
- },
195
- isPresignedUrl: { type: GraphQLBoolean },
196
- }),
197
- })
198
-
199
- const fileInputObject = new GraphQLInputObjectType({
200
- name: 'FileInput',
201
- description: 'Input to create a file',
202
- fields: () => ({
203
- file: { type: FileScalarType },
204
- url: { type: GraphQLString },
205
- }),
206
- })
207
-
208
- this.allObjects.FileInfo = {
209
- object: fileInfoObject,
210
- inputObject: fileInputObject,
211
- }
212
-
213
- return [fileInfoObject]
214
- }
215
-
216
- createScalars() {
217
- return (
218
- this.schemas.schema.scalars?.map(
219
- (scalar) =>
220
- new GraphQLScalarType({
221
- ...scalar,
222
- }),
223
- ) || []
224
- )
225
- }
226
-
227
- createOrderEnumType(wabeClass: ClassInterface<DevWabeTypes>) {
228
- const fields = wabeClass.fields
229
-
230
- const classEnums = Object.keys(fields).reduce(
231
- (acc, fieldName) => {
232
- acc[`${fieldName}_ASC`] = { value: { [fieldName]: 'ASC' } }
233
- acc[`${fieldName}_DESC`] = { value: { [fieldName]: 'DESC' } }
234
-
235
- return acc
236
- },
237
- {} as Record<string, any>,
238
- )
239
-
240
- return new GraphQLEnumType({
241
- name: `${wabeClass.name}Order`,
242
- values: classEnums,
243
- })
244
- }
245
-
246
- createEnums() {
247
- return (
248
- this.schemas.schema.enums?.map((wabeEnum) => {
249
- const enumValues = wabeEnum.values
250
-
251
- const values = Object.keys(enumValues).reduce(
252
- (acc, value) => {
253
- acc[value] = { value: enumValues[value] }
254
-
255
- return acc
256
- },
257
- {} as Record<string, any>,
258
- )
259
-
260
- return new GraphQLEnumType({
261
- ...wabeEnum,
262
- values,
263
- })
264
- }) || []
265
- )
266
- }
267
-
268
- createObject({
269
- wabeClass,
270
- graphqlParser,
271
- }: {
272
- wabeClass: ClassInterface<DevWabeTypes>
273
- graphqlParser: GraphqlParserFactory<DevWabeTypes>
274
- }) {
275
- const { name, fields, description } = wabeClass
276
-
277
- const nameWithoutSpace = name.replace(' ', '')
278
-
279
- const graphqlParserWithInput = graphqlParser({
280
- schemaFields: fields,
281
- graphqlObjectType: 'Object',
282
- allObjects: this.allObjects,
283
- })
284
-
285
- return new GraphQLObjectType({
286
- name: nameWithoutSpace,
287
- description,
288
- // We need to use function here to have lazy loading of fields
289
- fields: () => ({
290
- id: { type: new GraphQLNonNull(GraphQLID) },
291
- ...graphqlParserWithInput.getGraphqlFields(nameWithoutSpace),
292
- }),
293
- })
294
- }
295
-
296
- createPointerInputObject({
297
- wabeClass,
298
- inputCreateFields,
299
- }: {
300
- wabeClass: ClassInterface<DevWabeTypes>
301
- inputCreateFields: GraphQLInputObjectType
302
- }) {
303
- const { name } = wabeClass
304
-
305
- const nameWithoutSpace = name.replace(' ', '')
306
-
307
- return new GraphQLInputObjectType({
308
- name: `${nameWithoutSpace}PointerInput`,
309
- description: `Input to link an object to a pointer ${nameWithoutSpace}`,
310
- fields: () => ({
311
- unlink: { type: GraphQLBoolean },
312
- link: { type: GraphQLID },
313
- createAndLink: { type: inputCreateFields },
314
- }),
315
- })
316
- }
317
-
318
- createRelationInputObject({
319
- wabeClass,
320
- inputCreateFields,
321
- }: {
322
- wabeClass: ClassInterface<DevWabeTypes>
323
- inputCreateFields: GraphQLInputObjectType
324
- }) {
325
- const { name } = wabeClass
326
-
327
- const nameWithoutSpace = name.replace(' ', '')
328
-
329
- return new GraphQLInputObjectType({
330
- name: `${nameWithoutSpace}RelationInput`,
331
- description: `Input to add a relation to the class ${nameWithoutSpace}`,
332
- fields: () => ({
333
- add: { type: new GraphQLList(new GraphQLNonNull(GraphQLID)) },
334
- remove: {
335
- type: new GraphQLList(new GraphQLNonNull(GraphQLID)),
336
- },
337
- createAndAdd: {
338
- type: new GraphQLList(new GraphQLNonNull(inputCreateFields)),
339
- },
340
- }),
341
- })
342
- }
343
-
344
- createInputObject({
345
- wabeClass,
346
- graphqlParser,
347
- }: {
348
- wabeClass: ClassInterface<DevWabeTypes>
349
- graphqlParser: GraphqlParserFactory<DevWabeTypes>
350
- }) {
351
- const { name, fields, description } = wabeClass
352
-
353
- const nameWithoutSpace = name.replace(' ', '')
354
-
355
- const graphqlParserWithInput = graphqlParser({
356
- schemaFields: fields,
357
- graphqlObjectType: 'InputObject',
358
- allObjects: this.allObjects,
359
- })
360
-
361
- return new GraphQLInputObjectType({
362
- name: `${nameWithoutSpace}Input`,
363
- description,
364
- fields: () => ({
365
- ...graphqlParserWithInput.getGraphqlFields(nameWithoutSpace),
366
- }),
367
- })
368
- }
369
-
370
- createCreateInputObject({
371
- wabeClass,
372
- graphqlParser,
373
- }: {
374
- wabeClass: ClassInterface<DevWabeTypes>
375
- graphqlParser: GraphqlParserFactory<DevWabeTypes>
376
- }) {
377
- const { name, fields, description } = wabeClass
378
-
379
- const nameWithoutSpace = name.replace(' ', '')
380
-
381
- const graphqlParserWithInput = graphqlParser({
382
- schemaFields: fields,
383
- graphqlObjectType: 'CreateFieldsInput',
384
- allObjects: this.allObjects,
385
- })
386
-
387
- return new GraphQLInputObjectType({
388
- name: `${nameWithoutSpace}CreateFieldsInput`,
389
- description,
390
- fields: () => ({
391
- ...graphqlParserWithInput.getGraphqlFields(nameWithoutSpace),
392
- }),
393
- })
394
- }
395
-
396
- createUpdateInputObject({
397
- wabeClass,
398
- graphqlParser,
399
- }: {
400
- wabeClass: ClassInterface<DevWabeTypes>
401
- graphqlParser: GraphqlParserFactory<DevWabeTypes>
402
- }) {
403
- const { name, fields, description } = wabeClass
404
-
405
- const nameWithoutSpace = name.replace(' ', '')
406
-
407
- const graphqlParserWithInput = graphqlParser({
408
- schemaFields: fields,
409
- graphqlObjectType: 'UpdateFieldsInput',
410
- allObjects: this.allObjects,
411
- })
412
-
413
- return new GraphQLInputObjectType({
414
- name: `${nameWithoutSpace}UpdateFieldsInput`,
415
- description,
416
- fields: () => ({
417
- ...graphqlParserWithInput.getGraphqlFields(nameWithoutSpace),
418
- }),
419
- })
420
- }
421
-
422
- createWhereInputObject({
423
- wabeClass,
424
- graphqlParser,
425
- }: {
426
- wabeClass: ClassInterface<DevWabeTypes>
427
- graphqlParser: GraphqlParserFactory<DevWabeTypes>
428
- }) {
429
- const { name, fields, description } = wabeClass
430
-
431
- const nameWithoutSpace = name.replace(' ', '')
432
-
433
- const graphqlParserWithInput = graphqlParser({
434
- schemaFields: fields,
435
- graphqlObjectType: 'WhereInputObject',
436
- allObjects: this.allObjects,
437
- })
438
-
439
- const inputObject = new GraphQLInputObjectType({
440
- name: `${nameWithoutSpace}WhereInput`,
441
- description,
442
- fields: (): any => ({
443
- id: { type: IdWhereInput },
444
- ...graphqlParserWithInput.getGraphqlFields(nameWithoutSpace),
445
- OR: {
446
- type: new GraphQLList(inputObject),
447
- },
448
- AND: {
449
- type: new GraphQLList(inputObject),
450
- },
451
- search: { type: SearchWhereInput },
452
- }),
453
- })
454
-
455
- return inputObject
456
- }
457
-
458
- createConnectionObject({
459
- object,
460
- wabeClass,
461
- }: {
462
- object: GraphQLObjectType
463
- wabeClass: ClassInterface<DevWabeTypes>
464
- }) {
465
- const edgeObject = new GraphQLObjectType({
466
- name: `${wabeClass.name}Edge`,
467
- fields: () => ({
468
- node: { type: new GraphQLNonNull(object) },
469
- }),
470
- })
471
-
472
- const connectionObject = new GraphQLObjectType({
473
- name: `${wabeClass.name}Connection`,
474
- fields: () => ({
475
- ok: { type: GraphQLBoolean },
476
- totalCount: { type: GraphQLInt },
477
- edges: { type: new GraphQLList(edgeObject) },
478
- }),
479
- })
480
-
481
- return connectionObject
482
- }
483
-
484
- createCompleteObject(
485
- graphqlParser: GraphqlParserFactory<DevWabeTypes>,
486
- wabeClass: ClassInterface<DevWabeTypes>,
487
- ) {
488
- const object = this.createObject({ graphqlParser, wabeClass })
489
-
490
- const connectionObject = this.createConnectionObject({
491
- object,
492
- wabeClass,
493
- })
494
-
495
- const inputObject = this.createInputObject({
496
- graphqlParser,
497
- wabeClass,
498
- })
499
-
500
- const createInputObject = this.createCreateInputObject({
501
- graphqlParser,
502
- wabeClass,
503
- })
504
-
505
- const pointerInputObject = this.createPointerInputObject({
506
- inputCreateFields: createInputObject,
507
- wabeClass,
508
- })
509
-
510
- const relationInputObject = this.createRelationInputObject({
511
- inputCreateFields: createInputObject,
512
- wabeClass,
513
- })
514
-
515
- const updateInputObject = this.createUpdateInputObject({
516
- graphqlParser,
517
- wabeClass,
518
- })
519
-
520
- const whereInputObject = this.createWhereInputObject({
521
- graphqlParser,
522
- wabeClass,
523
- })
524
-
525
- const orderEnumType = this.createOrderEnumType(wabeClass)
526
-
527
- this.allObjects[wabeClass.name] = {
528
- connectionObject,
529
- createInputObject,
530
- updateInputObject,
531
- whereInputObject,
532
- pointerInputObject,
533
- relationInputObject,
534
- inputObject,
535
- object,
536
- orderEnumType,
537
- }
538
- }
539
-
540
- _getGraphQLOutputType(
541
- currentQueryOrMutation: QueryResolver<DevWabeTypes> | MutationResolver<DevWabeTypes>,
542
- graphqlParser: GraphqlParserFactory<DevWabeTypes>,
543
- currentArgs: SchemaFields<DevWabeTypes>,
544
- ): GraphQLOutputType | undefined {
545
- if (currentQueryOrMutation.type === 'Object') {
546
- const objectGraphqlParser = graphqlParser({
547
- schemaFields: currentQueryOrMutation.outputObject.fields,
548
- graphqlObjectType: 'Object',
549
- allObjects: this.allObjects,
550
- })
551
-
552
- return new GraphQLObjectType({
553
- name: currentQueryOrMutation.outputObject.name,
554
- fields: () =>
555
- objectGraphqlParser.getGraphqlFields(currentQueryOrMutation.outputObject.name),
556
- })
557
- }
558
-
559
- if (currentQueryOrMutation.type === 'Array' && currentQueryOrMutation.typeValue === 'Object') {
560
- const outputObject = graphqlParser({
561
- schemaFields: currentQueryOrMutation.outputObject.fields,
562
- graphqlObjectType: 'Object',
563
- allObjects: this.allObjects,
564
- })
565
-
566
- const graphqlObject = new GraphQLObjectType({
567
- name: currentQueryOrMutation.outputObject.name,
568
- fields: () => outputObject.getGraphqlFields(currentQueryOrMutation.outputObject.name),
569
- })
570
-
571
- return new GraphQLList(
572
- currentQueryOrMutation.typeValueRequired
573
- ? new GraphQLNonNull(graphqlObject)
574
- : graphqlObject,
575
- )
576
- }
577
-
578
- const graphqlParserWithInput = graphqlParser({
579
- schemaFields: currentArgs,
580
- graphqlObjectType: 'Object',
581
- allObjects: this.allObjects,
582
- })
583
-
584
- return graphqlParserWithInput.getGraphqlType(currentQueryOrMutation)
585
- }
586
-
587
- createCustomMutations({
588
- resolvers,
589
- graphqlParser,
590
- }: {
591
- resolvers: Record<string, MutationResolver<DevWabeTypes>>
592
- graphqlParser: GraphqlParserFactory<DevWabeTypes>
593
- }) {
594
- return Object.keys(resolvers).reduce(
595
- (acc, currentKey) => {
596
- const currentMutation = resolvers[currentKey]
597
-
598
- if (!currentMutation) return acc
599
-
600
- const required = !!currentMutation?.required
601
- const input = currentMutation?.args?.input || {}
602
- const numberOfFieldsInInput = Object.keys(input).length
603
-
604
- const currentKeyWithFirstLetterUpperCase = `${currentKey[0]?.toUpperCase()}${currentKey.slice(
605
- 1,
606
- )}`
607
-
608
- const graphqlParserWithInput = graphqlParser({
609
- schemaFields: input,
610
- graphqlObjectType: 'InputObject',
611
- allObjects: this.allObjects,
612
- })
613
-
614
- const outputType = this._getGraphQLOutputType(currentMutation, graphqlParser, input)
615
-
616
- if (!outputType) throw new Error('Invalid mutation output type')
617
-
618
- const graphqlInput = new GraphQLInputObjectType({
619
- name: `${currentKeyWithFirstLetterUpperCase}Input`,
620
- fields: graphqlParserWithInput.getGraphqlFields(currentKeyWithFirstLetterUpperCase),
621
- })
622
-
623
- acc[currentKey] = {
624
- type: required ? new GraphQLNonNull(outputType) : outputType,
625
- args:
626
- numberOfFieldsInInput > 0
627
- ? { input: { type: new GraphQLNonNull(graphqlInput) } }
628
- : undefined,
629
- description: currentMutation.description,
630
- resolve: currentMutation.resolve,
631
- }
632
-
633
- return acc
634
- },
635
- {} as Record<string, GraphQLFieldConfig<any, any, any>>,
636
- )
637
- }
638
-
639
- createCustomQueries({
640
- resolvers,
641
- graphqlParser,
642
- }: {
643
- resolvers: Record<string, QueryResolver<DevWabeTypes>>
644
- graphqlParser: GraphqlParserFactory<DevWabeTypes>
645
- }) {
646
- return Object.keys(resolvers).reduce(
647
- (acc, currentKey) => {
648
- const currentQuery = resolvers[currentKey]
649
-
650
- if (!currentQuery) return acc
651
-
652
- const required = !!currentQuery?.required
653
- const currentArgs = currentQuery?.args || {}
654
-
655
- const graphqlParserWithInput = graphqlParser({
656
- schemaFields: currentArgs,
657
- graphqlObjectType: 'Object',
658
- allObjects: this.allObjects,
659
- })
660
-
661
- const outputType = this._getGraphQLOutputType(currentQuery, graphqlParser, currentArgs)
662
-
663
- if (!outputType) throw new Error('Invalid mutation output type')
664
-
665
- acc[currentKey] = {
666
- type: required ? new GraphQLNonNull(outputType) : outputType,
667
- args: graphqlParserWithInput.getGraphqlFields(currentKey),
668
- description: currentQuery.description,
669
- resolve: currentQuery.resolve,
670
- }
671
-
672
- return acc
673
- },
674
- {} as Record<string, GraphQLFieldConfig<any, any, any>>,
675
- )
676
- }
677
-
678
- createDefaultQueries({
679
- className,
680
- whereInputType,
681
- object,
682
- connectionObject,
683
- orderEnumType,
684
- }: {
685
- className: string
686
- whereInputType: GraphQLInputObjectType
687
- object: GraphQLObjectType
688
- connectionObject: GraphQLObjectType
689
- orderEnumType: GraphQLEnumType
690
- }) {
691
- const classNameWithFirstLetterLowerCase = firstLetterInLowerCase(className)
692
-
693
- return {
694
- [classNameWithFirstLetterLowerCase]: {
695
- type: object,
696
- description: object.description,
697
- args: { id: { type: GraphQLID } },
698
- resolve: (root, args, ctx, info) => queryForOneObject(root, args, ctx, info, className),
699
- },
700
- [pluralize(classNameWithFirstLetterLowerCase)]: {
701
- type: new GraphQLNonNull(connectionObject),
702
- description: object.description,
703
- args: {
704
- where: { type: whereInputType },
705
- offset: { type: GraphQLInt },
706
- first: { type: GraphQLInt },
707
- order: { type: new GraphQLList(new GraphQLNonNull(orderEnumType)) },
708
- },
709
- resolve: (root, args, ctx, info) =>
710
- queryForMultipleObject(root, args, ctx, info, className),
711
- },
712
- } as Record<string, GraphQLFieldConfig<any, any, any>>
713
- }
714
-
715
- createDefaultMutations({
716
- className,
717
- object,
718
- defaultUpdateInputType,
719
- defaultCreateInputType,
720
- whereInputType,
721
- connectionObject,
722
- orderEnumType,
723
- }: {
724
- className: string
725
- defaultUpdateInputType: GraphQLInputObjectType
726
- defaultCreateInputType: GraphQLInputObjectType
727
- whereInputType: GraphQLInputObjectType
728
- object: GraphQLObjectType
729
- connectionObject: GraphQLObjectType
730
- orderEnumType: GraphQLEnumType
731
- }) {
732
- const classNameWithFirstLetterLowerCase = firstLetterInLowerCase(className)
733
-
734
- const pluralClassName = pluralize(className)
735
-
736
- const createPayloadType = new GraphQLObjectType({
737
- name: `Create${className}Payload`,
738
- fields: () => ({
739
- [classNameWithFirstLetterLowerCase]: { type: object },
740
- ok: { type: GraphQLBoolean },
741
- }),
742
- })
743
-
744
- const createInputType = new GraphQLInputObjectType({
745
- name: `Create${className}Input`,
746
- fields: () => ({
747
- fields: { type: defaultCreateInputType },
748
- }),
749
- })
750
-
751
- const createsInputType = new GraphQLInputObjectType({
752
- name: `Create${pluralClassName}Input`,
753
- fields: () => ({
754
- fields: {
755
- type: new GraphQLNonNull(new GraphQLList(defaultCreateInputType)),
756
- },
757
- offset: { type: GraphQLInt },
758
- first: { type: GraphQLInt },
759
- order: { type: new GraphQLList(orderEnumType) },
760
- }),
761
- })
762
-
763
- const updatePayloadType = new GraphQLObjectType({
764
- name: `Update${className}Payload`,
765
- fields: () => ({
766
- [classNameWithFirstLetterLowerCase]: { type: object },
767
- ok: { type: GraphQLBoolean },
768
- }),
769
- })
770
-
771
- const updateInputType = new GraphQLInputObjectType({
772
- name: `Update${className}Input`,
773
- fields: () => ({
774
- id: { type: GraphQLID },
775
- fields: { type: defaultUpdateInputType },
776
- }),
777
- })
778
-
779
- const updatesInputType = new GraphQLInputObjectType({
780
- name: `Update${pluralClassName}Input`,
781
- fields: () => ({
782
- fields: { type: defaultUpdateInputType },
783
- where: { type: whereInputType },
784
- offset: { type: GraphQLInt },
785
- first: { type: GraphQLInt },
786
- order: { type: new GraphQLList(orderEnumType) },
787
- }),
788
- })
789
-
790
- const deletePayloadType = new GraphQLObjectType({
791
- name: `Delete${className}Payload`,
792
- fields: () => ({
793
- [classNameWithFirstLetterLowerCase]: { type: object },
794
- ok: { type: GraphQLBoolean },
795
- }),
796
- })
797
-
798
- const deleteInputType = new GraphQLInputObjectType({
799
- name: `Delete${className}Input`,
800
- fields: () => ({
801
- id: { type: GraphQLID },
802
- }),
803
- })
804
-
805
- const deletesInputType = new GraphQLInputObjectType({
806
- name: `Delete${pluralClassName}Input`,
807
- fields: () => ({
808
- where: { type: whereInputType },
809
- order: { type: new GraphQLList(orderEnumType) },
810
- }),
811
- })
812
-
813
- return {
814
- [`create${className}`]: {
815
- type: createPayloadType,
816
- description: object.description,
817
- args: { input: { type: new GraphQLNonNull(createInputType) } },
818
- resolve: (root, args, ctx, info) =>
819
- mutationToCreateObject(root, args, ctx, info, className as keyof WabeTypes['types']),
820
- },
821
- [`create${pluralize(className)}`]: {
822
- type: new GraphQLNonNull(connectionObject),
823
- description: object.description,
824
- args: { input: { type: new GraphQLNonNull(createsInputType) } },
825
- resolve: (root, args, ctx, info) =>
826
- mutationToCreateMultipleObjects(
827
- root,
828
- args,
829
- ctx,
830
- info,
831
- className as keyof WabeTypes['types'],
832
- ),
833
- },
834
- [`update${className}`]: {
835
- type: updatePayloadType,
836
- description: object.description,
837
- args: { input: { type: new GraphQLNonNull(updateInputType) } },
838
- resolve: (root, args, ctx, info) =>
839
- mutationToUpdateObject(root, args, ctx, info, className as keyof WabeTypes['types']),
840
- },
841
- [`update${pluralize(className)}`]: {
842
- type: new GraphQLNonNull(connectionObject),
843
- description: object.description,
844
- args: { input: { type: new GraphQLNonNull(updatesInputType) } },
845
- resolve: (root, args, ctx, info) =>
846
- mutationToUpdateMultipleObjects(
847
- root,
848
- args,
849
- ctx,
850
- info,
851
- className as keyof WabeTypes['types'],
852
- ),
853
- },
854
- [`delete${className}`]: {
855
- type: deletePayloadType,
856
- description: object.description,
857
- args: {
858
- input: {
859
- type: new GraphQLNonNull(deleteInputType),
860
- },
861
- },
862
- resolve: (root, args, ctx, info) =>
863
- mutationToDeleteObject(root, args, ctx, info, className as keyof WabeTypes['types']),
864
- },
865
- [`delete${pluralize(className)}`]: {
866
- type: new GraphQLNonNull(connectionObject),
867
- description: object.description,
868
- args: { input: { type: new GraphQLNonNull(deletesInputType) } },
869
- resolve: (root, args, ctx, info) =>
870
- mutationToDeleteMultipleObjects(
871
- root,
872
- args,
873
- ctx,
874
- info,
875
- className as keyof WabeTypes['types'],
876
- ),
877
- },
878
- } as Record<string, GraphQLFieldConfig<any, any, any>>
879
- }
880
- }