feat(workflow): expand manual-trigger runtime payload with payload + _metadata (#21676)

## Summary

Step 1 (**expand**) of restructuring the manual-trigger output so record
fields live under a `payload` key and trigger-level metadata (the
running workspace member) lives alongside it. This step is **additive
and runtime-only** — no behavior changes for existing workflows, and
nothing new is surfaced in the variable picker yet.

The manual-trigger runtime payload now additively carries:
- `payload`: a mirror of the incoming record fields, reachable at
`{{trigger.payload.*}}`
- `_metadata.workspaceMemberId`: the member who ran the workflow,
reachable at `{{trigger._metadata.workspaceMemberId}}`

Record fields are still served at the trigger root, so existing
`{{trigger.id}}` references keep working unchanged. The output schema /
variable picker is intentionally left untouched here.

### Why `_metadata` (underscore)
During the transition, record fields still sit at the `trigger` root
next to the injected keys. Field API names can't start with `_`, so
`_metadata` is collision-proof against any record field; picking the
name now avoids a later variable-path rename migration.

### Phasing
- **Step 1 (this PR):** write `payload` + `_metadata` at runtime; keep
using direct `trigger.*`; don't display the new paths.
- **Step 2:** surface `payload` + `_metadata` in the variable picker.
- **Step 3:** migrate existing variables to `trigger.payload.*` and
contract the root record fields.

## Test plan
- [x] `twenty-shared` builds, `twenty-server` typechecks, lint clean on
changed files
- [x] Manual: run a manually-triggered (SINGLE_RECORD) workflow and
confirm the run's trigger payload contains `payload.*` mirroring the
record and `_metadata.workspaceMemberId`
- [x] Manual: confirm existing `{{trigger.id}}` references still resolve

<!-- This is an auto-generated description by cubic. -->
<a
href="https://cubic.dev/pr/twentyhq/twenty/pull/21676?utm_source=github"
target="_blank" rel="noopener noreferrer"
data-no-image-dialog="true"><picture><source
media="(prefers-color-scheme: dark)"
srcset="https://www.cubic.dev/buttons/review-in-cubic-dark.svg"><source
media="(prefers-color-scheme: light)"
srcset="https://www.cubic.dev/buttons/review-in-cubic-light.svg"><img
alt="Review in cubic"
src="https://www.cubic.dev/buttons/review-in-cubic-dark.svg"></picture></a>
<!-- End of auto-generated description by cubic. -->
This commit is contained in:
Thomas Trompette
2026-06-16 17:49:12 +02:00
committed by GitHub
parent 61309c45e6
commit ff03e935ef
5 changed files with 20 additions and 1 deletions
@@ -2,6 +2,11 @@ import { UseFilters, UseGuards, UsePipes } from '@nestjs/common';
import { Args, Mutation } from '@nestjs/graphql';
import { PermissionFlagType } from 'twenty-shared/constants';
import {
WORKFLOW_TRIGGER_METADATA_KEY,
WORKFLOW_TRIGGER_METADATA_WORKSPACE_MEMBER_ID_KEY,
WORKFLOW_TRIGGER_PAYLOAD_KEY,
} from 'twenty-shared/workflow';
import { CoreResolver } from 'src/engine/api/graphql/graphql-config/decorators/core-resolver.decorator';
import { UUIDScalarType } from 'src/engine/api/graphql/workspace-schema-builder/graphql-types/scalars';
@@ -98,7 +103,14 @@ export class WorkflowTriggerResolver {
return this.workflowTriggerWorkspaceService.runWorkflowVersion({
workflowVersionId,
workflowRunId: workflowRunId ?? undefined,
payload: payload ?? {},
payload: {
...(payload ?? {}),
[WORKFLOW_TRIGGER_PAYLOAD_KEY]: { ...(payload ?? {}) },
[WORKFLOW_TRIGGER_METADATA_KEY]: {
[WORKFLOW_TRIGGER_METADATA_WORKSPACE_MEMBER_ID_KEY]:
workspaceMember.id,
},
},
createdBy: buildCreatedByFromFullNameMetadata({
fullNameMetadata: {
firstName: workspaceMember.name.firstName,