1- import { getPaths , updateTomlConfig } from '@redwoodjs/cli-helpers' ;
1+ import { getInstalledRedwoodVersion , getPaths , updateTomlConfig } from '@redwoodjs/cli-helpers' ;
22import colors from 'colors' ;
33import execa from 'execa' ;
44import fs from 'fs' ;
55import { Listr , ListrTask } from 'listr2' ;
66import path from 'path' ;
7+ import semver from 'semver' ;
78import terminalLink from 'terminal-link' ;
89import { Project , SyntaxKind , type PropertyAssignment } from 'ts-morph' ;
910import 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
6167function 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 }
0 commit comments