vuejs/apollo

Handling Multiple Objects from Single Query?

irelandpaul opened this issue · 1 comments

Is there a way to map multiple objects from a single query? It currently seems to expect one object to equal one query.

Right now it seems that I either need to do multiple queries, like below (my queries are defined as constants elsewhere). This results in two queries or I can turn on batch to do one query but that requires changing our backend to accommodate that batched format (we are not using Apollo Server).

apollo: {
         clients: {
            query: clientQuery,
            loadingKey: 'loading'
         }
         ,
         client_statuses: {
            query: clientStatusesQuery,
            loadingKey: 'loading'
         } 
    }

or I have to use the Apollo Client directly to separate it out, like below.

  created() {
    this.$apollo.query({
      query: clientsAndStatusesQuery
    })
    .then(result => {
      this.clients = result.data.clients
      this.client_statuses = result.data.client_statuses
    });
  },

Another note, in the example it says to use watchQuery. I get "Uncaught TypeError: this.$apollo.watchQuery(...).then is not a function(…)". But just "query" works fine.

Any help would be appreciated! Thank you!

I've answered my own question by using the result hook

    apollo: {
         clients: {
            query: clientsQuery3(),
            loadingKey: 'loading',
            result(data) {
                this.clients = data.clients
                this.client_statuses = data.client_statuses
                
            }
         }