Use typescript-mongodb plugin with TypeGraphQL #5393
-
On my GraphQL API I use TypeGraphQL and MongoDB. I want to use The documentation says to add const schema = makeExecutableSchema({
typeDefs: [
DIRECTIVES,
// the rest of your GraphQL types
],
resolvers,
}); But in TypeGraphQL the schema is declared without a typeDefs field: const schema = await buildSchema({
resolvers
}); Is there a way to use the Also, what exactly is adding |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
Hi @Merlin04 ! Regarding your question: Since this codegen plugin is using custom directives, you need to add it to your runtime, since otherwise you'll get an error. These directives are declarative only, and they don't have any runtime effect, it's just for making the schema valid and loadable. The Codegen plugin for mongodb uses these directives to detect which types should get a DB model and how. I'm not highly familiar with TypeGraphQL, but there is a logical issue with this integration you are trying to do - GraphQL codegen requires you to input a schema, and TypeGraphQL is the one that creates it. Can you please elaborate what are you trying to achieve, and how do you define your schema? |
Beta Was this translation helpful? Give feedback.
Hi @Merlin04 !
I'll start with a side note: the
typescript-mongodb
was an experiment we did a long time ago, aiming to use the GraphQL (API) layer as a place to declare the DB models. This was an idea, turned into an experiment.My personal take is that you shouldn't mix your DB models and your APIs, since in most cases, these are different and have differences that are not minor.
Regarding your question: Since this codegen plugin is using custom directives, you need to add it to your runtime, since otherwise you'll get an error. These directives are declarative only, and they don't have any runtime effect, it's just for making the schema valid and loadable. The Codegen plugin for mongodb…