You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
If you’re using ESM, the trick is to run NODE_OPTIONS='--loader ts-node/esm --experimental-specifier-resolution=node' graphql-codegen, which will tell the node process to use ts-node/esm to load your module. You don’t need to specify a require option in the codegen in this case.
The Pothos docs’ method also works in both cases (provided you use the same trick for ESM), but it’s probably overkill since the Codegen module now supports importing TypeScript files directly.
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
I’ve just spent a few days on this one & ran into total hell. So I figured I’d post something here in case anyone is running into the same thing.
If you’re using CJS,
graphql-code-generator
has its own instructions on getting TypeScript to work. I’m on ESM so can’t verify them, but they should work fine.If you’re using ESM, the trick is to run
NODE_OPTIONS='--loader ts-node/esm --experimental-specifier-resolution=node' graphql-codegen
, which will tell thenode
process to usets-node/esm
to load your module. You don’t need to specify arequire
option in the codegen in this case.The Pothos docs’ method also works in both cases (provided you use the same trick for ESM), but it’s probably overkill since the Codegen module now supports importing TypeScript files directly.
Beta Was this translation helpful? Give feedback.
All reactions