I'm starting to build a Graphql service to go alongside with a REST api already in production, using NodeJS and Mongoose, but I'm having some trouble in finding a way to translate my mongoose schema to a GraphQL type.
I have the following schema:
var userSchema = new mongoose.Schema({
name: {type: String, required: true},
email: {type: String},
imageURL: {type: String, default:null},
providerId: {type: String, required: true},
token: {type: String, required: true},
history: [{
orders:[{type: mongoose.Types.ObjectId, ref:'Order'}],
restaurant: {type: mongoose.Types.ObjectId, ref: 'Restaurant'}
}]
}, { timestamps: true});
So, basically, the trouble is the history field. This field is a list an object with 2 subfields: orders (list of Objects that reference another mongoose schema) and restaurant (that reference the mongoose schema for restaurant).
My main question is: when writing the corresponding GraphQL type for "User", is there a way to create subfields, as I did with mongoose on the history field, or I have to create a second Type and then reference this type (knowing that there's no need for the application to create another schema in mongoose, whould only create in GraphQL).