我有以下可以正常工作的订阅查询:
subscription{
streamShipmentOrder{
id
}
}
但以下发送“无法读取未定义的属性'ShipmentOrder'”错误
subscription{
streamShipmentOrder{
id
logs{
comment
}
}
}
这是我的 ShipmentOrder 类型定义,我正在使用sequelize与数据库通信
const ShipmentOrderType = new GraphQLObjectType({
name: 'ShipmentOrder',
fields: () => ({
id: { type: GraphQLID },
logs: {
type: new GraphQLList(LogType),
resolve: async (parent, args, { models }, info) => {
return await models.ShipmentOrder.findOne({
where: { id: parent.id },
include: [{ model: models.Log }],
}).then((data) => data.logs);
}
},
}
这是订阅定义
const ShipmentOrderSubscription = new GraphQLObjectType({
name: 'Subscription',
fields: () => ({
streamShipmentOrder: {
type: ShipmentOrderType,
resolve: (payload) => payload.shipmentOrderData,
subscribe: () =>
socket.asyncIterator([
SHIPMENT_ORDER_CREATED,
SHIPMENT_ORDER_UPDATED,
SHIPMENT_ORDER_DELETED
]),
},
}),
});
以及触发订阅的突变,(在请求嵌套结果时,突变也可以正常工作)
const ShipmentOrderMutation = new GraphQLObjectType({
name: 'Mutation',
fields: () => ({
createShipmentOrder: {
type: ShipmentOrderType,
args: {...},
resolve: async (parent, args, { models }, info) => {
// create shipmentOrder
return await models.ShipmentOrder.create({...})
.then(async (createdShipmentOrder) => {
// create log and relate to created shipmentOrder
await models.Log.create({...});
// get created shipmentOrder with its logs
return await models.ShipmentOrder.findOne({
where: { id: createdShipmentOrder.id },
include: [{ model: models.Log }],
}).then((foundShipmentOrder) => {
// updates streams
socket.publish(SHIPMENT_ORDER_CREATED, {
shipmentOrderData: foundShipmentOrder,
});
return foundShipmentOrder;
});
}
}
}
})
});
我会错过什么?