11import { ReactiveArrayService , ReactiveArrayStore } from "@code0-tech/pictor" ;
22import {
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";
2932import flowCreateMutation from "@edition/flow/services/mutations/Flow.create.mutation.graphql" ;
3033import flowDeleteMutation from "@edition/flow/services/mutations/Flow.delete.mutation.graphql" ;
3134import flowUpdateMutation from "@edition/flow/services/mutations/Flow.update.mutation.graphql" ;
35+ import flowTriggerExecutionMutation from "@edition/flow/services/mutations/Flow.triggerExecution.mutation.graphql" ;
3236import { View } from "@code0-tech/pictor/dist/utils/view" ;
3337import { 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