@@ -321,18 +321,18 @@ func (b *Builder) createGenericRecordsResolver() graphql.FieldResolveFn {
321321 }
322322 after , _ := p .Args ["after" ].(string )
323323
324- // Decode cursor to URI if provided
325- var afterURI string
324+ // Decode cursor to timestamp if provided
325+ var afterTimestamp string
326326 if after != "" {
327327 var err error
328- afterURI , err = decodeCursor (after )
328+ afterTimestamp , err = decodeCursor (after )
329329 if err != nil {
330330 return nil , fmt .Errorf ("invalid cursor: %w" , err )
331331 }
332332 }
333333
334- // Query database with cursor
335- records , err := repos .Records .GetByCollectionWithCursor (p .Context , collection , first + 1 , afterURI )
334+ // Query database with cursor (ordered by indexed_at DESC)
335+ records , err := repos .Records .GetByCollectionWithCursor (p .Context , collection , first + 1 , afterTimestamp )
336336 if err != nil {
337337 return nil , fmt .Errorf ("failed to query records: %w" , err )
338338 }
@@ -354,7 +354,8 @@ func (b *Builder) createGenericRecordsResolver() graphql.FieldResolveFn {
354354 value = map [string ]interface {}{"raw" : rec .JSON }
355355 }
356356
357- cursor := encodeCursor (rec .URI )
357+ // Use indexed_at as cursor for chronological pagination
358+ cursor := encodeCursor (rec .IndexedAt .Format ("2006-01-02 15:04:05" ))
358359 if startCursor == "" {
359360 startCursor = cursor
360361 }
@@ -404,18 +405,19 @@ func (b *Builder) createCollectionResolver(lexiconID string) graphql.FieldResolv
404405 first = 20
405406 }
406407
407- // Decode cursor to URI if provided
408- var afterURI string
408+ // Decode cursor to timestamp if provided
409+ var afterTimestamp string
409410 if after != "" {
410411 var err error
411- afterURI , err = decodeCursor (after )
412+ afterTimestamp , err = decodeCursor (after )
412413 if err != nil {
413414 return nil , fmt .Errorf ("invalid cursor: %w" , err )
414415 }
415416 }
416417
417418 // Query database with cursor (fetch one extra to determine hasNextPage)
418- records , err := repos .Records .GetByCollectionWithCursor (p .Context , lexiconID , first + 1 , afterURI )
419+ // Ordered by indexed_at DESC for chronological display
420+ records , err := repos .Records .GetByCollectionWithCursor (p .Context , lexiconID , first + 1 , afterTimestamp )
419421 if err != nil {
420422 return nil , fmt .Errorf ("failed to query records: %w" , err )
421423 }
@@ -441,7 +443,8 @@ func (b *Builder) createCollectionResolver(lexiconID string) graphql.FieldResolv
441443 data ["uri" ] = rec .URI
442444 data ["cid" ] = rec .CID
443445
444- cursor := encodeCursor (rec .URI )
446+ // Use indexed_at as cursor for chronological pagination
447+ cursor := encodeCursor (rec .IndexedAt .Format ("2006-01-02 15:04:05" ))
445448 if startCursor == "" {
446449 startCursor = cursor
447450 }
0 commit comments