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