Skip to content

Commit

Permalink
Rename db.prismaPath to db.prismaClientPath (#8323)
Browse files Browse the repository at this point in the history
Co-authored-by: Daniel Cousens <dcousens@users.noreply.github.com>
  • Loading branch information
dcousens and dcousens committed Feb 19, 2023
1 parent d33bb47 commit 36b1e2d
Show file tree
Hide file tree
Showing 14 changed files with 39 additions and 31 deletions.
2 changes: 1 addition & 1 deletion .changeset/depend-on-me.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
'@keystone-6/core': major
---

Removes assumptions about `@prisma/client` output location, with a new `db.prismaPath` configuration option to set where to import the Prisma client from
Removes assumptions about `@prisma/client` output location, with a new `db.prismaClientPath` configuration option to set where to import the Prisma client from
2 changes: 1 addition & 1 deletion examples/example-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@
// still use node_modules/... to skip the painful experience that is jest/babel
// transforms
export const fixPrismaPath = {
prismaPath: 'node_modules/.myprisma/client',
prismaClientPath: 'node_modules/.myprisma/client',
};
6 changes: 4 additions & 2 deletions packages/core/src/artifacts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export async function getCommittedArtifacts(config: KeystoneConfig, graphQLSchem
const lists = initialiseLists(config);
const prismaSchema = printPrismaSchema(
lists,
config.db.prismaPath,
config.db.prismaClientPath,
config.db.provider,
config.db.prismaPreviewFeatures,
config.db.additionalPrismaDatasourceProperties,
Expand Down Expand Up @@ -83,7 +83,9 @@ export function getSystemPaths(cwd: string, config: KeystoneConfig) {
config: getBuiltKeystoneConfigurationPath(cwd),
admin: path.join(cwd, '.keystone/admin'),
keystone: path.join(cwd, 'node_modules/.keystone'),
prisma: config.db.prismaPath ? path.join(cwd, config.db.prismaPath) : '@prisma/client',
prisma: config.db.prismaClientPath
? path.join(cwd, config.db.prismaClientPath)
: '@prisma/client',
schema: {
// types: // TODO
prisma: path.join(cwd, 'schema.prisma'),
Expand Down
38 changes: 22 additions & 16 deletions packages/core/src/lib/schema-type-printer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -88,29 +88,29 @@ function printInputTypesFromSchema(schema: GraphQLSchema, scalars: Record<string
}

function printInterimFieldType({
prismaPath,
prismaClientPath,
listKey,
fieldKey,
prismaKey,
operation,
}: {
prismaPath: string;
prismaClientPath: string;
listKey: string;
fieldKey: string;
prismaKey: string;
operation: string;
}) {
return ` ${fieldKey}?: import('${prismaPath}').Prisma.${listKey}${operation}Input["${prismaKey}"];`;
return ` ${fieldKey}?: import('${prismaClientPath}').Prisma.${listKey}${operation}Input["${prismaKey}"];`;
}

function printInterimMultiFieldType({
prismaPath,
prismaClientPath,
listKey,
fieldKey,
operation,
fields,
}: {
prismaPath: string;
prismaClientPath: string;
listKey: string;
fieldKey: string;
operation: string;
Expand All @@ -122,15 +122,21 @@ function printInterimMultiFieldType({
const prismaKey = `${fieldKey}_${subFieldKey}`;
return (
' ' +
printInterimFieldType({ prismaPath, listKey, fieldKey: subFieldKey, prismaKey, operation })
printInterimFieldType({
prismaClientPath,
listKey,
fieldKey: subFieldKey,
prismaKey,
operation,
})
);
}),
` };`,
].join('\n');
}

function printInterimType<L extends InitialisedList>(
prismaPath: string,
prismaClientPath: string,
list: L,
listKey: string,
typename: string,
Expand All @@ -142,7 +148,7 @@ function printInterimType<L extends InitialisedList>(
if (dbField.kind === 'none' || fieldKey === 'id') return ` ${fieldKey}?: undefined;`;
if (dbField.kind === 'multi') {
return printInterimMultiFieldType({
prismaPath,
prismaClientPath,
listKey,
fieldKey,
operation,
Expand All @@ -151,7 +157,7 @@ function printInterimType<L extends InitialisedList>(
}

return printInterimFieldType({
prismaPath,
prismaClientPath,
listKey,
fieldKey,
prismaKey: fieldKey,
Expand All @@ -163,7 +169,7 @@ function printInterimType<L extends InitialisedList>(
}

function printListTypeInfo<L extends InitialisedList>(
prismaPath: string,
prismaClientPath: string,
listKey: string,
list: L
) {
Expand All @@ -181,7 +187,7 @@ function printListTypeInfo<L extends InitialisedList>(
return [
`export type ${listKey} = import('@keystone-6/core').ListConfig<${listTypeInfoName}, any>;`,
`namespace ${listKey} {`,
` export type Item = import('${prismaPath}').${listKey};`,
` export type Item = import('${prismaClientPath}').${listKey};`,
` export type TypeInfo = {`,
` key: "${listKey}";`,
` isSingleton: ${list.isSingleton};`,
Expand Down Expand Up @@ -215,7 +221,7 @@ function printListTypeInfo<L extends InitialisedList>(
}

export function printGeneratedTypes(
prismaPath: string,
prismaClientPath: string,
graphQLSchema: GraphQLSchema,
lists: Record<string, InitialisedList>
) {
Expand All @@ -229,18 +235,18 @@ export function printGeneratedTypes(

if (list.graphql.isEnabled.create) {
interimCreateUpdateTypes.push(
printInterimType(prismaPath, list, listKey, gqlNames.createInputName, 'Create')
printInterimType(prismaClientPath, list, listKey, gqlNames.createInputName, 'Create')
);
}

if (list.graphql.isEnabled.update) {
interimCreateUpdateTypes.push(
printInterimType(prismaPath, list, listKey, gqlNames.updateInputName, 'Update')
printInterimType(prismaClientPath, list, listKey, gqlNames.updateInputName, 'Update')
);
}

listsTypeInfo.push(` readonly ${listKey}: ${listTypeInfoName};`);
listsNamespaces.push(printListTypeInfo(prismaPath, listKey, list));
listsNamespaces.push(printListTypeInfo(prismaClientPath, listKey, list));
}

return [
Expand All @@ -265,7 +271,7 @@ export function printGeneratedTypes(
` lists: {`,
...listsTypeInfo,
` };`,
` prisma: import('${prismaPath}').PrismaClient;`,
` prisma: import('${prismaClientPath}').PrismaClient;`,
`};`,
``,
// we need to reference the `TypeInfo` above in another type that is also called `TypeInfo`
Expand Down
4 changes: 2 additions & 2 deletions packages/core/src/scripts/run/dev.ts
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ export async function dev(
const initialisedLists = initialiseLists(config);
const originalPrismaSchema = printPrismaSchema(
initialisedLists,
config.db.prismaPath,
config.db.prismaClientPath,
config.db.provider,
config.db.prismaPreviewFeatures,
config.db.additionalPrismaDatasourceProperties,
Expand All @@ -179,7 +179,7 @@ export async function dev(
if (prisma) {
const newPrismaSchema = printPrismaSchema(
initialiseLists(newConfig),
config.db.prismaPath,
config.db.prismaClientPath,
newConfig.db.provider,
newConfig.db.prismaPreviewFeatures,
newConfig.db.additionalPrismaDatasourceProperties,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ export default config({
db: {
provider: 'sqlite',
url: 'file:./app.db',
prismaPath: 'node_modules/.testprisma/client',
prismaClientPath: 'node_modules/.testprisma/client',
},
ui: { isDisabled: true },
lists: {
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/scripts/tests/fixtures/log-node-env.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export default config({
db: {
provider: 'sqlite',
url: 'file:./app.db',
prismaPath: 'node_modules/.testprisma/client',
prismaClientPath: 'node_modules/.testprisma/client',
},
ui: { isDisabled: true },
lists: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ export default config({
provider: 'sqlite',
url: 'file:./app.db',
useMigrations: true,
prismaPath: 'node_modules/.testprisma/client',
prismaClientPath: 'node_modules/.testprisma/client',
},
ui: { isDisabled: true },
lists: {
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/scripts/tests/fixtures/no-fields.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ export default config({
db: {
provider: 'sqlite',
url: 'file:./app.db',
prismaPath: 'node_modules/.testprisma/client',
prismaClientPath: 'node_modules/.testprisma/client',
},
ui: { isDisabled: true },
lists: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ export default config({
provider: 'sqlite',
url: 'file:./app.db',
useMigrations: true,
prismaPath: 'node_modules/.testprisma/client',
prismaClientPath: 'node_modules/.testprisma/client',
},
ui: { isDisabled: true },
lists: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ export default config({
provider: 'sqlite',
url: 'file:./app.db',
useMigrations: true,
prismaPath: 'node_modules/.testprisma/client',
prismaClientPath: 'node_modules/.testprisma/client',
},
ui: { isDisabled: true },
lists: {
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/scripts/tests/fixtures/with-ts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export default config({
db: {
provider: 'sqlite',
url: 'file:./app.db',
prismaPath: 'node_modules/.testprisma/client',
prismaClientPath: 'node_modules/.testprisma/client',
},
lists: {
Todo: list({
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/types/config/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ export type DatabaseConfig<TypeInfo extends BaseKeystoneTypeInfo> = {
/** @deprecated use extendPrismaSchema */
additionalPrismaDatasourceProperties?: { [key: string]: string };

prismaPath?: string;
prismaClientPath?: string;
extendPrismaSchema?: (schema: string) => string;
};

Expand Down
2 changes: 1 addition & 1 deletion tests/sandbox/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export const localStorageConfig: Record<string, StorageConfig> = {
// still use node_modules/... to skip the painful experience that is jest/babel
// transforms
export const fixPrismaPath = {
prismaPath: 'node_modules/.testprisma/client',
prismaClientPath: 'node_modules/.testprisma/client',
};

export const dbConfig: DatabaseConfig<BaseKeystoneTypeInfo> = {
Expand Down

0 comments on commit 36b1e2d

Please sign in to comment.