Skip to content

Commit 3831350

Browse files
authored
feat(redwood): redwood v7 support (#1617)
1 parent 5b437d9 commit 3831350

File tree

5 files changed

+260
-276
lines changed

5 files changed

+260
-276
lines changed

packages/misc/redwood/package.json

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,17 +39,18 @@
3939
"homepage": "https://zenstack.dev",
4040
"license": "MIT",
4141
"dependencies": {
42+
"@redwoodjs/cli-helpers": "^7.7.3",
4243
"@zenstackhq/runtime": "workspace:*",
4344
"colors": "1.4.0",
44-
"ts-morph": "^16.0.0",
45-
"@redwoodjs/cli-helpers": "^6.6.0",
4645
"execa": "^5.0.0",
4746
"listr2": "^6.0.0",
47+
"semver": "^7.5.2",
4848
"terminal-link": "^2.0.0",
49+
"ts-morph": "^16.0.0",
4950
"yargs": "^17.7.2"
5051
},
5152
"devDependencies": {
52-
"@redwoodjs/graphql-server": "^6.6.0",
53+
"@redwoodjs/graphql-server": "^7.7.3",
5354
"@types/yargs": "^17.0.32",
5455
"graphql-yoga": "^5.0.2"
5556
}

packages/misc/redwood/src/commands/setup.ts

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
1-
import { getPaths, updateTomlConfig } from '@redwoodjs/cli-helpers';
1+
import { getInstalledRedwoodVersion, getPaths, updateTomlConfig } from '@redwoodjs/cli-helpers';
22
import colors from 'colors';
33
import execa from 'execa';
44
import fs from 'fs';
55
import { Listr, ListrTask } from 'listr2';
66
import path from 'path';
7+
import semver from 'semver';
78
import terminalLink from 'terminal-link';
89
import { Project, SyntaxKind, type PropertyAssignment } from 'ts-morph';
910
import type { CommandModule } from 'yargs';
@@ -47,8 +48,8 @@ function bootstrapSchema() {
4748
const pkg = JSON.parse(content);
4849
if (!pkg.zenstack) {
4950
pkg.zenstack = {
50-
schema: path.relative(apiPaths.base, zmodel),
51-
prisma: path.relative(apiPaths.base, apiPaths.dbSchema),
51+
schema: normalizePath(path.relative(apiPaths.base, zmodel)),
52+
prisma: normalizePath(path.relative(apiPaths.base, apiPaths.dbSchema)),
5253
};
5354
fs.writeFileSync(pkgJson, JSON.stringify(pkg, null, 4));
5455
}
@@ -57,6 +58,11 @@ function bootstrapSchema() {
5758
};
5859
}
5960

61+
// ensures posix path separators are used in package.json
62+
function normalizePath(_path: string) {
63+
return _path.replaceAll(path.sep, path.posix.sep);
64+
}
65+
6066
// install ZenStack GraphQLYoga plugin
6167
function installGraphQLPlugin() {
6268
return {
@@ -144,11 +150,17 @@ function installGraphQLPlugin() {
144150
if (graphQlSourcePath.endsWith('.ts')) {
145151
const typeDefPath = path.join(getPaths().api.src, 'zenstack.d.ts');
146152
if (!fs.existsSync(typeDefPath)) {
153+
const rwVersion: string = getInstalledRedwoodVersion();
154+
const contextModule =
155+
rwVersion && semver.lt(rwVersion, '7.0.0')
156+
? '@redwoodjs/graphql-server' // pre v7
157+
: '@redwoodjs/context'; // v7+
158+
147159
const typeDefSourceFile = project.createSourceFile(
148160
typeDefPath,
149-
`import type { PrismaClient } from '@prisma/client'
161+
`import type { PrismaClient } from '@zenstackhq/runtime'
150162
151-
declare module '@redwoodjs/graphql-server' {
163+
declare module '${contextModule}' {
152164
interface GlobalContext {
153165
db: PrismaClient
154166
}

packages/runtime/res/enhance.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
export { auth, enhance } from '.zenstack/enhance';
1+
export { auth, enhance, type PrismaClient } from '.zenstack/enhance';

packages/schema/src/plugins/enhancer/enhance/index.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,8 +127,9 @@ ${
127127
}
128128

129129
private createSimplePrismaImports(prismaImport: string) {
130-
return `import { Prisma } from '${prismaImport}';
130+
return `import { Prisma, type PrismaClient } from '${prismaImport}';
131131
import type * as _P from '${prismaImport}';
132+
export type { PrismaClient };
132133
`;
133134
}
134135

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

0 commit comments

Comments
 (0)