robsontenorio/vue-api-query

Discussion about array format breaking change

Closed this issue ยท 1 comments

There is a discussion about 6098689 introducing a breaking change in the array format when parsing the query. After reading the reported issues (see #214) and making some tests, I can confirm that it indeed changes the array formatting, but for custom parameters only. This is not a bad thing at all as per our documentation, this was our intended behaviour in the first place. Our goal is to match spatie/laravel-query-builder.

In the custom parameters docs we have the following example:

const posts = await Post.params({
  doSomething: 'yes',
  process: false,
  multiple: ['awesome', 'amazing', 'super']
}).get()

Which should parse to:
See spatie/laravel-query-builder filtering docs

GET /posts?doSomething=yes&process=false&multiple=awesome,amazing,super

But it was actually parsing to:

GET /posts?doSomething=yes&process=false&multiple[0]=awesome&multiple[1]=amazing&multiple[2]=super

So as you can see here, the commit 6098689 fixes the behaviour to parse as the documentation.

But I understand that this can lead to issues for some use cases, so the best thing to do is adding an option to change the parser array format.

There was an attempt to add this option, see #248. The forked repo is currently unavailable, so I'm reproducing these changes locally and will be opening a new PR.

One thing to note though is that by changing the array format to indices, it will not only change the custom parameters, but the parsing of all methods. For example, the whereIn method with nested params will be parsed to:

const posts = await Post.whereIn(['user', 'status'], [
  'active', 'inactive'
]).get()
GET /posts?filter[user][status][0]=active&filter[user][status][1]=inactive

cc @robsontenorio

๐ŸŽ‰ This issue has been resolved in version 1.11.0 ๐ŸŽ‰

The release is available on:

Your semantic-release bot ๐Ÿ“ฆ๐Ÿš€