Multiple Queries using Apollo Client and React

Viewed 577

I first started using GraphQL, because I had read that all information could be gathered with a single query. This is in contrast to a REST server where the browser may need to make several trips to the API / Server.

I am now relying on the useQuery hook in Apollo Client. I want to get an ID from one database and then look up the respective name, based on that ID, in another database. Ideally, the client would only make a single request to the API / Server.

I can't seem to find any information on Stack Overflow or in the Apollo documentation. Can someone please provide insight?

1 Answers

API that you're fetching must be configured correct so it could resolve your query and link id from one database and entity info from another one.

Ideally, your query should look like this

query someQueryName($id: ID!) {
  getEntityInfo(id: $id) {
    name
    someOtherProperties
  }
}

And then API has to handle this query using provided databases

Related