Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handling Multiple Objects from Single Query? #15

Closed
irelandpaul opened this issue Dec 7, 2016 · 1 comment
Closed

Handling Multiple Objects from Single Query? #15

irelandpaul opened this issue Dec 7, 2016 · 1 comment

Comments

@irelandpaul
Copy link

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!

@irelandpaul
Copy link
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
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant