graphql-framework-experiment
graphql-framework-experiment copied to clipboard
Support monorepos
Perceived Problem
Nexus currently don't support monorepos/yarn workspaces for a couple of reasons:
-
It relies on "hardcoded" paths to
node_modules/*
. This means hoisted modules by yarn workspace will break the framework -
It relies on the nearest
package.json
toprocess.cwd()
, sometimes breaking the framework's ability to find the rightpackage.json
to extract and install the plugins
Ideas / Proposed Solution(s)
None yet.
Yeah I got this message
since my prisma folder is in the root of the monorepo and not on a single package... any date for this? :/
also running into this. Tomorrow I'm going to look into keeping our server in the same repo, but pulling it out from being a workspace, if that is even possible.
I was having trouble with running the production version of the server
(the one generated after nexus build
, on a monorepo).
I changed the recommended start script, along with adding "outDir": "./dist"
to tsconfig.json
:
- "start": "node node_modules/.build"
+ "start": "node dist"
and now it's working! 🎉
the version inside node_modules/.build
doesn't includes my files in the graphql
folder 🙂
(more info: I'm using yarn workspaces, with noHoist for all packages)
update: is there any particular reason why can't we just rely on the outDir
, and stop emitting the production code to node_modules
? 🤔
Same thing, just got into this issue, but it worked before. This issue is stopping me from fully migrating to Nexus.
Hey folks 👋,
I just made a test with nexus@next
+ nexus-plugin-prisma@next
in a yarn workspace setup and everything seemed to be working when keeping the prisma stuff (migrations + schema.prisma file) in the same folder as the package which contains nexus
(either at the root of that package or in a conventional prisma/
folder).
Could some of you report to me the issues they are currently facing so that we can move this forward (apart from @yovanoc 's issue when storing the prisma schema at the root of the repo)?
@Weakky works for me
@Weakky the current problem is that if I run yarn install
from my root directory it doesn't install necessary packages like @prisma/client
.
I'm having the following issue with using nexus with yarn workspaces.
Nexus is used in @learn/server
package.
Here's the tsconfig:
{
"compilerOptions": {
"target": "es2016",
"module": "commonjs",
"lib": ["esnext"],
"strict": true,
"rootDir": "src",
"esModuleInterop": true
},
"include": ["src"]
}
When I run nexus dev, I get the following error:
$ nexus dev
796 ✕ nexus reflection failed
| error TSError: ⨯ Unable to compile TypeScript:
| error TS6059: File '/Users/yan/Projects/learn2/packages/common/utils/index.ts' is not under 'rootDir' '/Users/yan/Projects/learn2/packages/server/src'. 'rootDir' is expected to contain all source files.
The error comes from this line:
import { initFirebaseAdmin } from '@learn/common/utils'
when I try to import a util from another workspace, that is present in package.json:
"dependencies": {
"@learn/common": "1.0.0",
}
Update. This happens only with nexus v0.21.0+
, works fine with v0.20.0
.
@Weakky I've been using nexus in 2 yarn workspace monorepo, and everything is fine as long as you keep everything under the same package.
Hi, I'm using nexus in a project that use yarn workspaces and lerna to build the app...
It works perfectly in dev mode... but fails when I try to build it...
The project use the nexus prisma plugin, with a sqlite database...
❯ yarn workspace @xXXxXXx/server build
yarn workspace v1.22.4
yarn run v1.22.4
$ nexus build
1170 ● nexus:build get used plugins
2099 ● nexus:plugin:nexusPluginPrisma Running Prisma generators ...
727 ● nexus:build starting reflection
5223 ✕ nexus reflection failed
| error Error:
| Runner failed with exit code "1".
|
| at ChildProcess.<anonymous> (/Users/xxx/xxx/xxx/packages/server/node_modules/nexus/dist/lib/reflection/reflect.js:71:28)
| at ChildProcess.emit (events.js:315:20)
| at ChildProcess.EventEmitter.emit (domain.js:485:12)
| at Process.ChildProcess._handle.onexit (internal/child_process.js:275:12)
The config files are in this gist:
https://gist.github.com/mtzfactory/65f321b03ef09769c7366e6550323675
In case anyone else has the same problem, the following config worked for me in dev
(not build
, see below):
// in the root package.json
"workspaces": {
"packages": [
"packages/*"
],
"noHoist": [
"**/@prisma/**",
"**/@prisma",
"**/prisma/**",
"**/prisma",
"**/nexus/**",
"**/nexus",
"**/nexus-plugin-prisma/**",
"**/nexus-plugin-prisma"
]
},
This should allow nexus packages, nexus plugin packages and packages using prisma to co-exist in the same set of workspaces.
Running a nexus production build still throws errors, but at at least you can keep working until there is a proper fix.
node_modules/@types/typegen-nexus/index.d.ts:41:12 - error TS2304: Cannot find name 'NexusPrisma'.
41 model: NexusPrisma<TypeName, 'model'>
~~~~~~~~~~~