twitchtv / igdb-api-node

Nodejs Wrapper for IGDB.com API. Requires an API key. Get one at:
https://api.igdb.com/
MIT License
128 stars 15 forks source link

request-endpoint: fields are processed and appended to the query string multiple times #19

Closed dsibilly closed 7 years ago

dsibilly commented 7 years ago

When there are multiple query options and a fields Array passed to request-endpoint, the fields Array is processed once for each option and appended to the query string result, such that requests like:

client.release_dates({
  filters: {
    'game-eq': 38722
  },
  expand: 'platform,game',
  limit: 50
}, [ 'human', 'region', 'platform.name', 'game.name', 'game.cover.url' ])
.then(response => { this.setState({ games: response.body }); })
.catch(error => { throw error; });

...results in a request url of https://igdbcom-internet-game-database-v1.p.mashape.com/release_dates/?filter[game][eq]=38722&fields=human,region,platform.name,game.name,game.cover.url&expand=platform,game&fields=human,region,platform.name,game.name,game.cover.url&limit=50&fields=human,region,platform.name,game.name,game.cover.url

The fields array should be processed separately from the options, or a sentinel set to that it is only processed and appended to the query string once.

Reported by @Cohaven in #16