-
Notifications
You must be signed in to change notification settings - Fork 65
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
TypeScript Error: Argument of type 'Model<T, {}, {}, {}>' is not assignable to parameter of type 'Collection<T>'. #88
Comments
I'm having similar error |
I have found a workaround for this but it is discouraged by Mongoose documentation here. Workaround is to extend your interface with Document:
I am not good with TypeScript so I just don't know how to fix this in library. But, I think we need to do something here: https://github.com/GraphQLGuide/apollo-datasource-mongodb/blob/master/index.d.ts#L18 |
I'd be happy to look at a PR for this! |
I tried using the same mongoose version for my application as specified for |
Ok, so I really didn't want to do this. It was a last resort... apollo-datasource-mongodb supports mongoose fine, in javascript. But the typing expects the model object type to extend Document from mongoose, so that it determine it to be a mongoose model, rather than a mongodb collection. But - not only is this recommended against, but it is not easily supported without a tonne more hacks whilst using codegen to generate the types based off of GraphQL types... As overriding types was not possible (in src/@types/environment.d.ts), only extending, this commit creates a package patch which removes the type inferrence and forces the datasource constructor parameter to be a Mongoose Model. This doesn't fix the root problem, that will have to be done on the type inferrence - ModelOrCollection. But I can safetly assume that we'll never use mongodb collections here - just mongoose models. 🫠V see: https://mongoosejs.com/docs/typescript.html#using-extends-document see: GraphQLGuide/apollo-datasource-mongodb#88
Ok, so I really didn't want to do this. It was a last resort... apollo-datasource-mongodb supports mongoose fine, in javascript. But the typing expects the model object type to extend Document from mongoose, so that it determine it to be a mongoose model, rather than a mongodb collection. But - not only is this recommended against, but it is not easily supported without a tonne more hacks whilst using codegen to generate the types based off of GraphQL types... As overriding types was not possible (in src/@types/environment.d.ts), only extending, this commit creates a package patch which removes the type inferrence and forces the datasource constructor parameter to be a Mongoose Model. This doesn't fix the root problem, that will have to be done on the type inferrence - ModelOrCollection. But I can safetly assume that we'll never use mongodb collections here - just mongoose models. 🫠V see: https://mongoosejs.com/docs/typescript.html#using-extends-document see: GraphQLGuide/apollo-datasource-mongodb#88
I am getting this weird typescript error when I put Mongoose Model in constructor.
My Listing Model is defined like this:
My Mongoose Model is defined like this:
My Listing Interfact is defined like this:
But when I pass my Mongoose Model to DataSource based class. I get following TypScript error:
I have tried many ways but this is not getting solved.
The text was updated successfully, but these errors were encountered: