We are working on quite a complicated GraphQL schema where we have several object types that belong to various micro services, where each object type has a natural API endpoint we can query. Therefore it would be quite convenient if it would be possible to define specific resolvers for certain object types directly, doing something like this:
const typeDefs = gql`
type Query {
getBook(bookId: ID!): BookPayload
}
type BookPayload {
book: Book
userErrors: UserError
}
type Book {
id: ID!
title: String
author: String
}
`;
const resolvers = {
Query: {
getBook: (parent, args, context, info) => {
return {
book: { id: args.bookId }
}
},
Book: (parent) => { // this object type level resolver doesn't seem to work
return {
id: parent.id,
...fetchBookMetadata(parent.id)
};
}
};
I understand this is a trivial example and might seem a bit over engineered, but it does make more sense (at least for us) when the schema starts becoming very complicated with hundreds cross references all over the place. Is there a good way to solve this right now?