I have the following subscription query that works fine:
subscription{
streamShipmentOrder{
id
}
}
But the following sends an "Cannot read property 'ShipmentOrder' of undefined" error
subscription{
streamShipmentOrder{
id
logs{
comment
}
}
}
Here is my ShipmentOrder type definition, I'm using sequelize to talk to the database
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);
}
},
}
And here is the Subscription definition
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
]),
},
}),
});
And the mutation that fires the subscription, (also the mutation works fine when asking for nested results)
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;
});
}
}
}
})
});
What could I be missing?