Hello, let’s say for example I want to make a search for my site, and I have books and posts, both objects have the same fields (author, title), how can I make it with a union?
On the docs I found this, isn’t it a bit odd to have to check if some fields are in the object? what if I have a lot of objects, what if some objects have the exact same field? Is there a better alternative to resolve a union than this?
const resolvers = {
Result: {
__resolveType(obj, context, info){
if(obj.name){
return 'Author';
}
if(obj.title){
return 'Book';
}
return null; // GraphQLError is thrown
},
},
Query: {
search: () => { ... }
},
};
Thanks.