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
@@ -56,7 +56,7 @@ Small explanation for variables naming:
56
56
57
57
-`UserSchema` - this is a mongoose schema
58
58
-`User` - this is a mongoose model
59
-
-`UserTC` - this is a `ObjectTypeComposer` instance for User. `ObjectTypeComposer` has `GraphQLObjectType` inside, avaliable via method `UserTC.getType()`.
59
+
-`UserTC` - this is a `ObjectTypeComposer` instance for User. `ObjectTypeComposer` has `GraphQLObjectType` inside, available via method `UserTC.getType()`.
60
60
- Here and in all other places of code variables suffix `...TC` means that this is `ObjectTypeComposer` instance, `...ITC` - `InputTypeComposer`, `...ETC` - `EnumTypeComposer`.
61
61
62
62
```js
@@ -79,17 +79,18 @@ const UserSchema = new mongoose.Schema({
79
79
type:Number,
80
80
index:true,
81
81
},
82
-
languages: {
82
+
ln: {
83
83
type: [LanguagesSchema], // you may include other schemas (here included as array of embedded documents)
84
84
default: [],
85
+
alias:'languages', // in schema `ln` will be named as `languages`
85
86
},
86
87
contacts: { // another mongoose way for providing embedded documents
constdroidTypeConverterOptions= { // this options will be merged with baseOptions -> customisationsOptions
205
+
constdroidTypeConverterOptions= { // this options will be merged with baseOptions -> customizationsOptions
205
206
fields: {
206
207
remove: ['makeDate'],
207
208
}
@@ -528,6 +529,19 @@ const UsersSchema = new Schema({
528
529
});
529
530
```
530
531
532
+
### Can field name in schema have different name in database?
533
+
534
+
Yes, it can. This package understands mongoose [`alias` option](https://mongoosejs.com/docs/guide.html#aliases) for fields. Just provide `alias: 'country'` for field `c` and you get `country` field name in GraphQL schema and Mongoose model but `c` field in database:
535
+
536
+
```js
537
+
constchildSchema=newSchema({
538
+
c: {
539
+
type:String,
540
+
alias:'country'
541
+
}
542
+
});
543
+
```
544
+
531
545
## Customization options
532
546
533
547
When we convert model `const UserTC = composeWithMongoose(User, customizationOptions);` you may tune every piece of future derived types and resolvers.
0 commit comments