Which data type will be used against the Mongoose data type? Here we go.
Mongoose data types
const mongoose = require('mongoose');
const Schema = mongoose.Schema;
const studentSchema = new Schema(
{
"year": {
"type": "Number"
},
"semester": {
"type": "String"
},
"profile": {
"name": {
##
"type": "String"
},
"imgUrl": {
"type": "String"
},
"phone":{
"type": "String"
},
"address": {
"type": "String"
}
},
"courses": {
"type": [
"String"
]
}
});
module.exports = mongoose.model('Student', studentSchema);
GraphQl object data type
/******************************************
* student profile object for graphql
*
* ***************************************/
const profile_type = new GraphQLObjectType({
name: 'profile',
fields: () => ({
name: { type: GraphQLString },
imgUrl: { type: GraphQLString },
phone: { type: GraphQLString },
address: { type: GraphQLString },
}),
});
GraphQl all data types
const StudentType = new GraphQLObjectType({
name: 'Student',
fields: () => ({
id: { type: GraphQLID },
year: { type: GraphQLInt },
semester: { type: GraphQLString },
profile: { type: profile_type },
courses: { type: new GraphQLList(GraphQLString) }, // for array of String
})
});
Top comments (0)