Handling Multiple Objects from Single Query? · Issue #15 · vuejs/apollo · GitHub
Skip to content

Handling Multiple Objects from Single Query? #15

Closed

Description

@irelandpaul

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!

Activity

  1. irelandpaul commented on Dec 8, 2016

    @irelandpaul
    Author

    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
                    
                }
             }
    
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions