Skip to content

Conversation

@pyramation
Copy link
Contributor

@pyramation pyramation commented Jan 27, 2026

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:

  1. Native Node.js http/https modules: Replaced undici with native Node.js http/https modules 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.

  2. 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}"
  3. 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

  • Replaced undici with native Node.js http/https modules in fetch-schema.ts and client.node.ts
  • Removed all localhost DNS resolution workaround code (not needed with native modules)
  • Browser-compatible template (client.browser.ts) still uses native W3C fetch API

Review & Testing Checklist for Human

  • Test codegen against localhost endpoint: Run codegen against a local GraphQL server (e.g., http://localhost:4000/graphql or http://api.localhost:4000/graphql) to verify native http/https handles localhost correctly without DNS issues
  • Test codegen with oxfmt formatting: Run npx @constructive-io/graphql-codegen generate --config .fig.ts and verify files are properly formatted
  • Test error messages: Try running codegen against a non-running server to verify the improved error message appears
  • Verify generated Node.js client works: Test that the generated client.node.ts code (using native http/https) successfully makes GraphQL requests
  • Note: AbortSignal removed: The signal option was removed from ExecuteOptions in the Node.js client - verify this doesn't break existing usage

Notes

  • The generated Node.js client (browserCompatible: false) now uses native http/https modules instead of undici
  • The generated browser client (browserCompatible: true) still uses native W3C fetch API
  • The formatOutput function is now async and marked as @deprecated - callers should use writeGeneratedFiles with formatFiles: true instead
  • The format-output test skips when oxfmt can't be dynamically imported in Jest - this means CI doesn't verify formatting functionality

Requested by: Dan Lynch (@pyramation)
Devin session: https://app.devin.ai/sessions/3d3a080162794754a76776042f44c8be

…mt API

- Improve fetch error messages with specific context for ECONNREFUSED,
  ENOTFOUND, and ECONNRESET errors instead of generic 'fetch failed'
- Replace shell-based oxfmt execution with programmatic API to avoid
  'command not found' errors when running via npx
- Format files inline during write instead of post-processing directory
@devin-ai-integration
Copy link
Contributor

🤖 Devin AI Engineer

I'll be helping with this pull request! Here's what you should know:

✅ I will automatically:

  • Address comments on this PR. Add '(aside)' to your comment to have me ignore it.
  • Look at CI failures and help fix them

Note: I can only respond to comments from users who have write access to this repository.

⚙️ Control Options:

  • Disable automatic comment and CI monitoring

- Remove undici dependency from fetch-schema.ts and client.node.ts
- Remove localhost DNS workaround code (not needed with native http/https)
- Simplify code by using native Node.js http/https modules directly
- Browser-compatible template (client.browser.ts) still uses native fetch
@devin-ai-integration devin-ai-integration bot changed the title fix(graphql-codegen): improve error messages and use programmatic oxfmt API fix(graphql-codegen): use native Node http/https, improve errors, programmatic oxfmt Jan 27, 2026
@pyramation pyramation merged commit 65f96f7 into main Jan 27, 2026
52 checks passed
@pyramation pyramation deleted the devin/1769510403-fix-codegen-cli-issues branch January 27, 2026 11:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants