Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
declare module 'apollo-datasource-mongodb' {
import { DataSource, DataSourceConfig } from 'apollo-datasource'
import * as mongoose from 'mongoose'

export {
DataSourceConfig
}

interface Options { ttl: number }

export abstract class MongoDataSource<T extends mongoose.Document, TContext = any> extends DataSource {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
export abstract class MongoDataSource<T extends mongoose.Document, TContext = any> extends DataSource {
export abstract class MongoDataSource<T extends mongoose.Document, TContext = any> extends DataSource<TContext> {

DataSource is also a generic type, which optionally takes in the context type, which is what we should do imo.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, I don't think the collection type makes these typings compatible with the native mongodb connector, which has a generic type for collection

collection: mongoose.Collection
model?: mongoose.Model<T>
constructor(collection: mongoose.Collection | mongoose.Model<T>)
public initialize(config: DataSourceConfig<TContext>): void
protected findOneById(id: string, { ttl }?: Options): T | null
protected findManyByIds(ids: string[], { ttl }?: Options): (T| null)[]
Copy link
Collaborator

@9at8 9at8 Dec 28, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The ids are supposed to be ObjectIds, at least for the native driver. Can you confirm @lorensr ?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes. And if it comes in as a string argument, I use this function to convert:

image

protected deleteFromCacheById(id: string): void
}
}