graphql-framework-experiment icon indicating copy to clipboard operation
graphql-framework-experiment copied to clipboard

Support monorepos

Open Weakky opened this issue 4 years ago • 12 comments

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 to process.cwd(), sometimes breaking the framework's ability to find the right package.json to extract and install the plugins

Ideas / Proposed Solution(s)

None yet.

Weakky avatar Mar 23 '20 17:03 Weakky

Yeah I got this message image

since my prisma folder is in the root of the monorepo and not on a single package... any date for this? :/

yovanoc avatar Mar 25 '20 15:03 yovanoc

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.

chrisdrackett avatar Apr 23 '20 07:04 chrisdrackett

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? 🤔

leonardodino avatar Apr 26 '20 21:04 leonardodino

Same thing, just got into this issue, but it worked before. This issue is stopping me from fully migrating to Nexus.

impowski avatar May 07 '20 14:05 impowski

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 avatar May 11 '20 10:05 Weakky

@Weakky works for me

impowski avatar May 11 '20 19:05 impowski

@Weakky the current problem is that if I run yarn install from my root directory it doesn't install necessary packages like @prisma/client.

impowski avatar May 11 '20 22:05 impowski

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",
}

yantakus avatar May 12 '20 10:05 yantakus

Update. This happens only with nexus v0.21.0+, works fine with v0.20.0.

yantakus avatar May 14 '20 06:05 yantakus

@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.

emyann avatar Jun 04 '20 15:06 emyann

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

mtzfactory avatar Jul 08 '20 10:07 mtzfactory

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'>
              ~~~~~~~~~~~

garth avatar Aug 24 '20 08:08 garth