You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Patch mongodb datasource to correctly type the mongoose model
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
0 commit comments