Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

graphql-compose-mongoose with Typescript without extending Document #414

Open
fotAlat opened this issue Sep 16, 2022 · 2 comments
Open

graphql-compose-mongoose with Typescript without extending Document #414

fotAlat opened this issue Sep 16, 2022 · 2 comments

Comments

@fotAlat
Copy link

fotAlat commented Sep 16, 2022

I was interested in using the library because i found it very handy in terms of translating Mongoose Schemas to GraphQLObjects. I was blown away by how good it works but i noticed something. In models that we use Typescript interfaces it complains if I do not use the Extends Documents in the interface.

Is there any reason why we should use the extends Document when the mongoose Documentation recommends against that?

https://mongoosejs.com/docs/typescript.html

@TubbyStubby
Copy link

TubbyStubby commented Jul 9, 2023

Would it be a good idea to hack it like this?

type IUser = InferSchemaType<typeof userSchema>;

const User = mongoose.model('User', userSchema);

const UserTC = composeMongoose(User as unknown as Model<Document<IUser>>, {});

@tatejones
Copy link

tatejones commented Oct 31, 2023

I have a similar issue when attempting to use a model from typegoose when the class/interface (eg. User) doesn't extend document.

const userModel = getModelForClass(User)
const UserModelTC = composeMongoose(userModel)

Argument of type 'ReturnModelType<typeof User, BeAnObject>' is not assignable to parameter of type 'Model<Document<any, any, any>, {}, {}, {}, Document<unknown, {}, Document<any, any, any>> & Document<any, any, any> & { _id: ObjectId; }, any>'.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants