spotify-graphql icon indicating copy to clipboard operation
spotify-graphql copied to clipboard

Pagination goes into infinite loop when querying empty lists

Open Skogsfrae opened this issue 6 years ago • 6 comments

When requesting a paginated resource with no values the paginator goes into an infinite loop of requests to the spotify api.

To reproduce the bug I made this query on a user with no public playlists

{
   user(id: "someid"){
    playlists{
      name
    }
  }
}

The api returns an empty list with total=0, but the !!iterator.total condition inside the shouldStopIterate function causes and infinite loop of requests.

Skogsfrae avatar Feb 19 '19 10:02 Skogsfrae

I published the first commit with a wrong email, then i amended it with the correct email, sorry 😅

Skogsfrae avatar Feb 19 '19 10:02 Skogsfrae

Hi @Skogsfrae,

Thanks for pointing this! 💯🙇

Please free to make a PR on this repo so I can review & publish it to npm 🚢

charlypoly avatar Feb 19 '19 11:02 charlypoly

I'm having the same problem can give an example to stop it from looping again and again. This is the result.

{
  "href" : "https://api.spotify.com/v1/users/31qkotz7ttscfyanfn4iktz4zcgi/playlists?offset=5950&limit=50",
  "items" : [ ],
  "limit" : 50,
  "next" : null,
  "offset" : 5950,
  "previous" : "https://api.spotify.com/v1/users/31qkotz7ttscfyanfn4iktz4zcgi/playlists?offset=5900&limit=50",
  "total" : 0
}

The next API call should be stopped if the next null and items are empty

pavittar95 avatar Jul 03 '20 13:07 pavittar95

@wittydeveloper are you still maintaining this package?

pavittar95 avatar Jul 06 '20 18:07 pavittar95

@pavittar95 you can use my fork containing the fix if you want. It's linked to this issue

Skogsfrae avatar Jul 07 '20 19:07 Skogsfrae

Will take a look in [email protected], cf: #79

charlypoly avatar Jan 11 '21 20:01 charlypoly