Floby/node-url-assembler

Can't build multiple query

Closed this issue · 5 comments

we can't build add multiple query :(

example this init code

const foo = UrlAssembler()
  .template('/users/:user')
  .param('user', 8)
  .param('include', 'address')
  .query({
    some: 'thing',
    other: 1234
  })
  .toString() // => "/users/8?include=address&some=thing&other=1234

foo.query('alpha', 'beta'); // this additional query will not added :(

I were expecting we can continuously add more URL query 😭

Floby commented

[EDIT]
Hello, I cannot replicate this bug. Here's what I tried which seems to be what you were describing

      describe('when called after a multi query call', () => {
        beforeEach(() => {
          myUrl = myUrl
            .param('hello', 'world')
            .query({a: 8, b: true})
        })
        it('adds the new query parameter', () => {
          expect(myUrl.query('c', 'hey').toString()).to.equal('/hello?hello=world&a=8&b=true&c=hey')
        })
      })

@Floby thank you for your response and please pardon my late reply.
The issue on my side is happened because i'm trying to call .query() twice and the second call didn't add the queries.

Here is the example code with the execution which i think more clearer https://runkit.com/gusdecool/url-assembler-cant-build-multiple-query 🙏

.query() doesn't mutate the object, it returns a new one:

https://runkit.com/5b2bbe0e6bb7720012426f93/5b2bbe156bb7720012426f98

@alexfoxgill thank you, exactly what i mean.

Floby commented

I think what you are describing is intended. no mutation in previously defined urls. All method return a brand new instance. As a matter of fact, if you find a case where a mutation occurs, please report it as a bug ;)