Considering such query:
xxxxxxxxxx
{
search(keyword: "car") {
... on Product {
name
price
}
... on Category {
itemsCount
avgProductPrice
Search field return union of Product and Category. To define such union we need to use @Union decorator
Product
Category
@Union
import { ObjectType, Field, Union } from 'decapi'
@ObjectType()
class Product {
@Field()
name: string
price: number
class Category {
itemsCount: number
avgProductPrice: number
@Union({ types: [Product, Category] })
class SearchResult {}