wabe 0.6.9 → 0.6.10

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 (158) hide show
  1. package/README.md +138 -32
  2. package/bucket/b.txt +1 -0
  3. package/dev/index.ts +215 -0
  4. package/dist/authentication/Session.d.ts +4 -1
  5. package/dist/authentication/interface.d.ts +16 -0
  6. package/dist/email/interface.d.ts +1 -1
  7. package/dist/graphql/resolvers.d.ts +4 -2
  8. package/dist/hooks/index.d.ts +1 -0
  9. package/dist/index.d.ts +0 -1
  10. package/dist/index.js +8713 -8867
  11. package/dist/server/index.d.ts +4 -2
  12. package/dist/utils/crypto.d.ts +7 -0
  13. package/dist/utils/helper.d.ts +4 -1
  14. package/generated/schema.graphql +16 -14
  15. package/generated/wabe.ts +4 -4
  16. package/package.json +15 -15
  17. package/src/authentication/OTP.test.ts +69 -0
  18. package/src/authentication/OTP.ts +66 -0
  19. package/src/authentication/Session.test.ts +665 -0
  20. package/src/authentication/Session.ts +529 -0
  21. package/src/authentication/defaultAuthentication.ts +214 -0
  22. package/src/authentication/index.ts +3 -0
  23. package/src/authentication/interface.ts +157 -0
  24. package/src/authentication/oauth/GitHub.test.ts +105 -0
  25. package/src/authentication/oauth/GitHub.ts +133 -0
  26. package/src/authentication/oauth/Google.test.ts +105 -0
  27. package/src/authentication/oauth/Google.ts +110 -0
  28. package/src/authentication/oauth/Oauth2Client.test.ts +225 -0
  29. package/src/authentication/oauth/Oauth2Client.ts +140 -0
  30. package/src/authentication/oauth/index.ts +2 -0
  31. package/src/authentication/oauth/utils.test.ts +35 -0
  32. package/src/authentication/oauth/utils.ts +28 -0
  33. package/src/authentication/providers/EmailOTP.test.ts +138 -0
  34. package/src/authentication/providers/EmailOTP.ts +93 -0
  35. package/src/authentication/providers/EmailPassword.test.ts +187 -0
  36. package/src/authentication/providers/EmailPassword.ts +130 -0
  37. package/src/authentication/providers/EmailPasswordSRP.test.ts +206 -0
  38. package/src/authentication/providers/EmailPasswordSRP.ts +184 -0
  39. package/src/authentication/providers/GitHub.ts +30 -0
  40. package/src/authentication/providers/Google.ts +30 -0
  41. package/src/authentication/providers/OAuth.test.ts +185 -0
  42. package/src/authentication/providers/OAuth.ts +112 -0
  43. package/src/authentication/providers/PhonePassword.test.ts +187 -0
  44. package/src/authentication/providers/PhonePassword.ts +129 -0
  45. package/src/authentication/providers/QRCodeOTP.test.ts +79 -0
  46. package/src/authentication/providers/QRCodeOTP.ts +65 -0
  47. package/src/authentication/providers/index.ts +6 -0
  48. package/src/authentication/resolvers/refreshResolver.test.ts +37 -0
  49. package/src/authentication/resolvers/refreshResolver.ts +20 -0
  50. package/src/authentication/resolvers/signInWithResolver.inte.test.ts +59 -0
  51. package/src/authentication/resolvers/signInWithResolver.test.ts +307 -0
  52. package/src/authentication/resolvers/signInWithResolver.ts +102 -0
  53. package/src/authentication/resolvers/signOutResolver.test.ts +41 -0
  54. package/src/authentication/resolvers/signOutResolver.ts +22 -0
  55. package/src/authentication/resolvers/signUpWithResolver.test.ts +186 -0
  56. package/src/authentication/resolvers/signUpWithResolver.ts +69 -0
  57. package/src/authentication/resolvers/verifyChallenge.test.ts +136 -0
  58. package/src/authentication/resolvers/verifyChallenge.ts +69 -0
  59. package/src/authentication/roles.test.ts +59 -0
  60. package/src/authentication/roles.ts +40 -0
  61. package/src/authentication/utils.test.ts +99 -0
  62. package/src/authentication/utils.ts +43 -0
  63. package/src/cache/InMemoryCache.test.ts +62 -0
  64. package/src/cache/InMemoryCache.ts +45 -0
  65. package/src/cron/index.test.ts +17 -0
  66. package/src/cron/index.ts +46 -0
  67. package/src/database/DatabaseController.test.ts +625 -0
  68. package/src/database/DatabaseController.ts +983 -0
  69. package/src/database/index.test.ts +1230 -0
  70. package/src/database/index.ts +9 -0
  71. package/src/database/interface.ts +312 -0
  72. package/src/email/DevAdapter.ts +8 -0
  73. package/src/email/EmailController.test.ts +29 -0
  74. package/src/email/EmailController.ts +13 -0
  75. package/src/email/index.ts +2 -0
  76. package/src/email/interface.ts +36 -0
  77. package/src/email/templates/sendOtpCode.ts +120 -0
  78. package/src/file/FileController.ts +28 -0
  79. package/src/file/FileDevAdapter.ts +54 -0
  80. package/src/file/hookDeleteFile.ts +27 -0
  81. package/src/file/hookReadFile.ts +70 -0
  82. package/src/file/hookUploadFile.ts +53 -0
  83. package/src/file/index.test.ts +979 -0
  84. package/src/file/index.ts +2 -0
  85. package/src/file/interface.ts +42 -0
  86. package/src/graphql/GraphQLSchema.test.ts +4399 -0
  87. package/src/graphql/GraphQLSchema.ts +928 -0
  88. package/src/graphql/index.ts +2 -0
  89. package/src/graphql/parseGraphqlSchema.ts +94 -0
  90. package/src/graphql/parser.test.ts +217 -0
  91. package/src/graphql/parser.ts +566 -0
  92. package/src/graphql/pointerAndRelationFunction.ts +200 -0
  93. package/src/graphql/resolvers.ts +467 -0
  94. package/src/graphql/tests/aggregation.test.ts +1123 -0
  95. package/src/graphql/tests/e2e.test.ts +596 -0
  96. package/src/graphql/tests/scalars.test.ts +250 -0
  97. package/src/graphql/types.ts +219 -0
  98. package/src/hooks/HookObject.test.ts +122 -0
  99. package/src/hooks/HookObject.ts +168 -0
  100. package/src/hooks/authentication.ts +76 -0
  101. package/src/hooks/createUser.test.ts +77 -0
  102. package/src/hooks/createUser.ts +10 -0
  103. package/src/hooks/defaultFields.test.ts +187 -0
  104. package/src/hooks/defaultFields.ts +40 -0
  105. package/src/hooks/deleteSession.test.ts +181 -0
  106. package/src/hooks/deleteSession.ts +20 -0
  107. package/src/hooks/hashFieldHook.test.ts +163 -0
  108. package/src/hooks/hashFieldHook.ts +97 -0
  109. package/src/hooks/index.test.ts +207 -0
  110. package/src/hooks/index.ts +430 -0
  111. package/src/hooks/permissions.test.ts +424 -0
  112. package/src/hooks/permissions.ts +113 -0
  113. package/src/hooks/protected.test.ts +551 -0
  114. package/src/hooks/protected.ts +72 -0
  115. package/src/hooks/searchableFields.test.ts +166 -0
  116. package/src/hooks/searchableFields.ts +98 -0
  117. package/src/hooks/session.test.ts +138 -0
  118. package/src/hooks/session.ts +78 -0
  119. package/src/hooks/setEmail.test.ts +216 -0
  120. package/src/hooks/setEmail.ts +35 -0
  121. package/src/hooks/setupAcl.test.ts +589 -0
  122. package/src/hooks/setupAcl.ts +29 -0
  123. package/src/index.ts +9 -0
  124. package/src/schema/Schema.test.ts +484 -0
  125. package/src/schema/Schema.ts +795 -0
  126. package/src/schema/defaultResolvers.ts +94 -0
  127. package/src/schema/index.ts +1 -0
  128. package/src/schema/resolvers/meResolver.test.ts +62 -0
  129. package/src/schema/resolvers/meResolver.ts +14 -0
  130. package/src/schema/resolvers/newFile.ts +0 -0
  131. package/src/schema/resolvers/resetPassword.test.ts +345 -0
  132. package/src/schema/resolvers/resetPassword.ts +64 -0
  133. package/src/schema/resolvers/sendEmail.test.ts +118 -0
  134. package/src/schema/resolvers/sendEmail.ts +21 -0
  135. package/src/schema/resolvers/sendOtpCode.test.ts +153 -0
  136. package/src/schema/resolvers/sendOtpCode.ts +52 -0
  137. package/src/security.test.ts +3461 -0
  138. package/src/server/defaultSessionHandler.test.ts +66 -0
  139. package/src/server/defaultSessionHandler.ts +115 -0
  140. package/src/server/generateCodegen.ts +476 -0
  141. package/src/server/index.test.ts +552 -0
  142. package/src/server/index.ts +354 -0
  143. package/src/server/interface.ts +11 -0
  144. package/src/server/routes/authHandler.ts +187 -0
  145. package/src/server/routes/index.ts +40 -0
  146. package/src/utils/crypto.test.ts +41 -0
  147. package/src/utils/crypto.ts +121 -0
  148. package/src/utils/export.ts +13 -0
  149. package/src/utils/helper.ts +195 -0
  150. package/src/utils/index.test.ts +11 -0
  151. package/src/utils/index.ts +201 -0
  152. package/src/utils/preload.ts +8 -0
  153. package/src/utils/testHelper.ts +117 -0
  154. package/tsconfig.json +32 -0
  155. package/bunfig.toml +0 -4
  156. package/dist/ai/index.d.ts +0 -1
  157. package/dist/ai/interface.d.ts +0 -9
  158. /package/dist/server/{defaultHandlers.d.ts → defaultSessionHandler.d.ts} +0 -0
@@ -0,0 +1,566 @@
1
+ import {
2
+ GraphQLBoolean,
3
+ type GraphQLEnumType,
4
+ type GraphQLFieldConfig,
5
+ GraphQLFloat,
6
+ GraphQLInputObjectType,
7
+ GraphQLInt,
8
+ GraphQLList,
9
+ GraphQLNonNull,
10
+ GraphQLObjectType,
11
+ type GraphQLScalarType,
12
+ GraphQLString,
13
+ } from 'graphql'
14
+ import {
15
+ type AllObjects,
16
+ AnyWhereInput,
17
+ ArrayWhereInput,
18
+ BooleanWhereInput,
19
+ DateScalarType,
20
+ DateWhereInput,
21
+ EmailScalarType,
22
+ EmailWhereInput,
23
+ FileScalarType,
24
+ FileWhereInput,
25
+ FloatWhereInput,
26
+ IntWhereInput,
27
+ PhoneScalarType,
28
+ PhoneWhereInput,
29
+ StringWhereInput,
30
+ } from '../graphql'
31
+ import type { ClassInterface, SchemaFields, WabePrimaryTypes } from '../schema'
32
+ import type { WabeTypes } from '../server'
33
+ import type { DevWabeTypes } from '../utils/helper'
34
+
35
+ type GraphqlObjectType =
36
+ | 'Object'
37
+ | 'InputObject'
38
+ | 'CreateFieldsInput'
39
+ | 'UpdateFieldsInput'
40
+ | 'WhereInputObject'
41
+
42
+ type ParseObjectOptions = {
43
+ required?: boolean
44
+ description?: string
45
+ objectToParse: ClassInterface<any>
46
+ nameOfTheObject: string
47
+ }
48
+
49
+ type ParseObjectCallback = (options: ParseObjectOptions) => any
50
+
51
+ export const templateScalarType: Record<WabePrimaryTypes, GraphQLScalarType> = {
52
+ String: GraphQLString,
53
+ Int: GraphQLInt,
54
+ Float: GraphQLFloat,
55
+ Boolean: GraphQLBoolean,
56
+ Date: DateScalarType,
57
+ Email: EmailScalarType,
58
+ File: FileScalarType,
59
+ Phone: PhoneScalarType,
60
+ Hash: GraphQLString,
61
+ }
62
+
63
+ export const templateWhereInput: Record<
64
+ WabePrimaryTypes | 'Array',
65
+ GraphQLInputObjectType
66
+ > = {
67
+ String: StringWhereInput,
68
+ Int: IntWhereInput,
69
+ Float: FloatWhereInput,
70
+ Boolean: BooleanWhereInput,
71
+ Date: DateWhereInput,
72
+ Email: EmailWhereInput,
73
+ Phone: PhoneWhereInput,
74
+ Array: ArrayWhereInput,
75
+ File: FileWhereInput,
76
+ Hash: StringWhereInput,
77
+ }
78
+
79
+ interface GraphqlParserFactoryOptions {
80
+ graphqlObjectType: GraphqlObjectType
81
+ allObjects: AllObjects
82
+ schemaFields: SchemaFields<DevWabeTypes>
83
+ }
84
+
85
+ interface GraphqlParserConstructorOptions {
86
+ scalars: GraphQLScalarType[]
87
+ enums: GraphQLEnumType[]
88
+ }
89
+
90
+ export type GraphqlParserFactory<T extends WabeTypes> = (
91
+ options: GraphqlParserFactoryOptions,
92
+ ) => {
93
+ _parseWabeObject(options: ParseObjectOptions): any
94
+ _parseWabeWhereInputObject(options: ParseObjectOptions): any
95
+ _parseWabeInputObject(options: ParseObjectOptions): any
96
+ _parseWabeUpdateInputObject(options: ParseObjectOptions): any
97
+ getGraphqlType(options: {
98
+ type: WabePrimaryTypes | 'Array' | T['enums'] | T['scalars']
99
+ typeValue?: WabePrimaryTypes
100
+ isWhereType?: boolean
101
+ }): any
102
+ getGraphqlFields(nameOfTheObject: string): any
103
+ }
104
+
105
+ export type GraphqlParserConstructor = <T extends WabeTypes>(
106
+ options: GraphqlParserConstructorOptions,
107
+ ) => GraphqlParserFactory<T>
108
+
109
+ export const GraphqlParser: GraphqlParserConstructor =
110
+ ({ scalars, enums }: GraphqlParserConstructorOptions) =>
111
+ ({
112
+ graphqlObjectType,
113
+ schemaFields,
114
+ allObjects,
115
+ }: GraphqlParserFactoryOptions) => {
116
+ // Get graphql fields from a wabe object
117
+ const _getGraphqlFieldsFromAnObject = ({
118
+ objectToParse,
119
+ callBackForObjectType,
120
+ forceRequiredToFalse = false,
121
+ isWhereType = false,
122
+ nameOfTheObject,
123
+ }: {
124
+ objectToParse: ClassInterface<DevWabeTypes>
125
+ forceRequiredToFalse?: boolean
126
+ isWhereType?: boolean
127
+ callBackForObjectType: ParseObjectCallback
128
+ nameOfTheObject: string
129
+ }) => {
130
+ const fields = objectToParse.fields
131
+
132
+ const graphqlFields = Object.keys(fields).reduce(
133
+ (acc, key) => {
134
+ const currentField = fields[key]
135
+
136
+ const keyWithFirstLetterUppercase = `${key
137
+ .charAt(0)
138
+ .toUpperCase()}${key.slice(1)}`
139
+
140
+ if (currentField?.type === 'Object') {
141
+ acc[key] = {
142
+ type: callBackForObjectType({
143
+ required: currentField.object.required,
144
+ description: currentField.description,
145
+ objectToParse: currentField.object,
146
+ nameOfTheObject: `${nameOfTheObject}${keyWithFirstLetterUppercase}`,
147
+ }),
148
+ }
149
+
150
+ return acc
151
+ }
152
+
153
+ if (currentField?.type === 'Array') {
154
+ if (currentField?.typeValue === 'Object') {
155
+ const objectList = new GraphQLList(
156
+ callBackForObjectType({
157
+ required: currentField.object.required,
158
+ description: currentField.description,
159
+ objectToParse: currentField.object,
160
+ nameOfTheObject: `${nameOfTheObject}${currentField.object.name}`,
161
+ }),
162
+ )
163
+
164
+ acc[key] = {
165
+ type: currentField.required
166
+ ? new GraphQLNonNull(objectList)
167
+ : objectList,
168
+ }
169
+ }
170
+
171
+ if (
172
+ currentField.typeValue &&
173
+ // @ts-expect-error
174
+ templateScalarType[currentField.typeValue]
175
+ ) {
176
+ const graphqlType = getGraphqlType({
177
+ type: currentField.type,
178
+ // @ts-expect-error
179
+ typeValue: currentField.typeValue,
180
+ isWhereType,
181
+ requiredValue: currentField.requiredValue,
182
+ })
183
+
184
+ acc[key] = {
185
+ type:
186
+ currentField.required && !forceRequiredToFalse
187
+ ? new GraphQLNonNull(graphqlType)
188
+ : graphqlType,
189
+ }
190
+ }
191
+
192
+ return acc
193
+ }
194
+
195
+ const graphqlType = getGraphqlType({
196
+ ...currentField,
197
+ // We never come here, complicated to good type this
198
+ type: currentField?.type as WabePrimaryTypes,
199
+ isWhereType,
200
+ })
201
+
202
+ acc[key] = {
203
+ type:
204
+ currentField?.required && !forceRequiredToFalse
205
+ ? new GraphQLNonNull(graphqlType)
206
+ : graphqlType,
207
+ }
208
+
209
+ return acc
210
+ },
211
+ {} as Record<string, any>,
212
+ )
213
+
214
+ return graphqlFields
215
+ }
216
+
217
+ // ------------------ Parsers ------------------
218
+
219
+ // Parse simple object
220
+ const _parseWabeObject = ({
221
+ required,
222
+ description,
223
+ objectToParse,
224
+ nameOfTheObject,
225
+ }: ParseObjectOptions) => {
226
+ const graphqlFields = _getGraphqlFieldsFromAnObject({
227
+ objectToParse,
228
+ callBackForObjectType: _parseWabeObject,
229
+ nameOfTheObject,
230
+ })
231
+
232
+ const graphqlObject = new GraphQLObjectType({
233
+ name: nameOfTheObject,
234
+ description: description,
235
+ fields: graphqlFields,
236
+ })
237
+
238
+ return required ? new GraphQLNonNull(graphqlObject) : graphqlObject
239
+ }
240
+
241
+ // Parse input object
242
+ const _parseWabeInputObject = ({
243
+ required,
244
+ description,
245
+ objectToParse,
246
+ nameOfTheObject,
247
+ }: ParseObjectOptions) => {
248
+ const graphqlFields = _getGraphqlFieldsFromAnObject({
249
+ objectToParse,
250
+ callBackForObjectType: _parseWabeInputObject,
251
+ nameOfTheObject,
252
+ })
253
+
254
+ const graphqlObject = new GraphQLInputObjectType({
255
+ name: `${nameOfTheObject}Input`,
256
+ description: description,
257
+ fields: graphqlFields,
258
+ })
259
+
260
+ return required ? new GraphQLNonNull(graphqlObject) : graphqlObject
261
+ }
262
+
263
+ // Parse create input object
264
+ const _parseWabeCreateInputObject = ({
265
+ required,
266
+ description,
267
+ objectToParse,
268
+ nameOfTheObject,
269
+ }: ParseObjectOptions) => {
270
+ const graphqlFields = _getGraphqlFieldsFromAnObject({
271
+ objectToParse,
272
+ callBackForObjectType: _parseWabeCreateInputObject,
273
+ forceRequiredToFalse: true,
274
+ nameOfTheObject,
275
+ })
276
+
277
+ const graphqlObject = new GraphQLInputObjectType({
278
+ name: `${nameOfTheObject}CreateFieldsInput`,
279
+ description: description,
280
+ fields: graphqlFields,
281
+ })
282
+
283
+ return required ? new GraphQLNonNull(graphqlObject) : graphqlObject
284
+ }
285
+
286
+ // Parse update input object
287
+ const _parseWabeUpdateInputObject = ({
288
+ required,
289
+ description,
290
+ objectToParse,
291
+ nameOfTheObject,
292
+ }: ParseObjectOptions) => {
293
+ const graphqlFields = _getGraphqlFieldsFromAnObject({
294
+ objectToParse,
295
+ callBackForObjectType: _parseWabeUpdateInputObject,
296
+ forceRequiredToFalse: true,
297
+ nameOfTheObject,
298
+ })
299
+
300
+ const graphqlObject = new GraphQLInputObjectType({
301
+ name: `${nameOfTheObject}UpdateFieldsInput`,
302
+ description: description,
303
+ fields: graphqlFields,
304
+ })
305
+
306
+ return required ? new GraphQLNonNull(graphqlObject) : graphqlObject
307
+ }
308
+
309
+ // Parse where input object
310
+ const _parseWabeWhereInputObject = ({
311
+ required,
312
+ description,
313
+ objectToParse,
314
+ nameOfTheObject,
315
+ }: ParseObjectOptions) => {
316
+ const graphqlFields = _getGraphqlFieldsFromAnObject({
317
+ objectToParse,
318
+ callBackForObjectType: _parseWabeWhereInputObject,
319
+ forceRequiredToFalse: true,
320
+ isWhereType: true,
321
+ nameOfTheObject,
322
+ })
323
+
324
+ const graphqlObject = new GraphQLInputObjectType({
325
+ name: `${nameOfTheObject}WhereInput`,
326
+ description: description,
327
+ fields: (): any => ({
328
+ ...graphqlFields,
329
+ ...{
330
+ OR: {
331
+ type: new GraphQLList(graphqlObject),
332
+ },
333
+ AND: {
334
+ type: new GraphQLList(graphqlObject),
335
+ },
336
+ },
337
+ }),
338
+ })
339
+
340
+ return required ? new GraphQLNonNull(graphqlObject) : graphqlObject
341
+ }
342
+
343
+ const _graphqlObjectFactory: Record<
344
+ GraphqlObjectType,
345
+ {
346
+ callback: ParseObjectCallback
347
+ isWhereType: boolean
348
+ forceRequiredToFalse: boolean
349
+ }
350
+ > = {
351
+ Object: {
352
+ callback: _parseWabeObject,
353
+ isWhereType: false,
354
+ forceRequiredToFalse: false,
355
+ },
356
+ InputObject: {
357
+ callback: _parseWabeInputObject,
358
+ isWhereType: false,
359
+ forceRequiredToFalse: false,
360
+ },
361
+ CreateFieldsInput: {
362
+ callback: _parseWabeCreateInputObject,
363
+ isWhereType: false,
364
+ forceRequiredToFalse: true,
365
+ },
366
+ UpdateFieldsInput: {
367
+ callback: _parseWabeUpdateInputObject,
368
+ isWhereType: false,
369
+ forceRequiredToFalse: true,
370
+ },
371
+ WhereInputObject: {
372
+ callback: _parseWabeWhereInputObject,
373
+ isWhereType: true,
374
+ forceRequiredToFalse: true,
375
+ },
376
+ }
377
+
378
+ // Get the good graphql type for a field
379
+ const getGraphqlType = ({
380
+ type,
381
+ typeValue,
382
+ requiredValue,
383
+ isWhereType = false,
384
+ }: {
385
+ type:
386
+ | WabePrimaryTypes
387
+ | 'Array'
388
+ | keyof WabeTypes['enums']
389
+ | WabeTypes['scalars']
390
+ typeValue?: WabePrimaryTypes
391
+ requiredValue?: boolean
392
+ isWhereType?: boolean
393
+ }) => {
394
+ const scalarExist = scalars.find((scalar) => scalar.name === type)
395
+
396
+ const enumExist = enums.find((e) => e.name === type)
397
+
398
+ if (isWhereType) {
399
+ if (!Object.keys(templateWhereInput).includes(type))
400
+ return AnyWhereInput
401
+
402
+ return templateWhereInput[type as WabePrimaryTypes]
403
+ }
404
+
405
+ if (scalarExist) return scalarExist
406
+ if (enumExist) return enumExist
407
+
408
+ const graphqlType =
409
+ type === 'Array' && typeValue
410
+ ? new GraphQLList(
411
+ requiredValue
412
+ ? new GraphQLNonNull(templateScalarType[typeValue])
413
+ : templateScalarType[typeValue],
414
+ )
415
+ : // @ts-expect-error
416
+ templateScalarType[type]
417
+
418
+ if (!graphqlType) throw new Error(`${type} not exist in schema`)
419
+
420
+ return graphqlType
421
+ }
422
+
423
+ // Get Graphql object from a schema fields passed in WabeGraphqlParser
424
+ const getGraphqlFields = (nameOfTheObject: string) => {
425
+ const { callback, forceRequiredToFalse, isWhereType } =
426
+ _graphqlObjectFactory[graphqlObjectType]
427
+
428
+ const keysOfObject = Object.keys(schemaFields)
429
+
430
+ const rawFields = keysOfObject.reduce(
431
+ (acc, key) => {
432
+ const currentField = schemaFields[key]
433
+
434
+ const isRelation = currentField?.type === 'Relation'
435
+ const isPointer = currentField?.type === 'Pointer'
436
+
437
+ if (isRelation || isPointer) {
438
+ const graphqlObject = allObjects[currentField.class]
439
+
440
+ switch (graphqlObjectType) {
441
+ case 'Object': {
442
+ acc[key] = {
443
+ type: isRelation
444
+ ? graphqlObject?.connectionObject
445
+ : graphqlObject?.object,
446
+ }
447
+
448
+ break
449
+ }
450
+ case 'UpdateFieldsInput':
451
+ case 'CreateFieldsInput':
452
+ case 'InputObject': {
453
+ acc[key] = {
454
+ type: isRelation
455
+ ? graphqlObject?.relationInputObject
456
+ : graphqlObject?.pointerInputObject,
457
+ }
458
+
459
+ break
460
+ }
461
+ case 'WhereInputObject': {
462
+ acc[key] = {
463
+ type: allObjects[currentField.class]?.whereInputObject,
464
+ }
465
+
466
+ break
467
+ }
468
+ }
469
+
470
+ return acc
471
+ }
472
+
473
+ if (currentField?.type === 'File') {
474
+ if (graphqlObjectType === 'Object')
475
+ acc[key] = {
476
+ type: currentField.required
477
+ ? new GraphQLNonNull(allObjects.FileInfo?.object)
478
+ : allObjects.FileInfo?.object,
479
+ }
480
+
481
+ if (
482
+ graphqlObjectType === 'CreateFieldsInput' ||
483
+ graphqlObjectType === 'UpdateFieldsInput'
484
+ ) {
485
+ acc[key] = {
486
+ type: currentField.required
487
+ ? new GraphQLNonNull(allObjects.FileInfo?.inputObject)
488
+ : allObjects.FileInfo?.inputObject,
489
+ }
490
+ }
491
+
492
+ return acc
493
+ }
494
+
495
+ if (currentField?.type === 'Object') {
496
+ acc[key] = {
497
+ type: callback({
498
+ ...currentField,
499
+ objectToParse: currentField.object,
500
+ nameOfTheObject: `${nameOfTheObject}${currentField.object.name}`,
501
+ }),
502
+ }
503
+
504
+ return acc
505
+ }
506
+
507
+ if (currentField?.type === 'Array') {
508
+ if (currentField.typeValue === 'Object') {
509
+ const objectList = new GraphQLList(
510
+ callback({
511
+ ...currentField,
512
+ required: currentField.object.required,
513
+ objectToParse: currentField.object,
514
+ nameOfTheObject: `${nameOfTheObject}${currentField.object.name}`,
515
+ }),
516
+ )
517
+
518
+ acc[key] = {
519
+ type: currentField.required
520
+ ? new GraphQLNonNull(objectList)
521
+ : objectList,
522
+ }
523
+
524
+ return acc
525
+ }
526
+ }
527
+
528
+ const graphqlType = getGraphqlType({
529
+ ...currentField,
530
+ type: currentField?.type,
531
+ isWhereType,
532
+ })
533
+
534
+ acc[key] = {
535
+ type:
536
+ currentField?.required && !forceRequiredToFalse
537
+ ? new GraphQLNonNull(graphqlType)
538
+ : graphqlType,
539
+ }
540
+
541
+ return acc
542
+ },
543
+ {} as Record<string, any>,
544
+ )
545
+
546
+ return Object.keys(rawFields).reduce(
547
+ (acc, key) => {
548
+ const field = rawFields[key]
549
+
550
+ acc[key] = field
551
+
552
+ return acc
553
+ },
554
+ {} as Record<string, GraphQLFieldConfig<any, any, any>>,
555
+ )
556
+ }
557
+
558
+ return {
559
+ getGraphqlType,
560
+ getGraphqlFields,
561
+ _parseWabeObject,
562
+ _parseWabeInputObject,
563
+ _parseWabeUpdateInputObject,
564
+ _parseWabeWhereInputObject,
565
+ }
566
+ }