Open WEeziel172 opened 3 years ago
It quite simple, just read datasources from context
and use as usual in resolve
methods:
// add Fields to Query
schemaComposer.Query.addFields({
user: {
type: UserTC,
args: { id: 'Int' },
resolve: (_, { id }, { dataSources: { users } }) => users.getUser(id)
}
});
// add relation between types
PostTC.addFields({
author: {
type: () => UserTC,
resolve: (post, _, { dataSources: { users } }) => users.getUser(post.authorId),
},
})
Thanks for your input!
Is there any reason not to use some of the available mongoose resolvers in the actual datasource class? For example: We would have a users datasource. Some of the data comes from and external API, and some could be fetched straight from the database. Could we use mongoose resolvers from UserTC inside the datasource if needed?
Hey!
Are there any examples of using this library with apollo datasources? Could it be feasable to use some of the resolvers in a custom datasource if needed?