Skip to content

Commit

Permalink
feat(redwood): redwood v7 support
Browse files Browse the repository at this point in the history
  • Loading branch information
ymc9 committed Jul 27, 2024
1 parent 5b437d9 commit 57af81d
Show file tree
Hide file tree
Showing 5 changed files with 253 additions and 274 deletions.
7 changes: 4 additions & 3 deletions packages/misc/redwood/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,17 +39,18 @@
"homepage": "https://zenstack.dev",
"license": "MIT",
"dependencies": {
"@redwoodjs/cli-helpers": "^7.7.3",
"@zenstackhq/runtime": "workspace:*",
"colors": "1.4.0",
"ts-morph": "^16.0.0",
"@redwoodjs/cli-helpers": "^6.6.0",
"execa": "^5.0.0",
"listr2": "^6.0.0",
"semver": "^7.5.2",
"terminal-link": "^2.0.0",
"ts-morph": "^16.0.0",
"yargs": "^17.7.2"
},
"devDependencies": {
"@redwoodjs/graphql-server": "^6.6.0",
"@redwoodjs/graphql-server": "^7.7.3",
"@types/yargs": "^17.0.32",
"graphql-yoga": "^5.0.2"
}
Expand Down
13 changes: 10 additions & 3 deletions packages/misc/redwood/src/commands/setup.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import { getPaths, updateTomlConfig } from '@redwoodjs/cli-helpers';
import { getInstalledRedwoodVersion, getPaths, updateTomlConfig } from '@redwoodjs/cli-helpers';
import colors from 'colors';
import execa from 'execa';
import fs from 'fs';
import { Listr, ListrTask } from 'listr2';
import path from 'path';
import semver from 'semver';
import terminalLink from 'terminal-link';
import { Project, SyntaxKind, type PropertyAssignment } from 'ts-morph';
import type { CommandModule } from 'yargs';
Expand Down Expand Up @@ -144,11 +145,17 @@ function installGraphQLPlugin() {
if (graphQlSourcePath.endsWith('.ts')) {
const typeDefPath = path.join(getPaths().api.src, 'zenstack.d.ts');
if (!fs.existsSync(typeDefPath)) {
const rwVersion: string = getInstalledRedwoodVersion();
const contextModule =
rwVersion && semver.lt(rwVersion, '7.0.0')
? '@redwoodjs/graphql-server' // pre v7
: '@redwoodjs/context'; // v7+

const typeDefSourceFile = project.createSourceFile(
typeDefPath,
`import type { PrismaClient } from '@prisma/client'
`import type { PrismaClient } from '@zenstackhq/runtime'
declare module '@redwoodjs/graphql-server' {
declare module '${contextModule}' {
interface GlobalContext {
db: PrismaClient
}
Expand Down
2 changes: 1 addition & 1 deletion packages/runtime/res/enhance.d.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export { auth, enhance } from '.zenstack/enhance';
export { auth, enhance, type PrismaClient } from '.zenstack/enhance';
4 changes: 3 additions & 1 deletion packages/schema/src/plugins/enhancer/enhance/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -127,8 +127,9 @@ ${
}

private createSimplePrismaImports(prismaImport: string) {
return `import { Prisma } from '${prismaImport}';
return `import { Prisma, type PrismaClient } from '${prismaImport}';
import type * as _P from '${prismaImport}';
export type { PrismaClient };
`;
}

Expand All @@ -152,6 +153,7 @@ export function enhance<DbClient extends object>(prisma: DbClient, context?: Enh
import type { InternalArgs, DynamicClientExtensionThis } from '${prismaImport}/runtime/library';
import type * as _P from '${logicalPrismaClientDir}/index-fixed';
import type { Prisma, PrismaClient } from '${logicalPrismaClientDir}/index-fixed';
export type { PrismaClient };
`;
}

Expand Down
Loading

0 comments on commit 57af81d

Please sign in to comment.