playlist tracks iterator not iterating
jopek opened this issue · comments
hello!
based on the https://github.com/wittydeveloper/spotify-fetch-my-playlists I am trying to fetch a particular playlist.
const config = {
accessToken: "<<TOKEN>>"
}
SpotifyGraphQLClient(config).query(`
{
playlist(userId: "1128723762", id: "2YARXniaJywrRZbbQeSoAi") {
id
name
tracks {
track {
id
name
artists {
id,
name
}
album {
id,
name
}
}
}
}
}
`).then(executionResult => {
if (executionResult.errors) {
console.log('error');
console.error(JSON.stringify(executionResult.errors));
} else {
console.log('success');
console.log(JSON.stringify(executionResult.data, null, 2));
console.log("number of tracks:", executionResult.data["playlist"].tracks.length);
}
})
the number of tracks returned is 50. it should be 1133.
when debugging, i see that the initial response contains the 50 elements, a next
url is also available, the offset iterator's offset is also incremented, only does the iterator not seem to be used afterwards.
what am i doing wrong?
Hi @jopek,
Thanks for using spotify-graphql
🎉
I found what is missing in your query.
In order to tell to spotify-graphql
to iterate until the last records, you should pass limit: -1
to tracks()
in order to explicitly say (dump everything, even if it's a large collection).
This "hack" is here to prevent the GraphQL server to fetch everything automatically.
I agree that this feature should be documented, sorry for the inconvenience 🙇
So, in short, your query should be:
{
playlist(userId: "1128723762", id: "2YARXniaJywrRZbbQeSoAi") {
id
name
tracks(limit: -1) {
track {
id
name
artists {
id,
name
}
album {
id,
name
}
}
}
}
}
Tip: in the future, you can use the interactive test console to test queries with real Spotify data 😉
Cheers,
Follow-up issue: #63
@wittydeveloper thank you very much for the super quick response and for this project!
setting the limit to -1 did the trick! ☀️