-
Notifications
You must be signed in to change notification settings - Fork 64
Closed
Description
I've implemented the example code, however when the resolver hits the data source, this error pops up
TypeError: collection.find(...).toArray is not a function
at _dataloader.default.ids (E:\test-graphql\node_modules\apollo-datasource-mongodb\dist\cache.js:31:6)
at dispatchQueueBatch (E:\test-graphql\node_modules\apollo-datasource-mongodb\node_modules\dataloader\index.js:246:22)
at dispatchQueue (E:\test-graphql\node_modules\apollo-datasource-mongodb\node_modules\dataloader\index.js:233:5)
at E:\test-graphql\node_modules\apollo-datasource-mongodb\node_modules\dataloader\index.js:70:20
at process._tickCallback (internal/process/next_tick.js:61:11)
This is how I create the data source in it's own file
const { MongoDataSource } = require("apollo-datasource-mongodb");
class ProductPages extends MongoDataSource {
getProductPage(id) {
return this.findOneById(id);
}
}
exports.ProductPagesDataSource = new ProductPages(ProductPageModel);
This is how I add it to the ApolloServer
const { ProductPagesDataSource } = require("../graphql/schema/schema");
const app = new ApolloServer({
...
dataSources: () => ({
productPages: ProductPagesDataSource
})
});
And in the resolver I call it like this (I use graphql-compose with graphql-compose-mongoose for my schema, but that shouldn't be an issue since I can make it work using the DataLoader package)
schemaComposer.Query.addFields({
page: ProductPageSchema.get("$findById").wrapResolve(next => rp => {
return rp.context.dataSources.productPages.getProductPage(rp.args._id);
})
});
What am I doing wrong?
Metadata
Metadata
Assignees
Labels
No labels