-
With Apollo, resolvers are allowed to return partial data, which is then fed into the object type resolver to fill in the rest. For example: const resolvers = {
Query: {
getHuman(_, { id }) {
const human = readFromDb(id);
// {
// id: id,
// age: 26,
// height: 123,
// }
return human;
},
Human: {
friends({ id }) {
const friends = friendsOf(id);
// [{id: 'friend-1-id'}, {id: 'friend-2-id'}, ...]
return friends;
},
},
},
}; However, if the schema defines export type Human = {
__typename?: 'Human';
id: Scalars['ID'];
age: Scalars['Number'];
height: Scalars['Number'];
friends: Array<Human>;
}; Of course, the At this point, I don't know how to proceed: TS is rightfully reporting a type mismatch. How do I make this work? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 3 replies
-
Actually GraphQL in general allows you to return any kind of data in resolvers. So that's why we have |
Beta Was this translation helpful? Give feedback.
Actually GraphQL in general allows you to return any kind of data in resolvers. So that's why we have
mappers
to let specify the types for those.https://graphql-code-generator.com/docs/plugins/typescript-resolvers#mappers---overwrite-parents-and-resolved-values