Vue-apollo: Multiple data from one query

Created on 27 Mar 2018  路  4Comments  路  Source: vuejs/vue-apollo

Sorry for the title. Not sure how to describe it best.

I have following query:

query allPalettes ($first: Int, $skip: Int, $orderBy: PaletteOrderBy) {
  allPalettes(first: $first, skip: $skip, orderBy: $orderBy) {
    id
    title
    colors
    votes {
      id
      user {
        id
      }
    }
  }
  totalCount: _allPalettesMeta {
    count
  }
}

So there are two datasets allPallettes and totalCount.
However I am not sure how to grab them in vue-apollo.

For a single node that would be simply:

    apollo: {
      allPalettes: {
        query: ALL_PALETTES,
        variables: {
          skip: 0,
          first: PALETTES_PER_PAGE
        },
        loadingKey: 'loading'
      },

However this way I am not getting totalCount. It is working if I duplicate the query:

    apollo: {
      allPalettes: {
        query: ALL_PALETTES,
        variables: {
          skip: 0,
          first: PALETTES_PER_PAGE
        },
        loadingKey: 'loading'
      },
      totalCount: {
        query: ALL_PALETTES,
        variables: {
          skip: 0,
          first: PALETTES_PER_PAGE
        },
        loadingKey: 'loading'
      }

However this feels kind of wrong. Is there a better way?

Most helpful comment

Use result hook (see the docs).

All 4 comments

Use result hook (see the docs).

Thanks!

Use result hook (see the docs).

I got the same question but the link is out of date.
I think the documentation is now here: https://apollo.vuejs.org/api/smart-query.html#options

{
  query: gql`...`,
  manual: true,
  result ({ data, loading }) {
    if (!loading) {
      this.items = data.items
    }
  },
}

If I get it correctly, items should also manually be initialized in the data hook.

buen d铆a, hace algunos d铆as he estado trabajando con vue, laravel y apollo y me encontrado con el siguiente problema.

estoy trantando de hacer un OrderBy en mi consulta Graphql y hasta el momento todo funciona a nivel Graphql Playground
pero cuando quiero implementarlo con vue y apollo no he podido.

adjunto mi codigo quiza alguien pueda ayudarme.

graphql
vue

a nivel graphql si he podido devolver el OrderBy, pero a nivel de vue aun no logro conseguirlo. quiza alguien pueda ayudarme. saludos

Was this page helpful?
0 / 5 - 0 ratings

Related issues

dsbert picture dsbert  路  4Comments

beeplin picture beeplin  路  4Comments

danthareja picture danthareja  路  4Comments

dohomi picture dohomi  路  5Comments

sadhakbj picture sadhakbj  路  3Comments