@wokcito/prisma-generator-pothos-codegen 1.0.0

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 (78) hide show
  1. package/README.md +416 -0
  2. package/package.json +76 -0
  3. package/src/bin.d.ts +2 -0
  4. package/src/bin.js +5 -0
  5. package/src/bin.js.map +1 -0
  6. package/src/crudGenerator/index.d.ts +3 -0
  7. package/src/crudGenerator/index.js +96 -0
  8. package/src/crudGenerator/index.js.map +1 -0
  9. package/src/crudGenerator/templates/mutation.d.ts +9 -0
  10. package/src/crudGenerator/templates/mutation.js +59 -0
  11. package/src/crudGenerator/templates/mutation.js.map +1 -0
  12. package/src/crudGenerator/templates/object.d.ts +4 -0
  13. package/src/crudGenerator/templates/object.js +59 -0
  14. package/src/crudGenerator/templates/object.js.map +1 -0
  15. package/src/crudGenerator/templates/query.d.ts +6 -0
  16. package/src/crudGenerator/templates/query.js +37 -0
  17. package/src/crudGenerator/templates/query.js.map +1 -0
  18. package/src/crudGenerator/templates/resolver.d.ts +2 -0
  19. package/src/crudGenerator/templates/resolver.js +35 -0
  20. package/src/crudGenerator/templates/resolver.js.map +1 -0
  21. package/src/crudGenerator/templates/root.d.ts +20 -0
  22. package/src/crudGenerator/templates/root.js +305 -0
  23. package/src/crudGenerator/templates/root.js.map +1 -0
  24. package/src/crudGenerator/utils/generator.d.ts +10 -0
  25. package/src/crudGenerator/utils/generator.js +20 -0
  26. package/src/crudGenerator/utils/generator.js.map +1 -0
  27. package/src/crudGenerator/utils/objectFields.d.ts +7 -0
  28. package/src/crudGenerator/utils/objectFields.js +58 -0
  29. package/src/crudGenerator/utils/objectFields.js.map +1 -0
  30. package/src/crudGenerator/utils/parts.d.ts +25 -0
  31. package/src/crudGenerator/utils/parts.js +132 -0
  32. package/src/crudGenerator/utils/parts.js.map +1 -0
  33. package/src/env.d.ts +3 -0
  34. package/src/env.js +7 -0
  35. package/src/env.js.map +1 -0
  36. package/src/generator.d.ts +6 -0
  37. package/src/generator.js +22 -0
  38. package/src/generator.js.map +1 -0
  39. package/src/index.d.ts +2 -0
  40. package/src/index.js +3 -0
  41. package/src/index.js.map +1 -0
  42. package/src/inputsGenerator/index.d.ts +34 -0
  43. package/src/inputsGenerator/index.js +19 -0
  44. package/src/inputsGenerator/index.js.map +1 -0
  45. package/src/inputsGenerator/utils/dmmf.d.ts +20 -0
  46. package/src/inputsGenerator/utils/dmmf.js +113 -0
  47. package/src/inputsGenerator/utils/dmmf.js.map +1 -0
  48. package/src/inputsGenerator/utils/inputFields.d.ts +4 -0
  49. package/src/inputsGenerator/utils/inputFields.js +74 -0
  50. package/src/inputsGenerator/utils/inputFields.js.map +1 -0
  51. package/src/inputsGenerator/utils/parser.d.ts +5 -0
  52. package/src/inputsGenerator/utils/parser.js +23 -0
  53. package/src/inputsGenerator/utils/parser.js.map +1 -0
  54. package/src/inputsGenerator/utils/parts.d.ts +7 -0
  55. package/src/inputsGenerator/utils/parts.js +158 -0
  56. package/src/inputsGenerator/utils/parts.js.map +1 -0
  57. package/src/inputsGenerator/utils/templates.d.ts +8 -0
  58. package/src/inputsGenerator/utils/templates.js +60 -0
  59. package/src/inputsGenerator/utils/templates.js.map +1 -0
  60. package/src/utils/config.d.ts +85 -0
  61. package/src/utils/config.js +113 -0
  62. package/src/utils/config.js.map +1 -0
  63. package/src/utils/configUtils.d.ts +2 -0
  64. package/src/utils/configUtils.js +9 -0
  65. package/src/utils/configUtils.js.map +1 -0
  66. package/src/utils/filesystem.d.ts +7 -0
  67. package/src/utils/filesystem.js +38 -0
  68. package/src/utils/filesystem.js.map +1 -0
  69. package/src/utils/replacer.d.ts +4 -0
  70. package/src/utils/replacer.js +3 -0
  71. package/src/utils/replacer.js.map +1 -0
  72. package/src/utils/string.d.ts +4 -0
  73. package/src/utils/string.js +18 -0
  74. package/src/utils/string.js.map +1 -0
  75. package/src/utils/template.d.ts +3 -0
  76. package/src/utils/template.js +13 -0
  77. package/src/utils/template.js.map +1 -0
  78. package/tsconfig.tsbuildinfo +1 -0
@@ -0,0 +1,59 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.mutations = void 0;
4
+ const resolver_1 = require("./resolver");
5
+ const mutationNames = ['createMany', 'createOne', 'deleteMany', 'deleteOne', 'updateMany', 'updateOne', 'upsertOne'];
6
+ const makeMutation = (operation, type, nullable, args, resolve, isPrisma = true) => (0, resolver_1.makeResolver)('Mutation', isPrisma ? '' : "\nimport { BatchPayload } from '../../objects';", operation, type, nullable, args, resolve, isPrisma);
7
+ const createManyArgs = '{ data: t.field({ type: [Inputs.#{modelName}CreateInput], required: true }) }';
8
+ const createManyResolver = `async (_query, _root, args, _context, _info) =>
9
+ await #{prisma}.$transaction(args.data.map((data) => #{prisma}.#{modelNameLower}.create({ data })))`;
10
+ const createMany = makeMutation('createMany', "['#{modelName}']", 'false', createManyArgs, createManyResolver);
11
+ const createOneArgs = '{ data: t.field({ type: Inputs.#{modelName}CreateInput, required: true }) }';
12
+ const createOneResolver = `async (query, _root, args, _context, _info) =>
13
+ await #{prisma}.#{modelNameLower}.create({ data: args.data, ...query })`;
14
+ const createOne = makeMutation('createOne', "'#{modelName}'", 'false', createOneArgs, createOneResolver);
15
+ const deleteManyArgs = '{ where: t.field({ type: Inputs.#{modelName}WhereInput, required: true }) }';
16
+ const deleteManyResolver = `async (_root, args, _context, _info) =>
17
+ await #{prisma}.#{modelNameLower}.deleteMany({ where: args.where })`;
18
+ const deleteMany = makeMutation('deleteMany', 'BatchPayload', 'true', deleteManyArgs, deleteManyResolver, false);
19
+ const delteOneArgs = '{ where: t.field({ type: Inputs.#{modelName}WhereUniqueInput, required: true }) }';
20
+ const deleteOneResolver = `async (query, _root, args, _context, _info) =>
21
+ await #{prisma}.#{modelNameLower}.delete({ where: args.where, ...query })`;
22
+ const deleteOne = makeMutation('deleteOne', "'#{modelName}'", 'true', delteOneArgs, deleteOneResolver);
23
+ const updateManyArgs = `{
24
+ where: t.field({ type: Inputs.#{modelName}WhereInput, required: false }),
25
+ data: t.field({ type: Inputs.#{modelName}UpdateManyMutationInput, required: true }),
26
+ }`;
27
+ const updateManyResolver = `async (_root, args, _context, _info) =>
28
+ await #{prisma}.#{modelNameLower}.updateMany({ where: args.where || undefined, data: args.data })`;
29
+ const updateMany = makeMutation('updateMany', 'BatchPayload', 'false', updateManyArgs, updateManyResolver, false);
30
+ const updateOneArgs = `{
31
+ where: t.field({ type: Inputs.#{modelName}WhereUniqueInput, required: true }),
32
+ data: t.field({ type: Inputs.#{modelName}UpdateInput, required: true }),
33
+ }`;
34
+ const updateOneResolver = `async (query, _root, args, _context, _info) =>
35
+ await #{prisma}.#{modelNameLower}.update({ where: args.where, data: args.data, ...query })`;
36
+ const updateOne = makeMutation('updateOne', "'#{modelName}'", 'true', updateOneArgs, updateOneResolver);
37
+ const upsertOneArgs = `{
38
+ where: t.field({ type: Inputs.#{modelName}WhereUniqueInput, required: true }),
39
+ create: t.field({ type: Inputs.#{modelName}CreateInput, required: true }),
40
+ update: t.field({ type: Inputs.#{modelName}UpdateInput, required: true }),
41
+ }`;
42
+ const upsertOneResolver = `async (query, _root, args, _context, _info) =>
43
+ await #{prisma}.#{modelNameLower}.upsert({
44
+ where: args.where,
45
+ create: args.create,
46
+ update: args.update,
47
+ ...query,
48
+ })`;
49
+ const upsertOne = makeMutation('upsertOne', "'#{modelName}'", 'false', upsertOneArgs, upsertOneResolver);
50
+ exports.mutations = {
51
+ createMany,
52
+ createOne,
53
+ deleteMany,
54
+ deleteOne,
55
+ updateMany,
56
+ updateOne,
57
+ upsertOne,
58
+ };
59
+ //# sourceMappingURL=mutation.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mutation.js","sourceRoot":"","sources":["../../../../src/crudGenerator/templates/mutation.ts"],"names":[],"mappings":";;;AAAA,yCAAyC;AAEzC,MAAM,aAAa,GAAG,CAAC,YAAY,EAAE,WAAW,EAAE,YAAY,EAAE,WAAW,EAAE,YAAY,EAAE,WAAW,EAAE,WAAW,CAAC,CAAA;AAGpH,MAAM,YAAY,GAAG,CACnB,SAA2B,EAC3B,IAAY,EACZ,QAA0B,EAC1B,IAAY,EACZ,OAAe,EACf,QAAQ,GAAG,IAAI,EACf,EAAE,CACF,IAAA,uBAAY,EACV,UAAU,EACV,QAAQ,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,iDAAiD,EACjE,SAAS,EACT,IAAI,EACJ,QAAQ,EACR,IAAI,EACJ,OAAO,EACP,QAAQ,CACT,CAAA;AAEH,MAAM,cAAc,GAAG,+EAA+E,CAAA;AAEtG,MAAM,kBAAkB,GAAG;0GAC+E,CAAA;AAE1G,MAAM,UAAU,GAAG,YAAY,CAAC,YAAY,EAAE,kBAAkB,EAAE,OAAO,EAAE,cAAc,EAAE,kBAAkB,CAAC,CAAA;AAE9G,MAAM,aAAa,GAAG,6EAA6E,CAAA;AAEnG,MAAM,iBAAiB,GAAG;8EACoD,CAAA;AAE9E,MAAM,SAAS,GAAG,YAAY,CAAC,WAAW,EAAE,gBAAgB,EAAE,OAAO,EAAE,aAAa,EAAE,iBAAiB,CAAC,CAAA;AAExG,MAAM,cAAc,GAAG,6EAA6E,CAAA;AAEpG,MAAM,kBAAkB,GAAG;0EAC+C,CAAA;AAE1E,MAAM,UAAU,GAAG,YAAY,CAAC,YAAY,EAAE,cAAc,EAAE,MAAM,EAAE,cAAc,EAAE,kBAAkB,EAAE,KAAK,CAAC,CAAA;AAEhH,MAAM,YAAY,GAAG,mFAAmF,CAAA;AAExG,MAAM,iBAAiB,GAAG;gFACsD,CAAA;AAEhF,MAAM,SAAS,GAAG,YAAY,CAAC,WAAW,EAAE,gBAAgB,EAAE,MAAM,EAAE,YAAY,EAAE,iBAAiB,CAAC,CAAA;AAEtG,MAAM,cAAc,GAAG;;;MAGjB,CAAA;AAEN,MAAM,kBAAkB,GAAG;wGAC6E,CAAA;AAExG,MAAM,UAAU,GAAG,YAAY,CAAC,YAAY,EAAE,cAAc,EAAE,OAAO,EAAE,cAAc,EAAE,kBAAkB,EAAE,KAAK,CAAC,CAAA;AAEjH,MAAM,aAAa,GAAG;;;MAGhB,CAAA;AAEN,MAAM,iBAAiB,GAAG;iGACuE,CAAA;AAEjG,MAAM,SAAS,GAAG,YAAY,CAAC,WAAW,EAAE,gBAAgB,EAAE,MAAM,EAAE,aAAa,EAAE,iBAAiB,CAAC,CAAA;AAEvG,MAAM,aAAa,GAAG;;;;MAIhB,CAAA;AAEN,MAAM,iBAAiB,GAAG;;;;;;SAMjB,CAAA;AAET,MAAM,SAAS,GAAG,YAAY,CAAC,WAAW,EAAE,gBAAgB,EAAE,OAAO,EAAE,aAAa,EAAE,iBAAiB,CAAC,CAAA;AAE3F,QAAA,SAAS,GAAG;IACvB,UAAU;IACV,SAAS;IACT,UAAU;IACV,SAAS;IACT,UAAU;IACV,SAAS;IACT,SAAS;CACV,CAAA"}
@@ -0,0 +1,4 @@
1
+ export declare const objectTemplate = "#{inputsImporter}#{builderCalculatedImport}\nimport {\n definePrismaObject,\n defineFieldObject,\n defineRelationFunction,\n defineRelationObject,\n} from '../utils';\n\nexport const #{modelName}#{optionalUnderscore}Object = definePrismaObject('#{modelName}', {\n description: #{description},\n findUnique: #{findUnique},\n fields: (t) => ({\n #{fields}\n }),\n});\n\n#{exportFields}\n";
2
+ export declare const fieldObjectTemplate = "export const #{modelName}#{optionalUnderscore}#{nameUpper}#{optionalUnderscore}FieldObject = defineFieldObject('#{modelName}', {\n type: #{conditionalType},\n description: #{description},\n nullable: #{nullable},\n resolve: (parent) => #{conditionalResolve},\n});";
3
+ export declare const listRelationObjectTemplate = "export const #{modelName}#{optionalUnderscore}#{nameUpper}#{optionalUnderscore}FieldArgs = builder.args((t) => ({\n where: t.field({ type: Inputs.#{type}WhereInput, required: false }),\n orderBy: t.field({ type: [Inputs.#{type}OrderByWithRelationInput], required: false }),\n cursor: t.field({ type: Inputs.#{type}WhereUniqueInput, required: false }),\n take: t.field({ type: 'Int', required: false }),\n skip: t.field({ type: 'Int', required: false }),\n distinct: t.field({ type: [Inputs.#{typeUpper}ScalarFieldEnum], required: false }),\n}))\n\nexport const #{modelName}#{optionalUnderscore}#{nameUpper}#{optionalUnderscore}FieldObject = defineRelationFunction('#{modelName}', (t) =>\n defineRelationObject('#{modelName}', '#{name}', {\n description: #{description},\n nullable: #{nullable},\n args: #{modelName}#{optionalUnderscore}#{nameUpper}#{optionalUnderscore}FieldArgs,\n query: (args) => ({\n where: args.where || undefined,\n cursor: args.cursor || undefined,\n take: args.take || undefined,\n distinct: args.distinct || undefined,\n skip: args.skip || undefined,\n orderBy: args.orderBy || undefined,\n }),\n }),\n);";
4
+ export declare const relationObjectTemplate = "export const #{modelName}#{optionalUnderscore}#{nameUpper}#{optionalUnderscore}FieldObject = defineRelationObject('#{modelName}', '#{name}', {\n description: #{description},\n nullable: #{nullable},\n args: undefined,\n query: undefined,\n});";
@@ -0,0 +1,59 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.relationObjectTemplate = exports.listRelationObjectTemplate = exports.fieldObjectTemplate = exports.objectTemplate = void 0;
4
+ // TODO only import what is necessary
5
+ exports.objectTemplate = `#{inputsImporter}#{builderCalculatedImport}
6
+ import {
7
+ definePrismaObject,
8
+ defineFieldObject,
9
+ defineRelationFunction,
10
+ defineRelationObject,
11
+ } from '../utils';
12
+
13
+ export const #{modelName}#{optionalUnderscore}Object = definePrismaObject('#{modelName}', {
14
+ description: #{description},
15
+ findUnique: #{findUnique},
16
+ fields: (t) => ({
17
+ #{fields}
18
+ }),
19
+ });
20
+
21
+ #{exportFields}
22
+ `;
23
+ exports.fieldObjectTemplate = `export const #{modelName}#{optionalUnderscore}#{nameUpper}#{optionalUnderscore}FieldObject = defineFieldObject('#{modelName}', {
24
+ type: #{conditionalType},
25
+ description: #{description},
26
+ nullable: #{nullable},
27
+ resolve: (parent) => #{conditionalResolve},
28
+ });`;
29
+ exports.listRelationObjectTemplate = `export const #{modelName}#{optionalUnderscore}#{nameUpper}#{optionalUnderscore}FieldArgs = builder.args((t) => ({
30
+ where: t.field({ type: Inputs.#{type}WhereInput, required: false }),
31
+ orderBy: t.field({ type: [Inputs.#{type}OrderByWithRelationInput], required: false }),
32
+ cursor: t.field({ type: Inputs.#{type}WhereUniqueInput, required: false }),
33
+ take: t.field({ type: 'Int', required: false }),
34
+ skip: t.field({ type: 'Int', required: false }),
35
+ distinct: t.field({ type: [Inputs.#{typeUpper}ScalarFieldEnum], required: false }),
36
+ }))
37
+
38
+ export const #{modelName}#{optionalUnderscore}#{nameUpper}#{optionalUnderscore}FieldObject = defineRelationFunction('#{modelName}', (t) =>
39
+ defineRelationObject('#{modelName}', '#{name}', {
40
+ description: #{description},
41
+ nullable: #{nullable},
42
+ args: #{modelName}#{optionalUnderscore}#{nameUpper}#{optionalUnderscore}FieldArgs,
43
+ query: (args) => ({
44
+ where: args.where || undefined,
45
+ cursor: args.cursor || undefined,
46
+ take: args.take || undefined,
47
+ distinct: args.distinct || undefined,
48
+ skip: args.skip || undefined,
49
+ orderBy: args.orderBy || undefined,
50
+ }),
51
+ }),
52
+ );`;
53
+ exports.relationObjectTemplate = `export const #{modelName}#{optionalUnderscore}#{nameUpper}#{optionalUnderscore}FieldObject = defineRelationObject('#{modelName}', '#{name}', {
54
+ description: #{description},
55
+ nullable: #{nullable},
56
+ args: undefined,
57
+ query: undefined,
58
+ });`;
59
+ //# sourceMappingURL=object.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"object.js","sourceRoot":"","sources":["../../../../src/crudGenerator/templates/object.ts"],"names":[],"mappings":";;;AAAA,qCAAqC;AACxB,QAAA,cAAc,GAAG;;;;;;;;;;;;;;;;;CAiB7B,CAAA;AAEY,QAAA,mBAAmB,GAAG;;;;;IAK/B,CAAA;AAES,QAAA,0BAA0B,GAAG;;;;;;;;;;;;;;;;;;;;;;;GAuBvC,CAAA;AAEU,QAAA,sBAAsB,GAAG;;;;;IAKlC,CAAA"}
@@ -0,0 +1,6 @@
1
+ export declare const queries: {
2
+ findFirst: string;
3
+ findMany: string;
4
+ count: string;
5
+ findUnique: string;
6
+ };
@@ -0,0 +1,37 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.queries = void 0;
4
+ const template_1 = require("../../utils/template");
5
+ const resolver_1 = require("./resolver");
6
+ const queryNames = ['findFirst', 'findMany', 'count', 'findUnique'];
7
+ const makeQuery = (operation, type, nullable, isPrisma = true, args, resolve) => (0, resolver_1.makeResolver)('Query', '', operation, type, nullable, args !== null && args !== void 0 ? args : (0, template_1.useTemplate)(queryListArgsTemplate, {}, ['modelName', 'modelNameUpper']), resolve !== null && resolve !== void 0 ? resolve : (0, template_1.useTemplate)(queryListResolveTemplate, {
8
+ distinct: operation === 'count' ? '' : '\n distinct: args.distinct || undefined,',
9
+ operation,
10
+ query: isPrisma ? '\n ...query,' : '',
11
+ argsQuery: isPrisma ? 'query, ' : '',
12
+ }, ['prisma', 'modelNameLower']), isPrisma);
13
+ const queryListArgsTemplate = `{
14
+ where: t.field({ type: Inputs.#{modelName}WhereInput, required: false }),
15
+ orderBy: t.field({ type: [Inputs.#{modelName}OrderByWithRelationInput], required: false }),
16
+ cursor: t.field({ type: Inputs.#{modelName}WhereUniqueInput, required: false }),
17
+ take: t.field({ type: 'Int', required: false }),
18
+ skip: t.field({ type: 'Int', required: false }),
19
+ distinct: t.field({ type: [Inputs.#{modelNameUpper}ScalarFieldEnum], required: false }),
20
+ }`;
21
+ const queryListResolveTemplate = `async (#{argsQuery}_root, args, _context, _info) =>
22
+ await #{prisma}.#{modelNameLower}.#{operation}({
23
+ where: args.where || undefined,
24
+ cursor: args.cursor || undefined,
25
+ take: args.take || undefined,#{distinct}
26
+ skip: args.skip || undefined,
27
+ orderBy: args.orderBy || undefined,#{query}
28
+ })`;
29
+ const querySingleArgsTemplate = `{ where: t.field({ type: Inputs.#{modelName}WhereUniqueInput, required: true }) }`;
30
+ const querySingleResolveTemplate = `async (query, _root, args, _context, _info) =>
31
+ await #{prisma}.#{modelNameLower}.findUnique({ where: args.where, ...query })`;
32
+ const findFirst = makeQuery('findFirst', "'#{modelName}'", 'true');
33
+ const findMany = makeQuery('findMany', "['#{modelName}']", 'false');
34
+ const count = makeQuery('count', "'Int'", 'false', false);
35
+ const findUnique = makeQuery('findUnique', "'#{modelName}'", 'true', true, (0, template_1.useTemplate)(querySingleArgsTemplate, {}, ['modelName']), (0, template_1.useTemplate)(querySingleResolveTemplate, {}, ['prisma', 'modelNameLower']));
36
+ exports.queries = { findFirst, findMany, count, findUnique };
37
+ //# sourceMappingURL=query.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"query.js","sourceRoot":"","sources":["../../../../src/crudGenerator/templates/query.ts"],"names":[],"mappings":";;;AAAA,mDAAkD;AAClD,yCAAyC;AAEzC,MAAM,UAAU,GAAG,CAAC,WAAW,EAAE,UAAU,EAAE,OAAO,EAAE,YAAY,CAAU,CAAA;AAG5E,MAAM,SAAS,GAAG,CAChB,SAA2B,EAC3B,IAAY,EACZ,QAA0B,EAC1B,QAAQ,GAAG,IAAI,EACf,IAAa,EACb,OAAgB,EAChB,EAAE,CACF,IAAA,uBAAY,EACV,OAAO,EACP,EAAE,EACF,SAAS,EACT,IAAI,EACJ,QAAQ,EACR,IAAI,aAAJ,IAAI,cAAJ,IAAI,GAAI,IAAA,sBAAW,EAAC,qBAAqB,EAAE,EAAE,EAAE,CAAC,WAAW,EAAE,gBAAgB,CAAC,CAAC,EAC/E,OAAO,aAAP,OAAO,cAAP,OAAO,GACL,IAAA,sBAAW,EACT,wBAAwB,EACxB;IACE,QAAQ,EAAE,SAAS,KAAK,OAAO,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,iDAAiD;IACxF,SAAS;IACT,KAAK,EAAE,QAAQ,CAAC,CAAC,CAAC,qBAAqB,CAAC,CAAC,CAAC,EAAE;IAC5C,SAAS,EAAE,QAAQ,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,EAAE;CACrC,EACD,CAAC,QAAQ,EAAE,gBAAgB,CAAC,CAC7B,EACH,QAAQ,CACT,CAAA;AAEH,MAAM,qBAAqB,GAAG;;;;;;;EAO5B,CAAA;AAEF,MAAM,wBAAwB,GAAG;;;;;;;SAOxB,CAAA;AAET,MAAM,uBAAuB,GAAG,mFAAmF,CAAA;AAEnH,MAAM,0BAA0B,GAAG;oFACiD,CAAA;AAEpF,MAAM,SAAS,GAAG,SAAS,CAAC,WAAW,EAAE,gBAAgB,EAAE,MAAM,CAAC,CAAA;AAElE,MAAM,QAAQ,GAAG,SAAS,CAAC,UAAU,EAAE,kBAAkB,EAAE,OAAO,CAAC,CAAA;AAEnE,MAAM,KAAK,GAAG,SAAS,CAAC,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,KAAK,CAAC,CAAA;AAEzD,MAAM,UAAU,GAAG,SAAS,CAC1B,YAAY,EACZ,gBAAgB,EAChB,MAAM,EACN,IAAI,EACJ,IAAA,sBAAW,EAAC,uBAAuB,EAAE,EAAE,EAAE,CAAC,WAAW,CAAC,CAAC,EACvD,IAAA,sBAAW,EAAC,0BAA0B,EAAE,EAAE,EAAE,CAAC,QAAQ,EAAE,gBAAgB,CAAC,CAAC,CAC1E,CAAA;AAEY,QAAA,OAAO,GAAG,EAAE,SAAS,EAAE,QAAQ,EAAE,KAAK,EAAE,UAAU,EAAE,CAAA"}
@@ -0,0 +1,2 @@
1
+ export declare const makeResolver: (root: "Query" | "Mutation", imports: string, operation: string, type: string, nullable: "true" | "false", args: string, resolve: string, isPrisma?: boolean) => string;
2
+ export declare const resolverTemplate = "#{inputsImporter}#{imports}#{resolverImports}#{builderCalculatedImport}\nimport { define#{root}, define#{root}Function, define#{root}#{object} } from '../../utils';\n\nexport const #{operation}#{modelName}#{root}Args = builder.args((t) => (#{args}))\n\nexport const #{operation}#{modelName}#{root}Object = define#{root}Function((t) =>\n define#{root}#{object}({\n type: #{type},\n nullable: #{nullable},\n args: #{operation}#{modelName}#{root}Args,\n resolve: #{resolve},\n }),\n);\n\nexport const #{operation}#{modelName}#{root} = define#{root}((t) => ({\n #{operation}#{modelName}: t.#{field}(#{operation}#{modelName}#{root}Object(t)),\n}));\n";
@@ -0,0 +1,35 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.resolverTemplate = exports.makeResolver = void 0;
4
+ const template_1 = require("../../utils/template");
5
+ const makeResolver = (root, imports, operation, type, nullable, args, resolve, isPrisma = true) => (0, template_1.useTemplate)(exports.resolverTemplate, {
6
+ root,
7
+ object: isPrisma ? 'PrismaObject' : 'Object',
8
+ imports,
9
+ operation,
10
+ type,
11
+ nullable,
12
+ args,
13
+ resolve,
14
+ field: isPrisma ? 'prismaField' : 'field',
15
+ }, ['modelName', 'inputsImporter', 'resolverImports', 'builderCalculatedImport']);
16
+ exports.makeResolver = makeResolver;
17
+ exports.resolverTemplate = `#{inputsImporter}#{imports}#{resolverImports}#{builderCalculatedImport}
18
+ import { define#{root}, define#{root}Function, define#{root}#{object} } from '../../utils';
19
+
20
+ export const #{operation}#{modelName}#{root}Args = builder.args((t) => (#{args}))
21
+
22
+ export const #{operation}#{modelName}#{root}Object = define#{root}Function((t) =>
23
+ define#{root}#{object}({
24
+ type: #{type},
25
+ nullable: #{nullable},
26
+ args: #{operation}#{modelName}#{root}Args,
27
+ resolve: #{resolve},
28
+ }),
29
+ );
30
+
31
+ export const #{operation}#{modelName}#{root} = define#{root}((t) => ({
32
+ #{operation}#{modelName}: t.#{field}(#{operation}#{modelName}#{root}Object(t)),
33
+ }));
34
+ `;
35
+ //# sourceMappingURL=resolver.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"resolver.js","sourceRoot":"","sources":["../../../../src/crudGenerator/templates/resolver.ts"],"names":[],"mappings":";;;AAAA,mDAAkD;AAE3C,MAAM,YAAY,GAAG,CAC1B,IAA0B,EAC1B,OAAe,EACf,SAAiB,EACjB,IAAY,EACZ,QAA0B,EAC1B,IAAY,EACZ,OAAe,EACf,QAAQ,GAAG,IAAI,EACf,EAAE,CACF,IAAA,sBAAW,EACT,wBAAgB,EAChB;IACE,IAAI;IACJ,MAAM,EAAE,QAAQ,CAAC,CAAC,CAAC,cAAc,CAAC,CAAC,CAAC,QAAQ;IAC5C,OAAO;IACP,SAAS;IACT,IAAI;IACJ,QAAQ;IACR,IAAI;IACJ,OAAO;IACP,KAAK,EAAE,QAAQ,CAAC,CAAC,CAAC,aAAa,CAAC,CAAC,CAAC,OAAO;CAC1C,EACD,CAAC,WAAW,EAAE,gBAAgB,EAAE,iBAAiB,EAAE,yBAAyB,CAAC,CAC9E,CAAA;AAxBU,QAAA,YAAY,gBAwBtB;AAEU,QAAA,gBAAgB,GAAG;;;;;;;;;;;;;;;;;CAiB/B,CAAA"}
@@ -0,0 +1,20 @@
1
+ export declare const objectsTemplate = "#{prismaImporter}#{crudExportRoot}#{builderCalculatedImport}\n\nexport const BatchPayload = builder.objectType(builder.objectRef<Prisma.BatchPayload>('BatchPayload'), {\n description: 'Batch payloads from prisma.',\n fields: (t) => ({\n count: t.exposeInt('count', { description: 'Prisma Batch Payload', nullable: false }),\n }),\n});\n\nexport const modelNames = [\n #{modelNames}\n] as const;\n\nexport type Model = typeof modelNames[number];\n";
2
+ export declare const utilsTemplate = "import {\n FieldOptionsFromKind,\n InputFieldMap,\n InterfaceParam,\n MutationFieldBuilder,\n MutationFieldsShape,\n ObjectRef,\n QueryFieldBuilder,\n QueryFieldsShape,\n TypeParam,\n} from '@pothos/core';\nimport {\n PrismaFieldOptions,\n PrismaObjectTypeOptions,\n RelatedFieldOptions,\n} from '@pothos/plugin-prisma';#{builderCalculatedImport}\n\ntype Types = typeof builder extends PothosSchemaTypes.SchemaBuilder<infer T> ? T : unknown;\n\nexport const defineQuery = <Q extends QueryFieldsShape<Types>>(q: Q) => q;\n\nexport const defineQueryFunction = <Obj>(\n func: (t: QueryFieldBuilder<Types, Types['Root']>) => Obj,\n) => func;\n\nexport const defineQueryObject = <\n Type extends TypeParam<Types>,\n Nullable extends boolean,\n Args extends InputFieldMap,\n>(\n obj: FieldOptionsFromKind<Types, Types['Root'], Type, Nullable, Args, 'Query', Types, unknown>,\n) => obj as { type: Type; nullable: Nullable; args: Args; resolve: typeof obj['resolve'] };\n\nexport const defineQueryPrismaObject = <\n Type extends keyof Types['PrismaTypes'] | [keyof Types['PrismaTypes']],\n Model extends Types['PrismaTypes'][Type extends [unknown] ? Type[0] : Type],\n Args extends InputFieldMap,\n Nullable extends boolean,\n>(\n def: PrismaFieldOptions<\n Types,\n Types['Root'],\n Type,\n Model,\n Type extends [unknown] ? [ObjectRef<Types, Model['Shape']>] : ObjectRef<Types, Model['Shape']>,\n Args,\n Nullable,\n unknown,\n unknown,\n 'Query'\n >,\n) => def as { type: Type; nullable: Nullable; args: Args; resolve: typeof def['resolve'] };\n\nexport const defineMutation = <M extends MutationFieldsShape<Types>>(m: M) => m;\n\nexport const defineMutationFunction = <Obj>(\n func: (t: MutationFieldBuilder<Types, Types['Root']>) => Obj,\n) => func;\n\nexport const defineMutationObject = <\n Type extends TypeParam<Types>,\n Nullable extends boolean,\n Args extends InputFieldMap,\n>(\n obj: FieldOptionsFromKind<Types, Types['Root'], Type, Nullable, Args, 'Mutation', Types, unknown>,\n) => obj as { type: Type; nullable: Nullable; args: Args; resolve: typeof obj['resolve'] };\n\nexport const defineMutationPrismaObject = <\n Type extends keyof Types['PrismaTypes'] | [keyof Types['PrismaTypes']],\n Model extends Types['PrismaTypes'][Type extends [unknown] ? Type[0] : Type],\n Args extends InputFieldMap,\n Nullable extends boolean,\n>(\n obj: PrismaFieldOptions<\n Types,\n Types['Root'],\n Type,\n Model,\n Type extends [unknown] ? [ObjectRef<Types, Model['Shape']>] : ObjectRef<Types, Model['Shape']>,\n Args,\n Nullable,\n unknown,\n unknown,\n 'Mutation'\n >,\n) => obj as { type: Type; nullable: Nullable; args: Args; resolve: typeof obj['resolve'] };\n\nexport const defineFieldObject = <\n Name extends keyof Types['PrismaTypes'],\n Type extends TypeParam<Types>,\n Nullable extends boolean,\n Args extends InputFieldMap,\n>(\n _: Name,\n obj: FieldOptionsFromKind<\n Types,\n Types['PrismaTypes'][Name]['Shape'],\n Type,\n Nullable,\n Args,\n 'Object',\n unknown,\n unknown\n >,\n) =>\n obj as { type: Type; nullable: Nullable; description?: string; resolve: typeof obj['resolve'] };\n\nexport const defineRelationObject = <\n ModelName extends keyof Types['PrismaTypes'],\n RelationName extends keyof Types['PrismaTypes'][ModelName]['Relations'],\n Nullable extends boolean,\n Args extends InputFieldMap,\n>(\n _: ModelName,\n __: RelationName,\n obj: RelatedFieldOptions<\n Types,\n Types['PrismaTypes'][ModelName],\n RelationName,\n Nullable,\n Args,\n unknown,\n Types['PrismaTypes'][ModelName]['Shape']\n >,\n) =>\n obj as {\n description: string | undefined;\n nullable: Nullable;\n args: Args;\n query: typeof obj['query'];\n };\n\nexport const defineRelationFunction = <ModelName extends keyof Types['PrismaTypes'], O>(\n _: ModelName,\n func: (\n t: PothosSchemaTypes.PrismaObjectFieldBuilder<\n Types,\n Types['PrismaTypes'][ModelName],\n Types['PrismaTypes'][ModelName]['Shape']\n >,\n ) => O,\n) => func;\n\nexport const definePrismaObject = <\n Name extends keyof Types['PrismaTypes'],\n Obj extends PrismaObjectTypeOptions<\n Types,\n Types['PrismaTypes'][Name],\n InterfaceParam<Types>[],\n unknown,\n unknown,\n Types['PrismaTypes'][Name]['Shape']\n >,\n>(\n _: Name,\n obj: Obj,\n) => obj;\n";
3
+ /**
4
+ User: {
5
+ Object: User.UserObject,
6
+ queries: {},
7
+ mutations: {},
8
+ },
9
+ Post: {
10
+ Object: Post.PostObject,
11
+ queries: {
12
+ findFirst: Post.findFirstPostQuery,
13
+ count: Post.countPostQuery,
14
+ },
15
+ mutations: {
16
+ createOne: Post.createOnePostMutation,
17
+ },
18
+ },
19
+ */
20
+ export declare const autoCrudTemplate = "#{imports}#{builderCalculatedImport}\nimport * as Objects from './objects';\n\ntype Model = Objects.Model;\n\nexport const Cruds: Record<\n Objects.Model,\n {\n Object: any;\n queries: Record<string, Function>;\n mutations: Record<string, Function>;\n }\n> = {\n#{modelsGenerated}\n};\n\nconst crudEntries = Object.entries(Cruds);\n\ntype ResolverType = \"Query\" | \"Mutation\";\nfunction generateResolversByType(type: ResolverType, opts?: CrudOptions) {\n return crudEntries\n .filter(([modelName]) => includeModel(modelName, opts))\n .map(([modelName, config]) => {\n const resolverEntries = Object.entries(config[type === \"Query\" ? \"queries\" : \"mutations\"]);\n\n return resolverEntries.map(([operationName, resolverObjectDefiner]) => {\n const resolverName = operationName + modelName;\n const isntPrismaFieldList = [\"count\", \"deleteMany\", \"updateMany\"];\n const isPrismaField = !isntPrismaFieldList.includes(operationName);\n\n const getFields = (t: any) => {\n const field = resolverObjectDefiner(t);\n const handledField = opts?.handleResolver\n ? opts.handleResolver({\n field,\n modelName: modelName as Model,\n operationName,\n resolverName,\n t,\n isPrismaField,\n type,\n })\n : field;\n\n return {\n [resolverName]: isPrismaField\n ? t.prismaField(handledField)\n : t.field(handledField),\n }\n }\n\n return type === \"Query\"\n ? builder.queryFields((t) => getFields(t))\n : builder.mutationFields((t) => getFields(t));\n });\n });\n}\n\nexport function generateAllObjects(opts?: CrudOptions) {\n return crudEntries\n .filter(([md]) => includeModel(md, opts))\n .map(([modelName, { Object }]) => {\n return builder.prismaObject(modelName as Model, Object); // Objects is all imports\n });\n}\n\nexport function generateAllQueries(opts?: CrudOptions) {\n generateResolversByType(\"Query\", opts);\n}\n\nexport function generateAllMutations(opts?: CrudOptions) {\n generateResolversByType(\"Mutation\", opts);\n}\n\nexport function generateAllResolvers(opts?: CrudOptions) {\n generateResolversByType(\"Mutation\", opts);\n generateResolversByType(\"Query\", opts);\n}\n\ntype CrudOptions = {\n include?: Model[];\n exclude?: Model[];\n /**\n * Caution: This is not type safe\n * Wrap all queries/mutations to override args, run extra code in resolve function (ie: throw errors, logs), apply plugins, etc.\n */\n handleResolver?: (props: {\n modelName: Model;\n field: any;\n operationName: string;\n resolverName: string;\n t: any;\n isPrismaField: boolean;\n type: ResolverType;\n }) => any;\n};\n\nconst includeModel = (model: string, opts?: CrudOptions): boolean => {\n if (!opts) return true;\n if (opts.include) return opts.include.includes(model as Model);\n if (opts.exclude) return !opts.exclude.includes(model as Model);\n return true;\n};\n\nexport function generateAllCrud(opts?: CrudOptions) {\n generateAllObjects(opts);\n generateAllQueries(opts);\n generateAllMutations(opts);\n}\n";
@@ -0,0 +1,305 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.autoCrudTemplate = exports.utilsTemplate = exports.objectsTemplate = void 0;
4
+ exports.objectsTemplate = `#{prismaImporter}#{crudExportRoot}#{builderCalculatedImport}
5
+
6
+ export const BatchPayload = builder.objectType(builder.objectRef<Prisma.BatchPayload>('BatchPayload'), {
7
+ description: 'Batch payloads from prisma.',
8
+ fields: (t) => ({
9
+ count: t.exposeInt('count', { description: 'Prisma Batch Payload', nullable: false }),
10
+ }),
11
+ });
12
+
13
+ export const modelNames = [
14
+ #{modelNames}
15
+ ] as const;
16
+
17
+ export type Model = typeof modelNames[number];
18
+ `;
19
+ exports.utilsTemplate = `import {
20
+ FieldOptionsFromKind,
21
+ InputFieldMap,
22
+ InterfaceParam,
23
+ MutationFieldBuilder,
24
+ MutationFieldsShape,
25
+ ObjectRef,
26
+ QueryFieldBuilder,
27
+ QueryFieldsShape,
28
+ TypeParam,
29
+ } from '@pothos/core';
30
+ import {
31
+ PrismaFieldOptions,
32
+ PrismaObjectTypeOptions,
33
+ RelatedFieldOptions,
34
+ } from '@pothos/plugin-prisma';#{builderCalculatedImport}
35
+
36
+ type Types = typeof builder extends PothosSchemaTypes.SchemaBuilder<infer T> ? T : unknown;
37
+
38
+ export const defineQuery = <Q extends QueryFieldsShape<Types>>(q: Q) => q;
39
+
40
+ export const defineQueryFunction = <Obj>(
41
+ func: (t: QueryFieldBuilder<Types, Types['Root']>) => Obj,
42
+ ) => func;
43
+
44
+ export const defineQueryObject = <
45
+ Type extends TypeParam<Types>,
46
+ Nullable extends boolean,
47
+ Args extends InputFieldMap,
48
+ >(
49
+ obj: FieldOptionsFromKind<Types, Types['Root'], Type, Nullable, Args, 'Query', Types, unknown>,
50
+ ) => obj as { type: Type; nullable: Nullable; args: Args; resolve: typeof obj['resolve'] };
51
+
52
+ export const defineQueryPrismaObject = <
53
+ Type extends keyof Types['PrismaTypes'] | [keyof Types['PrismaTypes']],
54
+ Model extends Types['PrismaTypes'][Type extends [unknown] ? Type[0] : Type],
55
+ Args extends InputFieldMap,
56
+ Nullable extends boolean,
57
+ >(
58
+ def: PrismaFieldOptions<
59
+ Types,
60
+ Types['Root'],
61
+ Type,
62
+ Model,
63
+ Type extends [unknown] ? [ObjectRef<Types, Model['Shape']>] : ObjectRef<Types, Model['Shape']>,
64
+ Args,
65
+ Nullable,
66
+ unknown,
67
+ unknown,
68
+ 'Query'
69
+ >,
70
+ ) => def as { type: Type; nullable: Nullable; args: Args; resolve: typeof def['resolve'] };
71
+
72
+ export const defineMutation = <M extends MutationFieldsShape<Types>>(m: M) => m;
73
+
74
+ export const defineMutationFunction = <Obj>(
75
+ func: (t: MutationFieldBuilder<Types, Types['Root']>) => Obj,
76
+ ) => func;
77
+
78
+ export const defineMutationObject = <
79
+ Type extends TypeParam<Types>,
80
+ Nullable extends boolean,
81
+ Args extends InputFieldMap,
82
+ >(
83
+ obj: FieldOptionsFromKind<Types, Types['Root'], Type, Nullable, Args, 'Mutation', Types, unknown>,
84
+ ) => obj as { type: Type; nullable: Nullable; args: Args; resolve: typeof obj['resolve'] };
85
+
86
+ export const defineMutationPrismaObject = <
87
+ Type extends keyof Types['PrismaTypes'] | [keyof Types['PrismaTypes']],
88
+ Model extends Types['PrismaTypes'][Type extends [unknown] ? Type[0] : Type],
89
+ Args extends InputFieldMap,
90
+ Nullable extends boolean,
91
+ >(
92
+ obj: PrismaFieldOptions<
93
+ Types,
94
+ Types['Root'],
95
+ Type,
96
+ Model,
97
+ Type extends [unknown] ? [ObjectRef<Types, Model['Shape']>] : ObjectRef<Types, Model['Shape']>,
98
+ Args,
99
+ Nullable,
100
+ unknown,
101
+ unknown,
102
+ 'Mutation'
103
+ >,
104
+ ) => obj as { type: Type; nullable: Nullable; args: Args; resolve: typeof obj['resolve'] };
105
+
106
+ export const defineFieldObject = <
107
+ Name extends keyof Types['PrismaTypes'],
108
+ Type extends TypeParam<Types>,
109
+ Nullable extends boolean,
110
+ Args extends InputFieldMap,
111
+ >(
112
+ _: Name,
113
+ obj: FieldOptionsFromKind<
114
+ Types,
115
+ Types['PrismaTypes'][Name]['Shape'],
116
+ Type,
117
+ Nullable,
118
+ Args,
119
+ 'Object',
120
+ unknown,
121
+ unknown
122
+ >,
123
+ ) =>
124
+ obj as { type: Type; nullable: Nullable; description?: string; resolve: typeof obj['resolve'] };
125
+
126
+ export const defineRelationObject = <
127
+ ModelName extends keyof Types['PrismaTypes'],
128
+ RelationName extends keyof Types['PrismaTypes'][ModelName]['Relations'],
129
+ Nullable extends boolean,
130
+ Args extends InputFieldMap,
131
+ >(
132
+ _: ModelName,
133
+ __: RelationName,
134
+ obj: RelatedFieldOptions<
135
+ Types,
136
+ Types['PrismaTypes'][ModelName],
137
+ RelationName,
138
+ Nullable,
139
+ Args,
140
+ unknown,
141
+ Types['PrismaTypes'][ModelName]['Shape']
142
+ >,
143
+ ) =>
144
+ obj as {
145
+ description: string | undefined;
146
+ nullable: Nullable;
147
+ args: Args;
148
+ query: typeof obj['query'];
149
+ };
150
+
151
+ export const defineRelationFunction = <ModelName extends keyof Types['PrismaTypes'], O>(
152
+ _: ModelName,
153
+ func: (
154
+ t: PothosSchemaTypes.PrismaObjectFieldBuilder<
155
+ Types,
156
+ Types['PrismaTypes'][ModelName],
157
+ Types['PrismaTypes'][ModelName]['Shape']
158
+ >,
159
+ ) => O,
160
+ ) => func;
161
+
162
+ export const definePrismaObject = <
163
+ Name extends keyof Types['PrismaTypes'],
164
+ Obj extends PrismaObjectTypeOptions<
165
+ Types,
166
+ Types['PrismaTypes'][Name],
167
+ InterfaceParam<Types>[],
168
+ unknown,
169
+ unknown,
170
+ Types['PrismaTypes'][Name]['Shape']
171
+ >,
172
+ >(
173
+ _: Name,
174
+ obj: Obj,
175
+ ) => obj;
176
+ `;
177
+ // TODO: Refactor getParams to link model with object base, and remove any
178
+ /**
179
+ User: {
180
+ Object: User.UserObject,
181
+ queries: {},
182
+ mutations: {},
183
+ },
184
+ Post: {
185
+ Object: Post.PostObject,
186
+ queries: {
187
+ findFirst: Post.findFirstPostQuery,
188
+ count: Post.countPostQuery,
189
+ },
190
+ mutations: {
191
+ createOne: Post.createOnePostMutation,
192
+ },
193
+ },
194
+ */
195
+ exports.autoCrudTemplate = `#{imports}#{builderCalculatedImport}
196
+ import * as Objects from './objects';
197
+
198
+ type Model = Objects.Model;
199
+
200
+ export const Cruds: Record<
201
+ Objects.Model,
202
+ {
203
+ Object: any;
204
+ queries: Record<string, Function>;
205
+ mutations: Record<string, Function>;
206
+ }
207
+ > = {
208
+ #{modelsGenerated}
209
+ };
210
+
211
+ const crudEntries = Object.entries(Cruds);
212
+
213
+ type ResolverType = "Query" | "Mutation";
214
+ function generateResolversByType(type: ResolverType, opts?: CrudOptions) {
215
+ return crudEntries
216
+ .filter(([modelName]) => includeModel(modelName, opts))
217
+ .map(([modelName, config]) => {
218
+ const resolverEntries = Object.entries(config[type === "Query" ? "queries" : "mutations"]);
219
+
220
+ return resolverEntries.map(([operationName, resolverObjectDefiner]) => {
221
+ const resolverName = operationName + modelName;
222
+ const isntPrismaFieldList = ["count", "deleteMany", "updateMany"];
223
+ const isPrismaField = !isntPrismaFieldList.includes(operationName);
224
+
225
+ const getFields = (t: any) => {
226
+ const field = resolverObjectDefiner(t);
227
+ const handledField = opts?.handleResolver
228
+ ? opts.handleResolver({
229
+ field,
230
+ modelName: modelName as Model,
231
+ operationName,
232
+ resolverName,
233
+ t,
234
+ isPrismaField,
235
+ type,
236
+ })
237
+ : field;
238
+
239
+ return {
240
+ [resolverName]: isPrismaField
241
+ ? t.prismaField(handledField)
242
+ : t.field(handledField),
243
+ }
244
+ }
245
+
246
+ return type === "Query"
247
+ ? builder.queryFields((t) => getFields(t))
248
+ : builder.mutationFields((t) => getFields(t));
249
+ });
250
+ });
251
+ }
252
+
253
+ export function generateAllObjects(opts?: CrudOptions) {
254
+ return crudEntries
255
+ .filter(([md]) => includeModel(md, opts))
256
+ .map(([modelName, { Object }]) => {
257
+ return builder.prismaObject(modelName as Model, Object); // Objects is all imports
258
+ });
259
+ }
260
+
261
+ export function generateAllQueries(opts?: CrudOptions) {
262
+ generateResolversByType("Query", opts);
263
+ }
264
+
265
+ export function generateAllMutations(opts?: CrudOptions) {
266
+ generateResolversByType("Mutation", opts);
267
+ }
268
+
269
+ export function generateAllResolvers(opts?: CrudOptions) {
270
+ generateResolversByType("Mutation", opts);
271
+ generateResolversByType("Query", opts);
272
+ }
273
+
274
+ type CrudOptions = {
275
+ include?: Model[];
276
+ exclude?: Model[];
277
+ /**
278
+ * Caution: This is not type safe
279
+ * Wrap all queries/mutations to override args, run extra code in resolve function (ie: throw errors, logs), apply plugins, etc.
280
+ */
281
+ handleResolver?: (props: {
282
+ modelName: Model;
283
+ field: any;
284
+ operationName: string;
285
+ resolverName: string;
286
+ t: any;
287
+ isPrismaField: boolean;
288
+ type: ResolverType;
289
+ }) => any;
290
+ };
291
+
292
+ const includeModel = (model: string, opts?: CrudOptions): boolean => {
293
+ if (!opts) return true;
294
+ if (opts.include) return opts.include.includes(model as Model);
295
+ if (opts.exclude) return !opts.exclude.includes(model as Model);
296
+ return true;
297
+ };
298
+
299
+ export function generateAllCrud(opts?: CrudOptions) {
300
+ generateAllObjects(opts);
301
+ generateAllQueries(opts);
302
+ generateAllMutations(opts);
303
+ }
304
+ `;
305
+ //# sourceMappingURL=root.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"root.js","sourceRoot":"","sources":["../../../../src/crudGenerator/templates/root.ts"],"names":[],"mappings":";;;AAAa,QAAA,eAAe,GAAG;;;;;;;;;;;;;;CAc9B,CAAA;AAEY,QAAA,aAAa,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CA6J5B,CAAA;AAED,0EAA0E;AAC1E;;;;;;;;;;;;;;;;GAgBG;AACU,QAAA,gBAAgB,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CA6G/B,CAAA"}
@@ -0,0 +1,10 @@
1
+ import { ConfigInternal } from '../../utils/config';
2
+ import { GeneratedResolver, writeIndex } from './parts';
3
+ import type { DMMF } from '@prisma/generator-helper';
4
+ /**
5
+ * @returns List of generated resolvers
6
+ */
7
+ export declare function generateModel(config: ConfigInternal, dmmf: DMMF.Document, modelName: string): Promise<{
8
+ resolvers: GeneratedResolver[];
9
+ index: Awaited<ReturnType<typeof writeIndex>>;
10
+ }>;
@@ -0,0 +1,20 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.generateModel = generateModel;
4
+ const mutation_1 = require("../templates/mutation");
5
+ const query_1 = require("../templates/query");
6
+ const parts_1 = require("./parts");
7
+ /**
8
+ * @returns List of generated resolvers
9
+ */
10
+ async function generateModel(config, dmmf, modelName) {
11
+ const model = dmmf.datamodel.models.find((m) => m.name === modelName);
12
+ if (!model)
13
+ return { index: [], resolvers: [] };
14
+ await (0, parts_1.writeObject)(config, model);
15
+ const queries = await (0, parts_1.writeResolvers)(config, model, 'queries', query_1.queries);
16
+ const mutations = await (0, parts_1.writeResolvers)(config, model, 'mutations', mutation_1.mutations);
17
+ const index = await (0, parts_1.writeIndex)(config, model, { queries, mutations });
18
+ return { resolvers: [...queries, ...mutations], index };
19
+ }
20
+ //# sourceMappingURL=generator.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"generator.js","sourceRoot":"","sources":["../../../../src/crudGenerator/utils/generator.ts"],"names":[],"mappings":";;AASA,sCAcC;AAtBD,oDAAsE;AACtE,8CAA8D;AAC9D,mCAAoF;AAGpF;;GAEG;AACI,KAAK,UAAU,aAAa,CACjC,MAAsB,EACtB,IAAmB,EACnB,SAAiB;IAEjB,MAAM,KAAK,GAAG,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,KAAK,SAAS,CAAC,CAAA;IACrE,IAAI,CAAC,KAAK;QAAE,OAAO,EAAE,KAAK,EAAE,EAAE,EAAE,SAAS,EAAE,EAAE,EAAE,CAAA;IAE/C,MAAM,IAAA,mBAAW,EAAC,MAAM,EAAE,KAAK,CAAC,CAAA;IAChC,MAAM,OAAO,GAAG,MAAM,IAAA,sBAAc,EAAC,MAAM,EAAE,KAAK,EAAE,SAAS,EAAE,eAAc,CAAC,CAAA;IAC9E,MAAM,SAAS,GAAG,MAAM,IAAA,sBAAc,EAAC,MAAM,EAAE,KAAK,EAAE,WAAW,EAAE,oBAAiB,CAAC,CAAA;IACrF,MAAM,KAAK,GAAG,MAAM,IAAA,kBAAU,EAAC,MAAM,EAAE,KAAK,EAAE,EAAE,OAAO,EAAE,SAAS,EAAE,CAAC,CAAA;IAErE,OAAO,EAAE,SAAS,EAAE,CAAC,GAAG,OAAO,EAAE,GAAG,SAAS,CAAC,EAAE,KAAK,EAAE,CAAA;AACzD,CAAC"}
@@ -0,0 +1,7 @@
1
+ import { ConfigInternal } from '../../utils/config';
2
+ import type { DMMF } from '@prisma/generator-helper';
3
+ export declare const cleanifyDocumentation: (str?: string) => string | undefined;
4
+ export declare const getObjectFieldsString: (modelName: string, fields: readonly DMMF.Field[], config: ConfigInternal) => {
5
+ fields: string[];
6
+ exportFields: string[];
7
+ };