Urigo / graphql-cli

📟 Command line tool for common GraphQL development workflows
https://graphql-cli.com
MIT License
1.99k stars 113 forks source link

Seems to be broken if you use with other CLI tools while using PNPM as package manager #1605

Open RIP21 opened 3 years ago

RIP21 commented 3 years ago

Basically, I'm using graphql-cli in a PNPM Workspaces environment, and if fails with the error below for any other CLI Tool integration such as codegen, coverage and valdiate. Using codegen as standalone CLI works fine no matter their setup.

(node:3206114) UnhandledPromiseRejectionWarning: Error: ENOTDIR: not a directory, stat '/home/alos/Projects/LiveFlow/app-frontend/common/temp/node_modules/.pnpm/graphql-cli@4.1.0_graphql@15.4.0/node_modules/graphql-cli/dist/bin.js/node_modules/@graphql-cli/*'
(node:3206114) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 1)
(node:3206114) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

PNPM resolves modules in a different way than yarn and npm I assume you may expect flattening and having graphql-codegen to be available in node_modules/.bin and just spawning the process like ./bin/graphql-codegen <some-args> relative to cwd, but it's not there due to PNPM resolution strategy so it fails. The obvious solution would be, to use the programmatic usage of CLIs tools mentioned above and not spawning the processes? Probably too much coding :) I'm unsure :) From code I see that there are maybe some issues with the generator of sh file ./node_modules/./bin/graphql that handles symlinks improperly?

To Reproduce Steps to reproduce the behavior:

  1. Use PNPM
  2. npx graphql-cli init
  3. Done
  4. Make sure you have everything in place for correct work of underlying CLI tools
  5. Run them.
  6. Get issue.

Expected behavior Everything is working fine. Or at least meaningful error message is there :)

Screenshots image

Versions (please complete the following information):

case uname in CYGWIN) basedir=cygpath -w "$basedir";; esac

export NODE_PATH="/home/alos/Projects/LiveFlow/app-frontend/common/temp/node_modules/.pnpm/graphql-cli@4.1.0_graphql@15.4.0/node_modules/graphql-cli/dist/bin.js/node_modules:/home/alos/Projects/LiveFlow/app-frontend/common/temp/node_modules/.pnpm/graphql-cli@4.1.0_graphql@15.4.0/node_modules/graphql-cli/dist/node_modules:/home/alos/Projects/LiveFlow/app-frontend/common/temp/node_modules/.pnpm/graphql-cli@4.1.0_graphql@15.4.0/node_modules/graphql-cli/node_modules:/home/alos/Projects/LiveFlow/app-frontend/common/temp/node_modules/.pnpm/graphql-cli@4.1.0_graphql@15.4.0/node_modules:/home/alos/Projects/LiveFlow/app-frontend/common/temp/node_modules/.pnpm/node_modules:/home/alos/Projects/LiveFlow/app-frontend/common/temp/node_modules:/home/alos/Projects/LiveFlow/app-frontend/common/node_modules:/home/alos/Projects/LiveFlow/app-frontend/node_modules:/home/alos/Projects/LiveFlow/node_modules:/home/alos/Projects/node_modules:/home/alos/node_modules:/home/node_modules:/node_modules:/home/alos/Projects/LiveFlow/app-frontend/ui/app/node_modules:/home/alos/Projects/LiveFlow/app-frontend/ui/node_modules" if [ -x "$basedir/node" ]; then exec "$basedir/node" "$basedir/../../../../common/temp/node_modules/.pnpm/graphql-cli@4.1.0_graphql@15.4.0/node_modules/graphql-cli/dist/bin.js" "$@" else exec node "$basedir/../../../../common/temp/node_modules/.pnpm/graphql-cli@4.1.0_graphql@15.4.0/node_modules/graphql-cli/dist/bin.js" "$@" fi

wtrocki commented 3 years ago

Never used CLI with this package manager. There will be couple places where CLI (and depending packages) will fail. We do not test with anything else than npm or yarn

RIP21 commented 3 years ago

You shall start testing with it as it is pretty popular :P PNPM is major for all people that are using rush.js monorepo management tool. To name a few Microsoft, Revolut and many more. PNPM is just amazing and IMO how npm should've been working from the day 1 :)

Anyway, mostly 99% of packages are working as is with PNPM, only CLIs are getting broken usually due to bin behavior (which is makes sense as it doesn't leak CLIs (bins) from transitive dependencies)

tvvignesh commented 3 years ago

Just tried installing graphql-cli using PNPM (since that's what I use) and I got the same error:

1
RIP21 commented 3 years ago

Overall GraphQL CLI + Codegen + Inspector add-ons are seem to be very fragile. I cannot specify, but on multiple occasions using those tools through the CLI wrapper, I end up getting issues, so currently I'm using those tools CLIs directly as, fortunately they're working as expected. And it's with regular npm. I'm not mentioning PNPM that is special.

I would rather keep init and few other commands unique to CLI in it, but rest would've removed for good to simplify maintenance.

As because I think you folks at Guild are having so much products to maintain I see their quality is worsened overtime and is not as perfect as it used to be and in integration they're not working quite often which is annoying.