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
Before all, i've been fiddling with this library for a few months now, thank you for putting work into it ! That's a really nice idea.
I've noticed a small issue with how mongoose is handling types on their side : a mongoose path can be either declared as a reference to the subschema directly or as the name of the custom type (if registered in mongoose beforehand)
This leads to compose-mongoose not being able to pick up a custom type and typing it as JSON.
Here a example you can run, the main thing to notice being the declaration of UserProfile and Article schemas :
importmongoose,{Schema}from'mongoose';import{schemaComposer}from'graphql-compose';// get the default schemaComposer or your created schemaComposerimport{convertSchemaToGraphQL}from'graphql-compose-mongoose';import{composeMongoose}from'graphql-compose-mongoose';// the embedded schemaconstImageDataStructure=newSchema({url: String,dimensions : {width: Number,height: Number}},{_id: false});// A class declaration of a schemaType so mongoose is pleasedclassIMGextendsmongoose.SchemaType{constructor(key: string,options: any){super(key,options,'ImageDataStructure');}cast(val: any){returnval;}}/* @ts-ignore */mongoose.SchemaTypes["ImageDataStructure"]=IMGconstUserProfile=newSchema({fullName: String,personalImage: ImageDataStructure});constArticle=newSchema({title: String,heroImage: "ImageDataStructure"});convertSchemaToGraphQL(ImageDataStructure,'ImageDataStructure',schemaComposer);// Force this type on this mongoose schemaconstUserProfileModel=mongoose.model('UserProfile',UserProfile);constArticleModel=mongoose.model('Article',Article);constUserProfileTC=composeMongoose(UserProfileModel);constArticleTC=composeMongoose(ArticleModel);schemaComposer.Query.addFields({userById: UserProfileTC.mongooseResolvers.findById(),articleById: ArticleTC.mongooseResolvers.findById(),})schemaComposer.buildSchema()console.log(schemaComposer.toSDL())
Which lead to the following output (truncated) :
type Article {
title: String
heroImage: JSON
_id: MongoID!
}
type ImageDataStructure {
url: String
dimensions: ImageDataStructureDimensions
}
type ImageDataStructureDimensions {
width: Float
height: Float
}
type UserProfile {
fullName: String
personalImage: ImageDataStructure
_id: MongoID!
}
UserProfile.personalImage is correct (as a ImageDataStructure) while Article.heroImage is typed as JSON.
Did i miss something to get this to work properly ?
Have a good day !
The text was updated successfully, but these errors were encountered:
Hello !
Before all, i've been fiddling with this library for a few months now, thank you for putting work into it ! That's a really nice idea.
I've noticed a small issue with how mongoose is handling types on their side : a mongoose path can be either declared as a reference to the subschema directly or as the name of the custom type (if registered in mongoose beforehand)
This leads to compose-mongoose not being able to pick up a custom type and typing it as
JSON
.Here a example you can run, the main thing to notice being the declaration of
UserProfile
andArticle
schemas :Which lead to the following output (truncated) :
UserProfile.personalImage
is correct (as aImageDataStructure
) whileArticle.heroImage
is typed as JSON.Did i miss something to get this to work properly ?
Have a good day !
The text was updated successfully, but these errors were encountered: