scalient / vuex-orm-json-api

A Vuex ORM adapter for JSON:API
Apache License 2.0
21 stars 4 forks source link

Response meta, links etc for pagination #1

Closed buckyflowers closed 2 years ago

buckyflowers commented 4 years ago

Hi there, nice job on this project. Been using it for a week or so and its been great. Is there any way to get the original jsonapi response from the server so I can access pagination and links?

carsomyr commented 4 years ago

@buckyflowers Glad you're seeing success with the library! Would attaching the original Axios response to the returned Object or Array suffice?

buckyflowers commented 4 years ago

Yes, that would be great! Thanks. That’s how the Vuex-ORM axioms plugin I was using is doing it, and they have an entities member with the upserted records, and it worked well for me.

https://github.com/vuex-orm/plugin-axios/blob/master/src/api/Response.ts

bytebrain commented 3 years ago

For the time being, I solved it by using the axios response interceptor. I use this create method in my Vue component:

  created () {
    // Add pagination detection to json-api calls.
    Product.jsonApi().axios.interceptors.response.use((response) => {
      if (response.status === 200 && response.config.url.indexOf('/api/private/products?') > -1) {
        this.productsApiCallMeta = response.data.meta.page;
      }
      return response;
    });
  },
ZachPerkitny commented 3 years ago

Any updates on this?

carsomyr commented 3 years ago

@buckyflowers @ZachPerkitny Sorry for the long pause: Work got in the way. In the coming months, I will most likely be releasing a companion library for handling pagination in line with the JSON:API spec. I'd imagine that it would take some design cues from vuex-pagination, with the twist that Vuex ORM records will be carrying pagination information like context, page, and offset from attributes mixed in by the pagination library.

carsomyr commented 2 years ago

Closing this, because I just addressed this in version 0.99: https://github.com/scalient/vuex-orm-json-api/blob/main/CHANGELOG.md#099-2022-11-01.