@@ -162,10 +162,19 @@ export function listDiscussions(
162162 }
163163
164164 const hasCategory = categoryId !== undefined ;
165- const query = `
166- query($owner: String!, $repo: String!, $first: Int!${ hasCategory ? ', $categoryId: ID!' : '' } ) {
165+
166+ const allNodes : RawDiscussion [ ] = [ ] ;
167+ let hasNextPage = true ;
168+ let endCursor : string | null = null ;
169+
170+ while ( hasNextPage ) {
171+ const afterClause = endCursor ? `, after: $after` : '' ;
172+ const afterVar = endCursor ? ', $after: String!' : '' ;
173+
174+ const query = `
175+ query($owner: String!, $repo: String!, $first: Int!${ hasCategory ? ', $categoryId: ID!' : '' } ${ afterVar } ) {
167176 repository(owner: $owner, name: $repo) {
168- discussions(first: $first${ hasCategory ? ', categoryId: $categoryId' : '' } ) {
177+ discussions(first: $first${ hasCategory ? ', categoryId: $categoryId' : '' } ${ afterClause } ) {
169178 nodes {
170179 number
171180 id
@@ -176,31 +185,54 @@ export function listDiscussions(
176185 createdAt
177186 updatedAt
178187 }
188+ pageInfo {
189+ hasNextPage
190+ endCursor
191+ }
179192 }
180193 }
181194 }
182195 ` . trim ( ) ;
183196
184- const args = [
185- 'api' , 'graphql' ,
186- '-f' , `query=${ query } ` ,
187- '-f' , `owner=${ owner } ` ,
188- '-f' , `repo=${ repoName } ` ,
189- '-F' , `first=${ first } ` ,
190- ] ;
197+ const args = [
198+ 'api' , 'graphql' ,
199+ '-f' , `query=${ query } ` ,
200+ '-f' , `owner=${ owner } ` ,
201+ '-f' , `repo=${ repoName } ` ,
202+ '-F' , `first=${ first } ` ,
203+ ] ;
191204
192- if ( hasCategory ) {
193- args . push ( '-f' , `categoryId=${ categoryId } ` ) ;
194- }
205+ if ( hasCategory ) {
206+ args . push ( '-f' , `categoryId=${ categoryId } ` ) ;
207+ }
195208
196- const result = ghJson < {
197- data : { repository : { discussions : { nodes : RawDiscussion [ ] } } } ;
198- } > ( args ) ;
209+ if ( endCursor ) {
210+ args . push ( '-f' , `after= ${ endCursor } ` ) ;
211+ }
199212
200- if ( ! result . ok ) return result ;
213+ const result = ghJson < {
214+ data : {
215+ repository : {
216+ discussions : {
217+ nodes : RawDiscussion [ ] ;
218+ pageInfo : { hasNextPage : boolean ; endCursor : string | null } ;
219+ } ;
220+ } ;
221+ } ;
222+ } > ( args ) ;
223+
224+ if ( ! result . ok ) return result ;
225+
226+ const discussions = result . data ?. data ?. repository ?. discussions ;
227+ const nodes = discussions ?. nodes ?? [ ] ;
228+ allNodes . push ( ...nodes ) ;
229+
230+ const pageInfo = discussions ?. pageInfo ;
231+ hasNextPage = pageInfo ?. hasNextPage ?? false ;
232+ endCursor = pageInfo ?. endCursor ?? null ;
233+ }
201234
202- const nodes = result . data ?. data ?. repository ?. discussions ?. nodes ?? [ ] ;
203- return { ok : true , data : nodes . map ( mapDiscussion ) } ;
235+ return { ok : true , data : allNodes . map ( mapDiscussion ) } ;
204236}
205237
206238export function getDiscussion (
0 commit comments