@@ -100,7 +100,7 @@ const itemSchemaWithTitles = {
100100module . exports = {
101101
102102 // docs: https://win.wiz.io/reference/pull-cloud-resources
103- async receive ( context ) {
103+ async receive ( context ) {
104104
105105 const { outputType, filter, limit = 10 } = context . messages . in . content ;
106106
@@ -116,28 +116,41 @@ module.exports = {
116116 throw new context . CancelError ( 'Invalid Input: Filter' , e ) ;
117117 }
118118 }
119- const { data } = await lib . makeApiCall ( {
120- context,
121- method : 'POST' ,
122- data : {
123- query,
124- variables : {
125- first : limit ,
126- filterBy
119+
120+ let records = [ ] ;
121+ let nextPageToken = null ;
122+ let totalRecordsCount = 0 ;
123+ const PAGE_SIZE = 5 ;
124+
125+ do {
126+ const { data } = await lib . makeApiCall ( {
127+ context,
128+ method : 'POST' ,
129+ data : {
130+ query,
131+ variables : {
132+ first : Math . min ( PAGE_SIZE , limit - totalRecordsCount ) ,
133+ after : nextPageToken ,
134+ filterBy
135+ }
127136 }
137+ } ) ;
138+
139+ if ( data . errors ) {
140+ throw new context . CancelError ( data . errors ) ;
128141 }
129- } ) ;
130142
131- if ( data . errors ) {
132- throw new context . CancelError ( data . errors ) ;
133- }
143+ const { pageInfo, nodes : pageRecords } = data . data . cloudResources ;
134144
135- context . log ( { stage : 'response' , data } ) ;
145+ if ( pageRecords . length === 0 ) {
146+ return context . sendJson ( { filter : filterBy } , 'notFound' ) ;
147+ }
136148
137- if ( data . data . cloudResources . nodes . length === 0 ) {
138- return context . sendJson ( { filter : filterBy } , 'notFound' ) ;
139- }
149+ records = records . concat ( pageRecords ) ;
150+ totalRecordsCount += pageRecords . length ;
151+ nextPageToken = pageInfo . endCursor ;
152+ } while ( nextPageToken && totalRecordsCount < limit ) ;
140153
141- return lib . sendArrayOutput ( { context, records : data . data . cloudResources . nodes , outputType } ) ;
154+ return lib . sendArrayOutput ( { context, records, outputType } ) ;
142155 }
143156} ;
0 commit comments