How to merge results from two gql queries in to one array of results?

228 Views Asked by At

We have two services exposing two sets of schemas, merged in a gateway using Graphql Tools Schema Stitching

Is it possible to merge queries from two services in such a way that it returns combined results? Example case:

Book service contains data for books

interface Searchable {
 id: ID!
} 

type Book implements Searchable {
  id: ID!
  name: String
  # other fields
}

type Query {
 _search( term: String ): [Searchable]
}

User Service has the data for authors

interface Searchable {
 id: ID!
} 

type Author implements Searchable {
  id: ID!
  name: String
  # other fields
}

type Query {
 _search( term: String ): [Searchable]
}

Gateway


interface Searchable {
 id: ID!
} 

type Book implements Searchable {
  id: ID!
  name: String
  # other fields
}


type Author implements Searchable {
  id: ID!
  name: String
  # other fields
}

type Query {
 search( term: String ): [Searchable]
}
1

There are 1 best solutions below

1
Gil Gardosh On

I can recommend using GraphQL-Mesh - it uses tools under the hood, and enables you to easily merge multiple sources (GraphQL and many others), manipulate it and get one GraphQL endpoint / schema