I had issues with apollo-datasource-mongodb when using mongoose so I've decided to make my own data source: @dariuszp/apollo-datasource-mongoose. Feedback would be welcome

This is something I started like 2 nights ago.

I needed something that can use the latest mongoose and not cause me issues. It’s still in early development. My tests use a real database so I use docker-compose.yml to run them because I had no time to mock mongoose. In near future, I will try to mock mongoose for testing. Any tips and tricks how to do that efficiently are welcome.

The cache is very basic. If enabled and configured it will pull parameters and populated fields from passed query and cache response for X seconds as documented. There are 3 build-in methods in the data source:

public find(filters: FilterQuery<T> = {}, page: number = 1, onPage: number = 10, sort: string | { [key: string]: SortOrder | { $meta: 'textScore' } } | undefined | null = undefined): Promise<T[]>
public findById(objectId: ObjectId | string): Promise<T | null>
protected cache(query: QueryWithHelpers<any, T>, options?: KeyValueCacheSetOptions): Promise<any>

When you write a custom method, you have to use method this.cache() on the query to make sure your method takes advantage of the cache.
I was thinking about messing with methods in the constructor but I kinda hate such an approach. I rather just give the devs a method and let them decide. And this way if you need custom cache logic - you got it. It’s up to you.

All examples are in typescript. I wonder if I should make a separate section for typescript and write the most basic examples in pure JS.

Ive limited my dependencies to:

And there is 2 peer dependencies:

Anyway, I would be grateful for any feedback, criticism, etc.