Comments (2)
I found ansver on my 2 question
compose schema
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
from graphql-compose-mongoose.
Did you get any resolution for your first question?
graphql-compose-mongoose : 9.8.0
mongoose: 7.6.4
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>'.
The types returned by 'castObject(...)' are incompatible between these types.
Type '{ 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; }' is not assignable to type 'Document<any, any, any>'.ts(2345)
from graphql-compose-mongoose.
Related Issues (20)
- Can't filter response by fields HOT 4
- Correct error handling in mutations HOT 2
- Unable to compose schema for discriminator with index HOT 1
- Array field UpdateMany - $set as object instead of $push array
- beforeRecordMutate not firing HOT 2
- Internal error occurred during message handling. Please check your implementation. Error: Subscription field must return Async Iterable. Received: undefined. HOT 1
- Relation detection HOT 4
- feat: Introduce subscription resolvers using Mongoose Watch
- Inconsistency with mongoose custom types
- Unable to use _operator while filtering a connection HOT 1
- graphql-compose-mongoose with Typescript without extending Document HOT 2
- removeMany throw an error if no items to delete with mongoose v6
- Preserve the array order when using findbyIds HOT 2
- unique type option in mongoose does not work with graphql-compose-mongoose
- If a TC's findMany resolver is added to schema multiple times, filter options for subsequent resolvers are ignored HOT 2
- Mongoose 7 issue ( graphql type and doc validate ) HOT 1
- Array items are generated as optional
- Provide collection name from request
- Incompatible with mongoose 8 HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from graphql-compose-mongoose.