你需要在AppointmentBooking中为serviceType编写一个解析程序。
Query: {
async getAppointmentBookings() {
...
}
},
Mutation: {
...
},
AppointmentBooking: {
serviceType: async(parent, args, ctx, info) => {
// Here you will get the objectId from the parent that need to query services
// This will call for every object inside the bookings
// Assuming you are storing the objectID for the services in the key servicetype
const serviceId = parent.serviceType;
try {
const serviceDetails = await Sevice.findByID(serviceID) ;
return serviceDetails;
} catch (err) {
throw new Error(err);
}
}
}
谢谢回复!我想知道这是使用GraphQL和MongoDB这样的数据库的通用设计模式吗?
对于以后的参考,const serviceDetails = await Sevice.findByID(serviceID)是有效的,因为对拥有自己的serviceID的每个AppointmentBooking都调用此方法。
medium.com/paypal-engineering/…。这篇博客文章将更好地理解这些模式,
伟大的!谢谢您的帮助!