clientgen: add optional CallParameters to generated TypeScript endpoint methods#2436
Open
0x4A756E65 wants to merge 1 commit into
Open
clientgen: add optional CallParameters to generated TypeScript endpoint methods#24360x4A756E65 wants to merge 1 commit into
0x4A756E65 wants to merge 1 commit into
Conversation
…nt methods
Generated TypeScript service methods for non-raw, non-stream endpoints
now accept an optional `options?: CallParameters` trailing parameter,
which is forwarded to `callTypedAPI`. This allows callers to pass
an AbortSignal (or other fetch RequestInit options) per request.
A common scenario: when a React SPA uses TanStack Query, the library
provides an AbortSignal that fires when a component unmounts or a query
is invalidated. Without this change, there is no way to forward that
signal through the generated client, causing the backend to continue
processing abandoned requests and logging spurious "context canceled"
errors.
Usage example:
const query = useQuery({
queryKey: ["status"],
queryFn: ({ signal }) =>
client.myService.GetStatus(req, { signal }),
});
When headers or query parameters are already present, the options
are spread into the existing params object (`{...options, headers, query}`)
so endpoint-specific values take precedence.
Raw endpoints already accepted CallParameters and are unchanged.
Stream endpoints are unchanged.
The sharedTypes code path is unchanged.
Author
|
Any interest here Encore team? |
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.
Generated TypeScript endpoint methods don't currently accept
CallParameters, so there's no way to pass anAbortSignalthrough the generated client. Raw endpoints already support this — this brings typed endpoints to parity.Without this, when a user navigates away from a page in a SPA, in-flight requests can't be canceled. The backend continues processing the abandoned request and logs "context canceled" errors when the response tries to write to a closed connection.
Before / After
Changes
pkg/clientgen/typescript.go: non-raw, non-stream endpoints now accept an optional trailingoptions?: CallParameters, forwarded tocallTypedAPI. When headers/query are present, options are spread first ({...options, headers, query}) so endpoint-specific values take precedence.sharedTypes, stream, and raw code paths are unchanged.