Skip to content

feat: use a field's @nexus.source as the default of an optional method parameter - #114

Closed
moetemp wants to merge 8 commits into
moe/up/stream-writer-sync-1106from
moe/source-fallback
Closed

moetemp wants to merge 8 commits into
moe/up/stream-writer-sync-1106from
moe/source-fallback

Conversation

@moetemp

@moetemp moetemp commented Nov 13, 2026 •

Copy link
Copy Markdown
Owner

This PR makes a field's @nexus.source the default of an optional resource method parameter.

A resource method can take a parameter that has the name of a sourced request field. When that
parameter is option<T>, the generated code passed it as it is. So a caller that gave no value
sent none, and the source was never used. With this change the caller's value wins, and the source
fills the field otherwise. The source is not evaluated when the caller passes a value. A required
parameter and a sourced field with no parameter behave as before.

The stream sample shows it. Its append and close take an optional producer.

producer=producer if producer is not None else _support.default_producer(),

Python, TypeScript and .NET follow the rule. The .NET sample also needed a fix for a flattened
list parameter in a method that builds the full request.

Notes for the review.

  • TypeScript and .NET cover top-level request fields. Python also covers the fields of nested
    records.
  • .NET has no runtime test, since the generated Stream needs a Workflow context. Python and
    TypeScript have one each.
  • The Workflow target shows the new parameter too. Should it?

moetemp and others added 4 commits November 12, 2026 18:08
The generated code passed an optional parameter as it was and dropped the source of the field. A
caller that passed nothing then sent no value for a required field.
A resource method passed an optional parameter as it was and dropped the source of the field. A
caller that passed nothing then sent no value for a required field.
A resource method passed an optional parameter as it was and dropped the source of the field. The
complete request also took a flattened list parameter as it was, so it did not compile.
The sample shows the source fallback in its generated Python, TypeScript and .NET. Its client source
helper is `default_producer`, since it picks the Producer by where the code runs.

Co-authored-by: Tim Conley <timothy.conley@temporal.io>
moetemp and others added 4 commits November 12, 2026 21:49
The optional `producer` parameters sit on top of the Store rename and the `append` result.
The docs of both `producer` fields match the API's WIT, which has the two optional parameters.

Co-authored-by: Tim Conley <timothy.conley@temporal.io>
The sync gave `append` its optional `sequence`, and this branch puts it after `producer` as the
API's WIT does. The generated samples were rebuilt, not merged by hand.
The sync brings the API's new offset and Workflow Producer comments, which this branch also needs.
@moetemp

moetemp commented Nov 13, 2026

Copy link
Copy Markdown
Owner Author

Replaced by temporalio#408.

@moetemp moetemp closed this Nov 13, 2026
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.

1 participant