fix(graphql-codegen): use native Node http/https, improve errors, programmatic oxfmt #666
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
fix(graphql-codegen): use native Node http/https, improve errors, programmatic oxfmt
Summary
This PR addresses issues with the graphql-codegen CLI and simplifies the HTTP implementation:
Native Node.js http/https modules: Replaced undici with native Node.js
http/httpsmodules in both the code generator (fetch-schema.ts) and the generated Node.js client template (client.node.ts). This eliminates the need for localhost DNS resolution workarounds that were required with undici.Better fetch error messages: When schema fetching fails, the CLI now provides specific error messages for common network errors instead of the generic "fetch failed":
ECONNREFUSED: "Connection refused - is the server running at {endpoint}?"ENOTFOUND: "DNS lookup failed for {hostname} - check the endpoint URL"ECONNRESET: "Connection reset by server at {endpoint}"Programmatic oxfmt usage: Replaced shell-based
execSync('npx oxfmt ...')with oxfmt's JavaScript API to avoid "command not found" errors when running via npx.Updates since last revision
http/httpsmodules infetch-schema.tsandclient.node.tsclient.browser.ts) still uses native W3C fetch APIReview & Testing Checklist for Human
http://localhost:4000/graphqlorhttp://api.localhost:4000/graphql) to verify native http/https handles localhost correctly without DNS issuesnpx @constructive-io/graphql-codegen generate --config .fig.tsand verify files are properly formattedclient.node.tscode (using native http/https) successfully makes GraphQL requestssignaloption was removed fromExecuteOptionsin the Node.js client - verify this doesn't break existing usageNotes
browserCompatible: false) now uses nativehttp/httpsmodules instead of undicibrowserCompatible: true) still uses native W3C fetch APIformatOutputfunction is now async and marked as@deprecated- callers should usewriteGeneratedFileswithformatFiles: trueinsteadRequested by: Dan Lynch (@pyramation)
Devin session: https://app.devin.ai/sessions/3d3a080162794754a76776042f44c8be