feat: add createFetch to runtime, remove @constructive-io/node#1033
Merged
pyramation merged 6 commits intomainfrom Apr 28, 2026
Merged
feat: add createFetch to runtime, remove @constructive-io/node#1033pyramation merged 6 commits intomainfrom
pyramation merged 6 commits intomainfrom
Conversation
Simple alternative to #1025 — adds *.localhost DNS rewriting and a fetch injection point to OrmClientConfig without pulling in node:http, new Function(), or runtime environment detection. Changes: - localhostFetch(): ~20-line wrapper that rewrites *.localhost URLs to plain localhost and sets the Host header (best-effort) using globalThis.fetch. Zero dependencies, works in all runtimes. - FetchAdapter: accepts optional fetchFn (defaults to localhostFetch). - OrmClientConfig: new fetch? option lets callers inject custom fetch (e.g. @constructive-io/node for full Host header support via node:http, or a mock for tests). - Regenerated all SDK client files. - Added codegen tests for the new config surface and localhost rewriting.
Contributor
🤖 Devin AI EngineerI'll be helping with this pull request! Here's what you should know: ✅ I will automatically:
Note: I can only respond to comments from users who have write access to this repository. ⚙️ Control Options:
|
3 tasks
Replace the inlined localhostFetch wrapper with an import from @constructive-io/fetch (dev-utils#81). The package handles: - *.localhost DNS rewriting via node:http (fixes ENOTFOUND) - Host header preservation (fixes silent drop by undici) - Automatic passthrough for non-localhost URLs and browsers This moves the fetch logic to a shared library so it can be iterated on in one place rather than being baked into every generated client file. Added @constructive-io/fetch ^0.1.0 as a dependency to all SDK packages (constructive-sdk, constructive-react, constructive-cli, migrate-client).
The CLI E2E test generates ORM code into a temp directory and runs it in a subprocess. The generated client.ts now imports createFetch from @constructive-io/fetch, so the package must be resolvable via NODE_PATH. Added to both the runtimeDeps array in cli-e2e.test.ts and as a dependency in graphql/server-test/package.json.
…tive-io/fetch dep Instead of adding @constructive-io/fetch as an external dependency to every SDK package, embed the localhost-aware fetch directly in @constructive-io/graphql-query/runtime — which every generated client already imports. Zero new dependencies for consumers. - Added graphql/query/src/runtime/localhost-fetch.ts - Re-exported createFetch from runtime/index.ts - Updated codegen template to import from runtime - Removed @constructive-io/fetch from all SDK + server-test package.json - Regenerated all 13 SDK client files
No longer needed — createFetch() in @constructive-io/graphql-query/runtime handles *.localhost DNS + Host header for Node.js automatically. The SDK now works everywhere (Node, browser, Deno, Bun) without a separate Node-specific package. BREAKING: @constructive-io/node is removed. Users should import from @constructive-io/sdk directly — no adapter setup needed.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
Simple alternative to #1025. Adds
createFetch()to@constructive-io/graphql-query/runtime(already imported by every generated client) and deletes@constructive-io/node— the SDK now works everywhere without a separate Node-specific package.What
createFetch()does:node:http/node:httpsfor*.localhostURLs, fixing both DNS resolution (ENOTFOUND) and Host header preservation (silently dropped by undici). Delegates all other URLs toglobalThis.fetch.globalThis.fetchas-is (browsers handle*.localhostnatively).What changed:
graphql/query/src/runtime/localhost-fetch.ts— new ~100 line file withcreateFetch(),isLocalhostSubdomain(),FetchFunctiontype.graphql/query/src/runtime/index.ts— re-exportscreateFetchandFetchFunction.graphql/codegen/.../templates/orm-client.ts— importscreateFetchfrom runtime.FetchAdapterdefaults tocreateFetch(). NewOrmClientConfig.fetch?for custom fetch injection.sdk/constructive-node/—NodeHttpAdapteris now redundant sinceFetchAdapterusescreateFetch()by default.Why not #1025? That PR bakes ~200 lines into the codegen template (
node:http,new Function, runtime detection). This PR puts the logic in the runtime package that generated code already depends on — update one file, no regeneration needed.BREAKING:
@constructive-io/nodeis removed. Users should import from@constructive-io/sdkdirectly — no adapter setup needed.Review & Testing Checklist for Human
createClient({ endpoint: 'http://auth.localhost:3000/graphql' })resolves correctly from Node.js (no ENOTFOUND)auth.localhostroutes to the auth schema)@constructive-io/nodebefore mergingNotes
createFetchlives in@constructive-io/graphql-query/runtime@constructive-io/fetchpackage in dev-utils is still available as a standalone if needed@constructive-io/nodeusers: replaceimport { NodeHttpAdapter } from '@constructive-io/node'+createClient({ adapter })with justimport { createClient } from '@constructive-io/sdk'+createClient({ endpoint })Link to Devin session: https://app.devin.ai/sessions/0e3a5bf6765a4c979b64ef786a813225
Requested by: @pyramation