-
-
Notifications
You must be signed in to change notification settings - Fork 94
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
Type 'Cat' is not assignable to type 'Document<any, any, any>' #424
Comments
I found ansver on my 2 question export const UserSchema = SchemaFactory.createForClass(User);
const UserModel = mongoose.model<any>('User', UserSchema);
const UserTC = composeMongoose(UserModel, {});
schemaComposer.Query.addFields({
userById: UserTC.mongooseResolvers.findById(),
getUser: UserTC.mongooseResolvers.findOne(),
getAllUsers: UserTC.mongooseResolvers.findMany(),
});
schemaComposer.Mutation.addFields({
updateUser: UserTC.mongooseResolvers.updateOne(),
removeUser: UserTC.mongooseResolvers.removeOne(),
});
const composeSchema = schemaComposer.buildSchema();
writeFileSync(join(process.cwd(), `/src/gql-schema/${User.name}.graphql`), printSchema(composeSchema)); connect compose schemas files to NestJS server @Module({
imports: [
MongooseModule.forRootAsync({
imports: [ConfigModule],
useFactory: async (configService: ConfigService) => ({
uri: process.env.MONGO_URI || configService.get('MONGO_URI'),
useNewUrlParser: true,
useUnifiedTopology: true,
}),
inject: [ConfigService],
}),
GraphQLModule.forRoot<ApolloDriverConfig>({
driver: ApolloDriver,
- autoSchemaFile: join(process.cwd(), 'src/schema.gql'),
+ typePaths: ['./**/*.graphql'],
}),
UserModule,
],
controllers: [],
providers: [],
})
export class AppModule {} but i steel have first question |
Did you get any resolution for your first question? graphql-compose-mongoose : 9.8.0 The basic code from the site fails TS. import { composeMongoose } from "graphql-compose-mongoose"
import mongoose from "mongoose"
const LanguagesSchema = new mongoose.Schema({
language: String,
skill: {
type: String,
enum: ["basic", "fluent", "native"],
},
})
const UserSchema = new mongoose.Schema({
name: String, // standard types
age: {
type: Number,
index: true,
},
ln: {
type: [LanguagesSchema], // you may include other schemas (here included as array of embedded documents)
default: [],
alias: "languages", // in schema `ln` will be named as `languages`
},
contacts: {
// another mongoose way for providing embedded documents
email: String,
phones: [String], // array of strings
},
gender: {
// enum field with values
type: String,
enum: ["male", "female"],
},
someMixed: {
type: mongoose.Schema.Types.Mixed,
description: "Can be any mixed type, that will be treated as JSON GraphQL Scalar Type",
},
})
const User = mongoose.model("User", UserSchema)
const customizationOptions = {} // left it empty for simplicity, described below
const UserTC = composeMongoose(**User**, customizationOptions) <===== Argument of type 'Model<{ ln: DocumentArray<{ language?: string | undefined; skill?: "basic" | "fluent" | "native" | undefined; }>; name?: string | undefined; age?: number | undefined; contacts?: { ...; } | undefined; gender?: "male" | ... 1 more ... | undefined; someMixed?: any; }, ... 4 more ..., Schema<...>>' 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>'. |
Latest version installed
package.json
Following instructions and try using graphql-compose-mongoose in NestJS project
But got error at
const CatTC = composeMongoose(CatModel, {});
I can pass any genericconst CatModel = mongoose.model<any>('Cat', schema);
but still having problemNestJS saying
cat.module.ts
Another way - cloning example and seen you using any heneric too
export const Category = model<any>('Category', CategorySchema);
If i remove it i got error
If update packages to latest version - got same error as in my own project
Based on the above, there are two questions:
The text was updated successfully, but these errors were encountered: