wabe 0.6.12 → 0.6.14

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