11// assumption is that apis are giving json as output
22
3+ import { cloneDeep } from 'lodash' ;
34import useCanvasStore from 'stores/CanvasStore' ;
45import useCollectionStore from 'stores/CollectionStore' ;
56import { useTabStore } from 'stores/TabStore' ;
@@ -9,6 +10,10 @@ import { computeRequestNode } from './compute/requestnode';
910
1011class Graph {
1112 constructor ( nodes , edges , collectionId , onGraphComplete ) {
13+ const activeEnv = useCollectionStore
14+ . getState ( )
15+ . collections . find ( ( c ) => c . id === collectionId )
16+ ?. environments . find ( ( e ) => e . name === useTabStore . getState ( ) . selectedEnv ) ;
1217 this . nodes = nodes ;
1318 this . edges = edges ;
1419 this . onGraphComplete = onGraphComplete ;
@@ -17,10 +22,7 @@ class Graph {
1722 this . startTime = Date . now ( ) ;
1823 this . graphRunNodeOutput = { } ;
1924 this . auth = undefined ;
20- this . env = useCollectionStore
21- . getState ( )
22- . collections . find ( ( c ) => c . id === collectionId )
23- ?. environments . find ( ( e ) => e . name === useTabStore . getState ( ) . selectedEnv ) ;
25+ this . envVariables = activeEnv ? cloneDeep ( activeEnv . variables ) : undefined ;
2426 }
2527
2628 #checkTimeout( ) {
@@ -95,12 +97,19 @@ class Graph {
9597 }
9698
9799 if ( node . type === 'authNode' ) {
98- this . auth = node . data . type ? computeAuthNode ( node . data , this . env ) : undefined ;
100+ this . auth = node . data . type ? computeAuthNode ( node . data , this . envVariables ) : undefined ;
99101 result = [ 'Success' , node , prevNodeOutput ] ;
100102 }
101103
102104 if ( node . type === 'requestNode' ) {
103- result = await computeRequestNode ( node , prevNodeOutputData , this . env , this . auth , this . logs ) ;
105+ result = await computeRequestNode ( node , prevNodeOutputData , this . envVariables , this . auth , this . logs ) ;
106+ // add post response variables if any
107+ if ( result [ 3 ] ) {
108+ this . envVariables = {
109+ ...this . envVariables ,
110+ ...result [ 3 ] ,
111+ } ;
112+ }
104113 }
105114
106115 if ( this . #checkTimeout( ) ) {
0 commit comments