-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(contact-server-graphql): Added full Prisma GraphQL schema code g…
…enerators
- Loading branch information
1 parent
3135949
commit e924832
Showing
25 changed files
with
328 additions
and
151 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,63 @@ | ||
/** @type {import('prisma-generator-pothos-codegen').Config} */ | ||
module.exports = { | ||
inputs: { | ||
// builderImporter: "import { builder } from '../builder';", | ||
prismaImporter: `import { prisma } from '../prisma';`, | ||
outputFilePath: "./src/__generated__/crud/inputs.ts", | ||
}, | ||
crud: { | ||
outputDir: "./src/__generated__/crud", | ||
prismaCaller: "prisma", | ||
disabled: false, | ||
generateAutocrud: true, | ||
inputsImporter: "import * as Inputs from '../inputs'", | ||
builderImporter: "import { builder } from '../../builder';", | ||
inputsImporter: "import * as Inputs from '../inputs';", | ||
deleteOutputDirBeforeGenerate: true, | ||
exportEverythingInObjectsDotTs: true, | ||
prismaImporter: `import { prisma } from '../prisma';`, | ||
prismaCaller: "client", | ||
resolverImports: `\nimport { client } from '../../builder';`, | ||
prismaImporter: `import { Prisma } from '@prisma/client/contact';`, | ||
resolverImports: `\nimport { prisma } from '../../../../client';`, | ||
replacer(generated, position) { | ||
// replacer(generated, position) { | ||
// return `// THIS CONTENT WAS INSERTED AT REPLACE. THE POSITION IS ${position}\n${generated}` | ||
// }, | ||
|
||
//export const ContactAttachmentObject = definePrismaObject('ContactAttachment', | ||
generated = generated.replace( | ||
"type Types = typeof builder extends PothosSchemaTypes.SchemaBuilder<infer T> ? T : unknown;", | ||
"export type Types = typeof builder extends PothosSchemaTypes.SchemaBuilder<infer T> ? T : unknown;" | ||
); | ||
|
||
const regex = /export const (\w+)Object = definePrismaObject\('(\w+)',/g; | ||
const match = regex.exec(generated); | ||
if (match && match.length > 1) { | ||
generated = generated.replace( | ||
`export const ${match[1]}Object = definePrismaObject('${match[1]}'`, | ||
`import { InterfaceParam } from "@pothos/core"; | ||
import { PrismaObjectTypeOptions } from "@pothos/plugin-prisma"; | ||
import { Types } from "../utils"; | ||
export const ${match[1]}Object: PrismaObjectTypeOptions< | ||
Types, | ||
Types["PrismaTypes"]["${match[1]}"], | ||
InterfaceParam<Types>[], | ||
any, | ||
Types["PrismaTypes"]["${match[1]}"]["Include"], | ||
Types["PrismaTypes"]["${match[1]}"]["Select"], | ||
Types["PrismaTypes"]["${match[1]}"]["Shape"] | ||
> = definePrismaObject("${match[1]}"` | ||
); | ||
} | ||
|
||
return generated | ||
.replace( | ||
"resolve: async (query, _root, args, _context, _info)", | ||
"resolve: async (query, _root, args: any, _context, _info)" | ||
) | ||
.replace( | ||
"resolve: async (_root, args, _context, _info)", | ||
"resolve: async (_root, args: any, _context, _info)" | ||
) | ||
.replace("query: undefined,", "") | ||
.replace("query: (args) =>", "query: (args: any) =>"); | ||
}, | ||
}, | ||
global: { | ||
builderImporter: `import { builder } from '../../builder';`, | ||
inputs: { | ||
builderImporter: "import { builder } from '../../builder';", | ||
prismaImporter: `import { Prisma } from '@prisma/client/contact';`, | ||
outputFilePath: "./src/__generated__/crud/inputs.ts", | ||
}, | ||
global: {}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,33 @@ | ||
/* eslint-disable @typescript-eslint/no-explicit-any */ | ||
import { createSchemaBuilder } from "@open-system/core-server-graphql"; | ||
import { PrismaClient } from "./__generated__/prisma"; | ||
import { Prisma } from "@prisma/client/contact"; | ||
import PrismaTypes from "./__generated__/types"; | ||
import { prisma } from "./client"; | ||
import { ContactApiServerContext } from "./types"; | ||
|
||
export const client = new PrismaClient({ | ||
log: ["error", "info", "query", "warn"], | ||
}); | ||
|
||
export const builder = createSchemaBuilder< | ||
PrismaTypes, | ||
ContactApiServerContext | ||
>(client); | ||
>(prisma, Prisma.dmmf); | ||
|
||
/*export const builder = new SchemaBuilder<{ | ||
Context: any; | ||
PrismaTypes: PrismaTypes; | ||
Scalars: any; | ||
}>({ | ||
plugins: [PrismaPlugin], | ||
prisma: { | ||
client: prisma, | ||
}, | ||
notStrict: | ||
"Pothos may not work correctly when strict mode is not enabled in tsconfig.json", | ||
relayOptions: { | ||
clientMutationId: "optional", | ||
cursorType: "ID", | ||
idFieldName: "id", | ||
brandLoadedObjects: true, | ||
nodesOnConnection: true, | ||
encodeGlobalID, | ||
decodeGlobalID, | ||
}, | ||
});*/ |
Oops, something went wrong.