Skip to content

Commit

Permalink
Patch mongodb datasource to correctly type the mongoose model
Browse files Browse the repository at this point in the history
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
  • Loading branch information
J J Walwyn committed Sep 21, 2022
1 parent 650dab9 commit af81b78
Show file tree
Hide file tree
Showing 4 changed files with 577 additions and 2 deletions.
Loading

0 comments on commit af81b78

Please sign in to comment.