Skip to content

Commit 55d50aa

Browse files
committed
feat: add triggerExecution mutation and execution result management to Flow service
1 parent 422a032 commit 55d50aa

1 file changed

Lines changed: 32 additions & 0 deletions

File tree

src/packages/ce/src/flow/services/Flow.service.ts

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import {ReactiveArrayService, ReactiveArrayStore} from "@code0-tech/pictor";
22
import {
3+
ExecutionResult,
34
FlowInput,
45
FlowSetting,
56
FlowType,
@@ -13,6 +14,8 @@ import {
1314
NamespacesProjectsFlowsCreatePayload,
1415
NamespacesProjectsFlowsDeleteInput,
1516
NamespacesProjectsFlowsDeletePayload,
17+
NamespacesProjectsFlowsTriggerExecutionInput,
18+
NamespacesProjectsFlowsTriggerExecutionPayload,
1619
NamespacesProjectsFlowsUpdateInput,
1720
NamespacesProjectsFlowsUpdatePayload,
1821
NodeFunction,
@@ -29,6 +32,7 @@ import flowQuery from "@edition/flow/services/queries/Flow.query.graphql";
2932
import flowCreateMutation from "@edition/flow/services/mutations/Flow.create.mutation.graphql";
3033
import flowDeleteMutation from "@edition/flow/services/mutations/Flow.delete.mutation.graphql";
3134
import flowUpdateMutation from "@edition/flow/services/mutations/Flow.update.mutation.graphql";
35+
import flowTriggerExecutionMutation from "@edition/flow/services/mutations/Flow.triggerExecution.mutation.graphql";
3236
import {View} from "@code0-tech/pictor/dist/utils/view";
3337
import {FlowView} from "@edition/flow/services/Flow.view";
3438

@@ -537,4 +541,32 @@ export class FlowService extends ReactiveArrayService<FlowView, FlowDependencies
537541
return result.data?.namespacesProjectsFlowsUpdate ?? undefined
538542
}
539543

544+
async triggerExecution(payload: NamespacesProjectsFlowsTriggerExecutionInput): Promise<NamespacesProjectsFlowsTriggerExecutionPayload | undefined> {
545+
const result = await this.client.mutate<Mutation, NamespacesProjectsFlowsTriggerExecutionInput>({
546+
mutation: flowTriggerExecutionMutation,
547+
variables: {
548+
...payload
549+
}
550+
})
551+
552+
return result.data?.namespacesProjectsFlowsTriggerExecution ?? undefined
553+
}
554+
555+
addExecutionResult(flowId: FlowView['id'], executionResult: ExecutionResult): void {
556+
const flow = this.getById(flowId)
557+
const index = this.values().findIndex(f => f.id === flowId)
558+
if (!flow || index < 0) return
559+
560+
const existingNodes = flow.executionResults?.nodes ?? []
561+
if (existingNodes.some(node => node?.id === executionResult.id)) return
562+
563+
flow.executionResults = {
564+
__typename: "ExecutionResultConnection",
565+
...flow.executionResults,
566+
nodes: [...existingNodes, executionResult],
567+
}
568+
569+
this.set(index, new View(flow))
570+
}
571+
540572
}

0 commit comments

Comments
 (0)