Skip to content

Commit

Permalink
Add function to BaseConvexClient to return a mutation's request ID (#…
Browse files Browse the repository at this point in the history
…32373)

Related to get-convex/convex#32367, but when we request a mutation, we want to get its request ID so we can track it properly and potentially handle it being reflected in the `onTransition` callback.

GitOrigin-RevId: 1525f6de224bb88acba013dd6841cd53f0260b6b
  • Loading branch information
sshader authored and Convex, Inc. committed Dec 20, 2024
1 parent 0eefed1 commit 84314db
Showing 1 changed file with 23 additions and 1 deletion.
24 changes: 23 additions & 1 deletion src/browser/sync/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -719,6 +719,24 @@ export class BaseConvexClient {
options?: MutationOptions,
componentPath?: string,
): Promise<FunctionResult> {
const { mutationPromise } = this.enqueueMutation(
udfPath,
args,
options,
componentPath,
);
return mutationPromise;
}

/**
* @internal
*/
enqueueMutation(
udfPath: string,
args?: Record<string, Value>,
options?: MutationOptions,
componentPath?: string,
): { requestId: RequestId; mutationPromise: Promise<FunctionResult> } {
const mutationArgs = parseArgs(args);
this.tryReportLongDisconnect();
const requestId = this.nextRequestId;
Expand Down Expand Up @@ -770,7 +788,11 @@ export class BaseConvexClient {
args: [convexToJson(mutationArgs)],
};
const mightBeSent = this.webSocketManager.sendMessage(message);
return this.requestManager.request(message, mightBeSent);
const mutationPromise = this.requestManager.request(message, mightBeSent);
return {
requestId,
mutationPromise,
};
}

/**
Expand Down

0 comments on commit 84314db

Please sign in to comment.