dillonkearns / elm-graphql

Autogenerate type-safe GraphQL queries in Elm.

Home Page:https://package.elm-lang.org/packages/dillonkearns/elm-graphql/latest

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Don't require NPX for elm-format

toastal opened this issue · comments

I understand the idea here, but there are people that may want to either a globally installed version or a forked version of elm-format. For me locally, npx is failing to run the NPM-distributed binary, so I manually installed Elm format globally to my system. It works, but this generation script still fails. I think there may be many reasons to want to use a different formatting style or a bugfix fork. I would prefer to see the script test for binary existence first, and fallback to npx iff necessary.

It's funny you mention it, we just discussed this exact thing on an Elm Radio episode we recorded. I agree, I think it makes sense to check to see if there is an elm-format executable on the PATH first.

Jeroen mentioned that elm-review tries to run elm-format using different methods to see if any of them succeed. I found the code for it here:

https://github.com/jfmengels/node-elm-review/blob/45b5ba07f9776eb12829c63725fc66b09386ed70/lib/autofix.js#L105-L184

I think a similar approach would make sense for elm-graphql.

Just a note for this discussion, I finished a new setup on my computer, put the project to work, and everything was fine until I regenerated the Graphql modules.
I thought it had broken in some Graphql version bump, but that wasn't the case.
I had installed yarn and node on my system, and as there was no reason, I skipped NPM. I had elm-format system-wide and in node_modules. But I didn't have NPX.

TL;DR: If you don't have NPX, elm-graphql doesn't even output a warning that files were not formatted. What may look broken for you and the elm compiler are actually just not formatted files...

I pushed a fix for this in NPM version 4.2.0!

https://github.com/dillonkearns/elm-graphql/blob/master/CHANGELOG-NPM-PACKAGE.md

Thanks all for the feedback on this 🙏