Skip to content

Commit bdf2e71

Browse files
committed
fix nested workflows
1 parent 60936f9 commit bdf2e71

File tree

4 files changed

+37
-3
lines changed

4 files changed

+37
-3
lines changed

example/convex/_generated/api.d.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111
import type * as admin from "../admin.js";
1212
import type * as example from "../example.js";
13+
import type * as nestedWorkflow from "../nestedWorkflow.js";
1314
import type * as transcription from "../transcription.js";
1415
import type * as userConfirmation_steps from "../userConfirmation/steps.js";
1516
import type * as userConfirmation_workflow from "../userConfirmation/workflow.js";
@@ -31,6 +32,7 @@ import type {
3132
declare const fullApi: ApiFromModules<{
3233
admin: typeof admin;
3334
example: typeof example;
35+
nestedWorkflow: typeof nestedWorkflow;
3436
transcription: typeof transcription;
3537
"userConfirmation/steps": typeof userConfirmation_steps;
3638
"userConfirmation/workflow": typeof userConfirmation_workflow;

example/convex/nestedWorkflow.ts

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import { v } from "convex/values";
2+
import { workflow } from "./example";
3+
import { internal } from "./_generated/api";
4+
5+
export const parentWorkflow = workflow.define({
6+
args: { prompt: v.string() },
7+
returns: v.null(),
8+
handler: async (ctx, args) => {
9+
console.log("Starting confirmation workflow");
10+
const length = await ctx.runWorkflow(
11+
internal.nestedWorkflow.nestedWorkflow,
12+
{ foo: args.prompt },
13+
);
14+
console.log("Length:", length);
15+
},
16+
});
17+
18+
export const nestedWorkflow = workflow.define({
19+
args: { foo: v.string() },
20+
returns: v.number(),
21+
handler: async (_, args) => {
22+
console.log("Starting nested workflow");
23+
return args.foo.length;
24+
},
25+
});

src/client/index.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,12 @@ import {
1515
type RegisteredMutation,
1616
type ReturnValueForOptionalValidator,
1717
} from "convex/server";
18-
import type { ObjectType, PropertyValidators, Validator } from "convex/values";
18+
import type {
19+
Infer,
20+
ObjectType,
21+
PropertyValidators,
22+
Validator,
23+
} from "convex/values";
1924
import type { Step } from "../component/schema.js";
2025
import type {
2126
EventId,
@@ -113,7 +118,9 @@ export class WorkflowManager {
113118
fn: "You should not call this directly, call workflow.start instead";
114119
args: ObjectType<ArgsValidator>;
115120
},
116-
void
121+
ReturnsValidator extends Validator<unknown, "required", string>
122+
? Infer<ReturnsValidator>
123+
: void
117124
> {
118125
return workflowMutation(
119126
this.component,

src/client/types.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ export type WorkflowCtx = {
9191
*/
9292
runWorkflow<Workflow extends FunctionReference<"mutation", "internal">>(
9393
workflow: Workflow,
94-
args: FunctionArgs<Workflow>,
94+
args: FunctionArgs<Workflow>["args"],
9595
opts?: RunOptions,
9696
): Promise<FunctionReturnType<Workflow>>;
9797

0 commit comments

Comments
 (0)