Is it possible to create a Union type in the MongoDB GraphQL API? E.g.
union SearchResult = Book | Author
type Book {
title: String!
}
type Author {
name: String!
}
type Query {
search(contains: String): [SearchResult!]
}
Then query that union using inline fragments:
query GetSearchResults {
search(contains: "Shakespeare") {
__typename
... on Book {
title
}
... on Author {
name
}
}
}
I have the need to return an array of two object types from a search query.