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
I'm setting up a stack that includes Typescript, Mongoose, and GraphQL so I was hoping to get the type safety of TS while keeping everything DRY by having my Mongoose schema be my absolute source of truth for types. However, it seems like ts-mongoose's approach to generating the schema conflicts with the way graphql-compose-mongoose converts Mongoose schemas to GraphQL types. A tiny case to reproduce the issue:
I dug into it and narrowed down the problem a bit. It seems that in order for graphql-compose-mongoose to generate types properly, nested fields like name in this example need to have User.schema.paths['name'].instance equal to Embedded. However, when generating the schema using ts-mongoose, the instance property ends up being Mixed instead, at which point graphql-compose-mongoose gives up trying to figure out the nested type and just calls it a JSON blob.
I don't think I have enough of an understanding of mongoose to know the solution though.
The text was updated successfully, but these errors were encountered:
bibekg
changed the title
graphql-compose-mongoose can't generate useful types
graphql-compose-mongoose can't generate useful types for nested objects
Apr 16, 2020
In case you figure this out with ts-mongoose or typegoose, I've also been trying to have a single source of truth, but can't seem to find a way to define GraphQL schema comments for types, queries, and query parameters, other than by actually writing out a GraphQL schema. Any ideas?
I'm setting up a stack that includes Typescript, Mongoose, and GraphQL so I was hoping to get the type safety of TS while keeping everything DRY by having my Mongoose schema be my absolute source of truth for types. However, it seems like ts-mongoose's approach to generating the schema conflicts with the way graphql-compose-mongoose converts Mongoose schemas to GraphQL types. A tiny case to reproduce the issue:
I then try to generate my GraphQL schema from this schema as follows
I'd expect the generated types to include definitions for both
User
andUserName
(the nested name object)but instead I get unhelpful
JSON
types likeI dug into it and narrowed down the problem a bit. It seems that in order for graphql-compose-mongoose to generate types properly, nested fields like
name
in this example need to haveUser.schema.paths['name'].instance
equal toEmbedded
. However, when generating the schema using ts-mongoose, theinstance
property ends up beingMixed
instead, at which point graphql-compose-mongoose gives up trying to figure out the nested type and just calls it aJSON
blob.I don't think I have enough of an understanding of mongoose to know the solution though.
The text was updated successfully, but these errors were encountered: