Releases

v1.11.0 11/21/2022

Features

v1.10.0 7/5/2022

Bug Fixes

  • parser: fix behaviour when stringifying arrays (6098689), closes #214

Features

  • builder: add when method (8f08c8f), closes #219
  • builder: add support to pass an object as argument in where and whereIn methods (d77b365), closes #205

v1.9.1 5/25/2021

Bug Fixes

  • model: merge request config recursively (dc617da)
  • model: prevent request config from ditching private data (#185) (4b12b18)
  • model: throw an error if operations are used with custom (#173) (eef91b1), closes #172

v1.9.0 1/17/2021

Bug Fixes

Features

v1.8.2 12/4/2020

Bug Fixes

  • builder: multiple nested filters were not working (#154) (72de598)
  • builder: use typeof instead of constructor for checks (644ab4e)

v1.8.1 11/10/2020

Bug Fixes

  • deps: add missing dependency qs (80a7636)

v1.8.0 11/10/2020

Features

  • builder: accept array for include, append and orderBy (#148) (0d7ac00)
  • builder: add support to nested filters (#141) (faf3d1e)
  • model: add methods with, all and $all (#147) (db39511)
  • model: add support to configuration at query builder (#142) (e46d63e)
  • model: add support to upload files (#143) (a93cf5e), closes #83

v1.7.1 11/1/2020

Bug Fixes

  • model: fix typo in for error message (fbd2bca)

v1.7.0 10/31/2020

Features

  • model: handle 'data' wrapped responses for create and update (#109) (1bc6248) (@fadugyamfi)
  • model: add support to nested keys for relations (#127) (095c1c3) (@JoaoPedroAS51)

Bug Fixes

  • model: add null check in isValidId (#115) (279f9dc) (@guirociozanini)
  • model: relations are not being applied if any is null (#134) (92932cc) (@JoaoPedroAS51)

Docs

  • add new documentation website :tada: (#130) (e1afa2a) (@JoaoPedroAS51)

See https://robsontenorio.github.io/vue-api-query/

1.6.1 10/9/2020

Bump

Apply instances of relationships to nested objects. 10/9/2020

Thanks @JoaoPedroAS51 !

You can also apply a model instance to a nested object by setting the key and the model in relations method.

If the backend responds with:

// response from API for /posts/1
{
  title: 'My title'
  body: 'Some text here',
  user: {
    firstName: 'John',
    lastName: 'Doe'
  }
}

We just need to set user to User model:

/models/Post.js

class Post extends Model {
  relations () {
    return {
      // Apply User model to `user` object
      user: User
    }
  }
}

It also works for collections. So if the backend responds with:

// response from API for /comments
{
  text: 'Some text here',
  user: {
    firstName: 'John',
    lastName: 'Doe'
  },
  replies: [
    {
      text: 'A reply here',
      user: {
        firstName: 'Joe',
        lastName: 'Doe'
      }
    },
    {
      text: 'Another reply here',
      user: {
        firstName: 'Mary',
        lastName: 'Doe'
      },
      replies: [
        {
          text: 'Yes, this is the reply of the reply!',
          user: {
            firstName: 'Max',
            lastName: 'Doe'
          }
        }
      ]
    }
  ]
}

Then we just need to set user to User model and replies to Comment model:

/models/Comment.js

class Comment extends Model {
  relations () {
    return {
      // Apply User model to `user` object
      user: User,
      // Apply Comment model to each object of `replies` array
      replies: Comment
    }
  }
}

Fixes 5/15/2020

  • Update all dependencies
  • Small fix on README @manniL
  • Reset query string @MichMich
  • save() method makes a PUT request to the correct URL on nested object thas was fetched with find() method @taai

Thanks to @Peter-Krebs for reviewing.

Fix for $find to use a constructor on the result 5/2/2019

Thanks @rossity for #67

Add 'fetch' based methods: $first() and $find() 4/18/2019

Thanks @leeovery for #61.

Introduces new fetch style request for find() and first() methods. See README for more info.

let user = await User.$find(1)

let user = await User.$first()

Fix custom resources baseURL() 2/27/2019

Thanks @peterquentin

The `custom()` method takes multiples parameters 2/24/2019

Thanks @Peter-Krebs

The custom() method can be called with multiple arguments to build resource endpoints and hierarchies. Simply supply them in the correct order. Any combination of strings and models is possible.

    let user = new User({ id: 1 })
    let post = new Post()

    // GET /users/1/posts/latest
    const result = await Post.custom(user, post, 'latest').get()

Improvements and fixes 2/18/2019

Update dependencies

Updated to latest babel and eslint features.

Added ability to customize query parameter names

If you need to change default values just override parametersName() on your Base Model. So, the generated query string will use this new values.

import { Model as BaseModel } from 'vue-api-query'

export default class Model extends BaseModel {

  parameterNames () {
    return {
      include: 'include_custom',
      filter: 'filter_custom',
      sort: 'sort_custom',
      fields: 'fields_custom',
      append: 'append_custom',
      page: 'page_custom',
      limit: 'limit_custom'
    }
  }
}

Thanks @suth https://github.com/robsontenorio/vue-api-query/pull/42

Fix array strategy validation for SSR

Got error on using vue-api-query with NUXT on universal mode (SSR)

Thanks @MisterEffix https://github.com/robsontenorio/vue-api-query/pull/43

The `for()` method can take multiple objects to build hierarchy levels. 11/22/2018

 let user = new User({id: 1})
 let post = await user.posts().first()

 // Related objects go in order of their appearance in the URL.
 let comment = new Comment({text: 'for() takes multiple objects.'}).for(user, post)
  // POST /users/1/posts/1/comments
 await comment.save()

.for() should use object.getPrimaryKey() 10/31/2018

find() method for nested resources 7/26/2018

If you need to get a nested resource, without getting the parent model at first, you can do something like this.

// GET /users/1/posts

let User = new User({id: 1})
let Post = await User.posts().get()

// GET /users/1/posts/2
let User = new User({id: 1})
let Post = await User.posts().find(2)

Stable release and for() method 7/16/2018

  • Tag 1.0.0 stable
  • for() method for creating new related objects

Creating new related objects is easy. Just use the for() method, passing the related object.

  let post = new Post({title: 'Woo!'})  

  // POST /posts
  await post.save()

  let comment = new Comment({text: 'New one for this post'}).for(post)

  // POST /posts/1/comments
  await comment.save()

Custom params 6/5/2018

If you need to pass any extra param not provided by vue-api-query pattern, just use the params() method while querying:

// GET /users?doSomething=yes&process=no

let users = await User
  .params({
    doSomething: 'yes',
    process: 'no'
  })
  .get()

Of course you can chain it with other methods, including on relationships.

// GET /posts/1/comments?include=user&blah=123

let comments = await post
  .comments()
  .include('user')
  .params({blah: 123})
  .get()

Add `primaryKey()` method. 5/16/2018

In case your model does not work with default primary key ('id').

0.5.0 4/11/2018

Support PUT, POST, DELETE for nested relationships

0.4.1 4/6/2018

Fix internal variable name

0.4.0 4/5/2018

  • Add select() for sparse fields

  • Remove find() restriction for integers

0.3.0 3/31/2018

  • add delete() method

0.2.0 3/30/2018

  • add "fetch style request" with $get()
  • add pagination with page() and limit()