graphql-mesh icon indicating copy to clipboard operation
graphql-mesh copied to clipboard

Unable to build if handler package is hoisted in monorepo

Open yukukotani opened this issue 1 year ago • 2 comments

Issue workflow progress

Progress of the issue based on the Contributor Workflow

Make sure to fork this template and run yarn generate in the terminal.

Please make sure Mesh package versions under package.json matches yours.

  • [ ] 2. A failing test has been provided
  • [ ] 3. A local solution has been provided
  • [ ] 4. A pull request is pending review

Describe the bug

In monorepo environment, some packages may be hoisted and located in different directories. For example, @graphql-mesh/cli is hoisted and located at root node_modules, and handlers such as @graphql-mesh/graphql are located at workspace node_modules.

In the case of cli and handlers being in different directories like this, mesh build will fail with the error below.

💡 🕸️  Mesh Cleaning existing artifacts
💡 🕸️  Mesh Reading the configuration
💥 🕸️  Mesh TypeError: HandlerCtor is not a constructor
    at /Users/yukukotani/ghq/github.com/yuku-sandbox/graphql-mesh-handler-error-repro/node_modules/@graphql-mesh/cli/node_modules/@graphql-mesh/config/cjs/process.js:116:28
    at async /Users/yukukotani/ghq/github.com/yuku-sandbox/graphql-mesh-handler-error-repro/node_modules/@graphql-mesh/cli/node_modules/@graphql-mesh/config/cjs/process.js:95:17
    at async Promise.all (index 0)
    at async Promise.all (index 0)
    at async processConfig (/Users/yukukotani/ghq/github.com/yuku-sandbox/graphql-mesh-handler-error-repro/node_modules/@graphql-mesh/cli/node_modules/@graphql-mesh/config/cjs/process.js:87:114)
    at async Object.handler (/Users/yukukotani/ghq/github.com/yuku-sandbox/graphql-mesh-handler-error-repro/node_modules/@graphql-mesh/cli/cjs/index.js:296:32)
npm ERR! Lifecycle script `build` failed with error:
npm ERR! Error: command failed
npm ERR!   in workspace: [email protected]
npm ERR!   at location: /Users/yukukotani/ghq/github.com/yuku-sandbox/graphql-mesh-handler-error-repro/mesh

To Reproduce Steps to reproduce the behavior:

https://github.com/yuku-sandbox/graphql-mesh-handler-error-repro

Expected behavior

mesh build succeed even if some packages are hoisted.

Environment:

  • OS: MacOS 13.3.1 Apple Silicon
  • NodeJS: v18.18.2
  • npm: v9.8.1

Additional context

yukukotani avatar Nov 02 '23 15:11 yukukotani

same problem with npm workspaces

pczern avatar Dec 22 '23 03:12 pczern

solved it with pnpm add .npmrc with hoist-pattern[]=!@graphql-mesh/cli in your workspace where you use graphql-mesh you can define workspaces at the root in a pnpm-workspace.yaml with

packages:
  - 'packages/*'

pczern avatar Dec 22 '23 06:12 pczern