n1ru4l/graphql-live-query

Document prisma example usage with resource invalidation middleware

n1ru4l opened this issue · 1 comments

// Register Middleware for automatic model invalidation
prisma.$use(async (params, next) => {
  const resultPromise = next(params);

  if (params.action === "update") {
    resultPromise.then((res) => {
      if (res?.id) {
        liveQueryStore.invalidate(`${params.model}:${res.id}`);
      }
    });
  }

  return resultPromise;
});

I am no longer using prisma and don't wanna maintain docs for that