我遇到了一个错误,其中在Subscription中调用了解析程序,但是在解析程序完成之前返回了响应。如下所示,created_by字段通常由getUser
函数解析,对于不涉及预订的其他操作,我没有任何错误。客户端收到字段created_by
的空值。
模式
Place {
...other fields
created_by: User
}
订阅
Subscription: {
addedPlace: {
resolve: (payload, args, context, info) => {
console.log('subscription --> resolve a', payload, '\n created_by: ',payload.addedPlace.place.created_by);
// created_by is a valid id string here
return payload.addedPlace;
},
subscribe: withFilter(
() => pubsub.asyncIterator('addedPlace'),
({ addedPlace }, variables) => {
return addedPlace.tripId == variables.tripId;
},
)
}
}
Place {
created_by: async ({ created_by }, args, { userLoader }) => { return await getUser(created_by, null, userLoader); },
}