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

NoImplicitPrelude is not well handled

Open lf- opened this issue 9 months ago • 3 comments

I have a project which uses NoImplicitPrelude to replace the stock Haskell prelude. Thus, all the modules must import that custom prelude. However, there seems to not be a knob to turn (besides the hilarious idea of exporting a prelude from the Scalars module, which is a viable workaround) to actually ask graphql-codegen to import a module from the apiModule to get symbols like Show.

lf- avatar Mar 05 '25 01:03 lf-

Hm would explicitly adding {-# LANGUAGE ImplicitPrelude #-} work, or do you want graphql-codegen to explicitly import a different prelude?

If the latter, a couple options come to mind:

  1. Use a cabal mixin to rename your custom prelude as Prelude
  2. Add a step that runs sed on the generated file to use your module instead

If neither of those options work, then I'd be open to a PR that allows the user to configure the prelude to use

brandonchinn178 avatar Mar 05 '25 02:03 brandonchinn178

Hmmm. Good question. I did just wind up reexporting the prelude from the scalars module and fixed my problem by doing so; it looks like the main work codebase authors had the same idea.

Cabal mixin is possible but I don't know how those work. Perhaps adding ImplicitPrelude is okay; I doubt it will cause problems at the very least except to the most dedicated prelude replacement projects.

lf- avatar Mar 05 '25 02:03 lf-

https://cabal.readthedocs.io/en/stable/cabal-package-description-file.html#pkg-field-mixins

You should be able to add

mixins:
  base (Prelude as PreludeBase)

and then rename your CustomPrelude.hs as just Prelude.hs, then the implicit prelude in the rest of your project would import your prelude with the implicit import Prelude

brandonchinn178 avatar Mar 05 '25 03:03 brandonchinn178