Graphql订购ID

时间:2019-03-04 22:14:59

标签: graphql prisma graphql-subscriptions prisma-graphql

我需要通过id进行订阅,如果仅更新了一个字段,我将得到通知,我正在使用Yoga Server和Prisma进行开发,这是我到目前为止的工作。

在订阅中:

async function purchaseAssigned(parent, args, context, info) {
    return async context.prisma.$subscribe.purchases({ mutation_in: ['UPDATED'] }).node();
}

const assigned = {
    subscribe: purchaseAssigned,
    resolve: (payload, variables) => {
        return payload.purchaseId === variables.purchaseId;
    }
}

module.exports = {
    assigned
};

在架构中: purchaseAssigned(purchaseId: ID!): Purchase

,这是触发订阅的解析器:

async function assignPurchase(root, args, contex) {
  const userID = getUserId(context);
  if (!userID) {
    throw new Error("Not authenticated");
  }

  id = args.id;

  const purchase = await contex.prisma.updatePurchases({
    where: { id },
    data: {
      professional: userID
    }
  });

  pubsub.publish("purchaseAssigned", {
    purchaseAssigned: purchase,
    purchaseId: id,
    professional: userID
  });

  return purchase;
}

谢谢。

0 个答案:

没有答案