charlypoly / spotify-graphql

GraphQL schema for Spotify WebAPI — TypeScript / Node.js (v6)

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Pagination goes into infinite loop when querying empty lists

Skogsfrae opened this issue · 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.

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

Hi @Skogsfrae,

Thanks for pointing this! 💯🙇

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

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

@wittydeveloper are you still maintaining this package?

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

Will take a look in spotify-graphql@4.0.0, cf: #79