{"id":110870,"date":"2026-09-29T15:49:04","date_gmt":"2026-09-29T07:49:04","guid":{"rendered":"https:\/\/www.wsisp.com\/helps\/110870.html"},"modified":"2026-09-29T15:49:04","modified_gmt":"2026-09-29T07:49:04","slug":"%e4%bd%bf%e7%94%a8-prisma-%e4%b8%8e-prisma-bindings-%e6%9e%84%e5%bb%ba%e5%ae%9e%e6%97%b6-graphql-%e6%9c%8d%e5%8a%a1%e5%99%a8%ef%bc%9asubscriptions-%e5%ae%9e%e6%88%98%e6%8c%87%e5%8d%97","status":"publish","type":"post","link":"https:\/\/www.wsisp.com\/helps\/110870.html","title":{"rendered":"\u4f7f\u7528 Prisma \u4e0e Prisma Bindings \u6784\u5efa\u5b9e\u65f6 GraphQL \u670d\u52a1\u5668\uff1aSubscriptions \u5b9e\u6218\u6307\u5357"},"content":{"rendered":"<ul class=\"gcb-tag-list\">\n<li><span class=\"gcb-tag\">\u540e\u7aef<\/span><\/li>\n<li><span class=\"gcb-tag\">\u6570\u636e\u5e93<\/span><\/li>\n<li><span class=\"gcb-tag\">GraphQL<\/span><\/li>\n<\/ul>\n<h3 class=\"gcb-project-title\">\u3010\u514d\u8d39\u4e0b\u8f7d\u94fe\u63a5\u3011prisma1<\/h3>\n<p class=\"gcb-project-desc\">&#x1f4be; Database Tools incl. ORM, Migrations and Admin UI (Postgres, MySQL &amp; MongoDB) [deprecated]<\/p>\n<p>    <span class=\"gcb-project-addr-label\">\u9879\u76ee\u5730\u5740&#xff1a;<\/span><br \/>\n    <span class=\"gcb-project-addr-link\">https:\/\/gitcode.com\/gh_mirrors\/pr\/prisma1<\/span> <\/p>\n<p>  <span class=\"gcb-project-btn\"> <span class=\"gcb-project-btn-main\">\u70b9\u51fb\u67e5\u770b<\/span> <span class=\"gcb-project-btn-sub\">\u514d\u8d39\u4e0b\u8f7d<\/span> <\/span> <\/p>\n<p>\u672c\u6307\u5357\u57fa\u4e8e Prisma \u5b98\u65b9\u6559\u7a0b\u300aBuild a Realtime GraphQL Server with Subscriptions\u300b&#xff08;\u539f\u6587\u6863\u4f4d\u4e8e docs\/1.10\/03-Tutorials2\/02-Build-GraphQL-Servers\/01-Development\/03-Build-a-Realtime-GraphQL-Server-with-Subscriptions.md&#xff09;&#xff0c;\u5b8c\u6574\u8bb2\u89e3\u5982\u4f55\u501f\u52a9 Prisma \u7684 Subscription API \u4e0e Prisma bindings \u7684\u5c01\u88c5&#xff0c;\u5728 GraphQL \u5e94\u7528\u5c42\u5feb\u901f\u5b9e\u73b0\u4e24\u7c7b\u5b9e\u65f6\u8ba2\u9605&#xff08;\u65b0\u6587\u7ae0\u521b\u5efa\/\u6807\u9898\u66f4\u65b0\u3001\u6587\u7ae0\u5220\u9664&#xff09;\u3002\u8bfb\u5b8c\u672c\u6587&#xff0c;\u4f60\u5c06\u638c\u63e1 Prisma \u81ea\u52a8\u751f\u6210\u7684\u8ba2\u9605 Schema&#xff08;Subscription \u7c7b\u578b\u3001SubscriptionWhereInput\u3001SubscriptionPayload&#xff09;\u7684\u5b8c\u6574\u5b57\u6bb5\u8bed\u4e49\u3001subscribe\/resolve \u4e24\u7ea7\u8ba2\u9605\u89e3\u6790\u5668\u7684\u7f16\u5199\u65b9\u6cd5&#xff0c;\u4ee5\u53ca\u57fa\u4e8e WebSocket \u7684\u957f\u8fde\u63a5\u63a8\u9001\u7684\u5e95\u5c42\u539f\u7406\u3002<\/p>\n<h3>\u76ee\u5f55<\/h3>\n<ul>\n<li>Overview&#xff1a;\u4e3a\u4ec0\u4e48\u8ba2\u9605\u662f GraphQL \u5b9e\u65f6\u80fd\u529b\u7684\u57fa\u77f3<\/li>\n<li>1. \u9879\u76ee\u642d\u5efa<\/li>\n<li>2. \u7406\u89e3 Prisma \u7684\u8ba2\u9605 API<\/li>\n<li>3. \u6dfb\u52a0 publications \u8ba2\u9605<\/li>\n<li>4. \u6dfb\u52a0 postDeleted \u8ba2\u9605<\/li>\n<li>5. \u6df1\u5165\u5e95\u5c42&#xff1a;\u4ed3\u5e93\u4e2d\u7684\u5b9e\u73b0\u8bc1\u636e<\/li>\n<li>\u603b\u7ed3<\/li>\n<\/ul>\n<h3>Overview&#xff1a;\u4e3a\u4ec0\u4e48\u8ba2\u9605\u662f GraphQL \u5b9e\u65f6\u80fd\u529b\u7684\u57fa\u77f3<\/h3>\n<p>GraphQL \u8ba2\u9605&#xff08;Subscriptions&#xff09;\u6700\u4fbf\u6377\u7684\u7279\u6027\u4e4b\u4e00&#xff0c;\u662f\u5b83\u4e0e\u67e5\u8be2&#xff08;Query&#xff09;\u3001\u53d8\u66f4&#xff08;Mutation&#xff09;\u4f7f\u7528\u5b8c\u5168\u76f8\u540c\u7684\u8bed\u6cd5\u3002\u5bf9\u5ba2\u6237\u7aef\u800c\u8a00&#xff0c;\u5b66\u4e60\u8ba2\u9605\u51e0\u4e4e\u96f6\u6210\u672c\u3002<\/p>\n<p>\u8ba2\u9605\u4e0e\u67e5\u8be2\/\u53d8\u66f4\u7684\u672c\u8d28\u533a\u522b\u5728\u4e8e\u6267\u884c\u6a21\u578b&#xff1a;<\/p>\n<ul>\n<li>\u67e5\u8be2\u548c\u53d8\u66f4\u9075\u5faa\u5178\u578b\u7684\u201c\u8bf7\u6c42-\u54cd\u5e94\u201d\u5faa\u73af&#xff0c;\u4e0e\u666e\u901a HTTP \u8bf7\u6c42\u65e0\u5f02\u2014\u2014\u5ba2\u6237\u7aef\u53d1\u51fa\u8bf7\u6c42&#xff0c;\u670d\u52a1\u5668\u8ba1\u7b97\u5e76\u4e00\u6b21\u6027\u8fd4\u56de\u7ed3\u679c&#xff1b;<\/li>\n<li>\u8ba2\u9605\u5219\u4e0d\u540c&#xff1a;\u5f53 GraphQL \u670d\u52a1\u5668\u6536\u5230\u8ba2\u9605\u8bf7\u6c42\u540e&#xff0c;\u5b83\u5e76\u4e0d\u4f1a\u7acb\u5373\u8fd4\u56de\u6570\u636e&#xff0c;\u800c\u662f\u4e0e\u53d1\u8d77\u8bf7\u6c42\u7684\u5ba2\u6237\u7aef\u5efa\u7acb\u4e00\u6761\u957f\u8fde\u63a5&#xff08;long-lived connection&#xff09;&#xff0c;\u5ba2\u6237\u7aef\u501f\u6b64\u8868\u8fbe\u5bf9\u67d0\u4e2a\u4e8b\u4ef6&#xff08;\u4f8b\u5982\u67d0\u4e2a\u7528\u6237\u70b9\u8d5e\u4e86\u4e00\u5f20\u56fe\u7247&#xff09;\u7684\u6301\u7eed\u5173\u6ce8\u3002<\/li>\n<\/ul>\n<p>\u4f8b\u5982&#xff0c;\u4e0b\u9762\u8fd9\u6761\u8ba2\u9605\u8868\u8fbe\u4e86\u201c\u5f53 userId \u5bf9\u5e94\u7684\u7528\u6237\u70b9\u8d5e\u56fe\u7247\u65f6&#xff0c;\u5411\u6211\u63a8\u9001\u56fe\u7247\u7684 URL \u4e0e\u7528\u6237\u540d\u201d&#xff1a;<\/p>\n<p>subscription($userId: ID!) {<br \/>\n  likeCreated(userId: $userId) {<br \/>\n    user {<br \/>\n      name<br \/>\n    }<br \/>\n    picture {<br \/>\n      url<br \/>\n    }<br \/>\n  }<br \/>\n}<\/p>\n<p>\u5f53\u4e8b\u4ef6\u771f\u6b63\u53d1\u751f\u65f6&#xff0c;\u670d\u52a1\u5668\u901a\u8fc7\u8fde\u63a5\u5c06\u8bf7\u6c42\u7684\u6570\u636e\u63a8\u9001\u7ed9\u8ba2\u9605\u5ba2\u6237\u7aef&#xff1a;<\/p>\n<p>{<br \/>\n  &#034;data&#034;: {<br \/>\n    &#034;likeCreated&#034;: {<br \/>\n      &#034;user&#034;: {<br \/>\n        &#034;name&#034;: &#034;Alice&#034;<br \/>\n      },<br \/>\n      &#034;picture&#034;: {<br \/>\n        &#034;url&#034;: &#034;https:\/\/media.giphy.com\/media\/5r5J4JD9miis\/giphy.gif&#034;<br \/>\n      }<br \/>\n    }<br \/>\n  }<br \/>\n}<\/p>\n<h4>\u7528 WebSocket \u5b9e\u73b0\u8ba2\u9605<\/h4>\n<p>\u8ba2\u9605\u901a\u5e38\u57fa\u4e8e WebSocket \u5b9e\u73b0\u3002\u9664\u4e86\u5b9e\u65f6\u903b\u8f91&#xff08;\u901a\u5e38\u7531 pub\/sub \u7cfb\u7edf\u627f\u62c5&#xff09;&#xff0c;\u4f60\u8fd8\u9700\u8981\u5b9e\u73b0 GraphQL \u8ba2\u9605\u7684\u5b98\u65b9\u901a\u4fe1\u534f\u8bae\u3002\u53ea\u6709\u5f53\u670d\u52a1\u5668\u4e25\u683c\u9075\u5faa\u534f\u8bae\u5b9a\u4e49\u7684\u6d41\u7a0b\u65f6&#xff0c;\u5ba2\u6237\u7aef\u624d\u80fd\u6b63\u786e\u53d1\u8d77\u8ba2\u9605\u8bf7\u6c42\u5e76\u63a5\u6536\u4e8b\u4ef6\u6570\u636e\u3002<\/p>\n<p>\u540c\u65f6\u5904\u7406\u5b9e\u65f6\u903b\u8f91\u3001pub\/sub \u7cfb\u7edf\u3001\u6570\u636e\u5e93\u8bbf\u95ee\u4ee5\u53ca\u8ba2\u9605\u534f\u8bae&#xff0c;\u590d\u6742\u5ea6\u4f1a\u8fc5\u901f\u4e0a\u5347&#xff1b;\u8ba4\u8bc1\u4e0e\u6388\u6743\u903b\u8f91\u8fd8\u4f1a\u8fdb\u4e00\u6b65\u589e\u52a0\u5b9e\u73b0\u96be\u5ea6\u3002\u6b64\u65f6&#xff0c;\u4f7f\u7528\u5408\u9002\u7684\u62bd\u8c61\u5c42\u4f1a\u5927\u5e45\u7b80\u5316\u5de5\u4f5c\u2014\u2014Prisma \u4e0e Prisma bindings \u7684\u7ec4\u5408\u6b63\u662f\u8fd9\u6837\u4e00\u5c42\u62bd\u8c61&#xff1a;\u53ef\u4ee5\u628a\u5b83\u7406\u89e3\u4e3a\u4e00\u5c42\u201cGraphQL ORM\u201d&#xff0c;\u5b9e\u65f6\u8ba2\u9605\u5f00\u7bb1\u5373\u7528&#xff0c;\u8ba9\u4f60\u8f7b\u677e\u4e3a API \u6dfb\u52a0\u8ba2\u9605\u80fd\u529b\u3002<\/p>\n<h3>1. \u9879\u76ee\u642d\u5efa<\/h3>\n<h4>1.1 \u4e0b\u8f7d\u5e76\u63a2\u7d22 starter \u9879\u76ee<\/h4>\n<p>\u672c\u6559\u7a0b\u914d\u5957\u4e00\u4e2a starter \u9879\u76ee&#xff08;subscriptions \u4ed3\u5e93&#xff09;\u3002\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u4e0b\u8f7d\u5e76\u5b89\u88c5\u4f9d\u8d56&#xff1a;<\/p>\n<p>curl https:\/\/codeload.github.com\/nikolasburk\/subscriptions\/tar.gz\/starter | tar -xz subscriptions-starter<br \/>\ncd subscriptions-starter<br \/>\nyarn install # or npm install<\/p>\n<p>\u8be5\u9879\u76ee\u5305\u542b\u4e00\u4e2a\u975e\u5e38\u7b80\u5355\u7684 GraphQL API&#xff0c;Schema \u5982\u4e0b&#xff1a;<\/p>\n<p># import Post from &#034;.\/generated\/prisma.graphql&#034;<\/p>\n<p>type Query {<br \/>\n  feed: [Post!]!<br \/>\n}<\/p>\n<p>type Mutation {<br \/>\n  writePost(title: String!): Post<br \/>\n  updateTitle(id: ID!, newTitle: String!): Post<br \/>\n  deletePost(id: ID!): Post<br \/>\n}<\/p>\n<p>Post \u7c7b\u578b\u7531 Prisma \u6570\u636e\u6a21\u578b&#xff08;database\/datamodel.graphql&#xff09;\u5b9a\u4e49&#xff1a;<\/p>\n<p>type Post {<br \/>\n  id: ID! &#064;unique<br \/>\n  title: String!<br \/>\n}<\/p>\n<p>\u672c\u9879\u76ee\u7684\u76ee\u6807\u662f\u4e3a API \u6dfb\u52a0\u4e24\u6761\u8ba2\u9605&#xff1a;<\/p>\n<ul>\n<li>\u4e00\u6761\u8ba2\u9605&#xff1a;\u5f53\u65b0\u7684 Post \u88ab\u521b\u5efa&#xff0c;\u6216\u5df2\u6709 Post \u7684 title \u88ab\u66f4\u65b0\u65f6\u89e6\u53d1&#xff1b;<\/li>\n<li>\u4e00\u6761\u8ba2\u9605&#xff1a;\u5f53\u5df2\u6709 Post \u88ab\u5220\u9664\u65f6\u89e6\u53d1\u3002<\/li>\n<\/ul>\n<h4>1.2 \u90e8\u7f72 Prisma \u6570\u636e\u5e93 API<\/h4>\n<p>\u5728\u542f\u52a8\u670d\u52a1\u5668\u4e4b\u524d&#xff0c;\u9700\u8981\u5148\u786e\u4fdd Prisma \u6570\u636e\u5e93 API \u53ef\u7528&#xff0c;\u4e14\u80fd\u88ab\u4f60\u7684 GraphQL \u670d\u52a1\u5668&#xff08;\u901a\u8fc7 Prisma bindings&#xff09;\u8bbf\u95ee\u3002<\/p>\n<p>\u5728 subscriptions-starter \u76ee\u5f55\u4e0b\u8fd0\u884c&#xff1a;<\/p>\n<p>yarn prisma deploy<\/p>\n<p>CLI \u4f1a\u8be2\u95ee\u4e00\u7cfb\u5217\u5173\u4e8e\u201c\u5982\u4f55\u90e8\u7f72 API\u201d\u7684\u95ee\u9898\u3002\u672c\u6559\u7a0b\u9009\u62e9 Demo server \u9009\u9879&#xff0c;\u7136\u540e\u76f4\u63a5\u6309 Enter \u63a5\u53d7 service name \u4e0e stage \u7684\u63a8\u8350\u503c&#xff08;\u5982\u679c\u4f60\u88c5\u6709 Docker&#xff0c;\u4e5f\u53ef\u4ee5\u9009\u62e9\u672c\u5730\u90e8\u7f72&#xff09;\u3002<\/p>\n<p>\u90e8\u7f72\u5b8c\u6210\u540e&#xff0c;CLI \u4f1a\u6253\u5370 Prisma \u6570\u636e\u5e93 API \u7684 HTTP endpoint\u3002\u590d\u5236\u8be5 endpoint&#xff0c;\u7c98\u8d34\u5230 index.js \u4e2d\u5b9e\u4f8b\u5316 GraphQLServer \u7684\u4f4d\u7f6e\u2014\u2014\u6ce8\u610f\u9700\u8981\u7528\u771f\u5b9e endpoint \u66ff\u6362\u5360\u4f4d\u7b26 __PRISMA_ENDPOINT__\u3002\u5b8c\u6210\u540e\u4ee3\u7801\u5927\u81f4\u5982\u4e0b&#xff1a;<\/p>\n<p>const server &#061; new GraphQLServer({<br \/>\n  typeDefs: &#039;.\/src\/schema.graphql&#039;,<br \/>\n  resolvers,<br \/>\n  context: req &#061;&gt; ({<br \/>\n    &#8230;req,<br \/>\n    db: new Prisma({<br \/>\n      typeDefs: &#039;src\/generated\/prisma.graphql&#039;,<br \/>\n      endpoint: &#039;https:\/\/eu1.prisma.sh\/jane-doe\/subscriptions-example\/dev&#039;,<br \/>\n      secret: &#039;mysecret123&#039;,<br \/>\n      debug: true,<br \/>\n    }),<br \/>\n  }),<br \/>\n})<\/p>\n<h4>1.3 \u6253\u5f00 GraphQL Playground<\/h4>\n<p>\u8fd0\u884c yarn dev \u542f\u52a8\u670d\u52a1\u5668\u5e76\u6253\u5f00 GraphQL Playground\u3002\u4f60\u53ef\u4ee5\u81ea\u7531\u63a2\u7d22\u9879\u76ee&#xff0c;\u5e76\u53d1\u9001\u4e00\u4e9b\u67e5\u8be2\u4e0e\u53d8\u66f4\u3002<\/p>\n<p>Note&#xff1a;Playground \u4f1a\u5c55\u793a .graphqlconfig.yml \u4e2d\u5b9a\u4e49\u7684\u4e24\u4e2a GraphQL API&#xff1a;app \u9879\u76ee\u4ee3\u8868\u5e94\u7528\u5c42&#xff0c;\u7531 \/src\/schema.graphql \u5b9a\u4e49&#xff1b;database \u9879\u76ee\u4ee3\u8868\u6570\u636e\u5e93\u5c42&#xff0c;\u7531\u81ea\u52a8\u751f\u6210\u7684 Prisma GraphQL Schema&#xff08;\/src\/generated\/prisma.graphql&#xff09;\u5b9a\u4e49\u3002<\/p>\n<h3>2. \u7406\u89e3 Prisma \u7684\u8ba2\u9605 API<\/h3>\n<h4>2.1 \u6982\u89c8<\/h4>\n<p>\u5728\u52a8\u624b\u5b9e\u73b0\u8ba2\u9605\u4e4b\u524d&#xff0c;\u5148\u82b1\u4e00\u70b9\u65f6\u95f4\u7406\u89e3 Prisma \u63d0\u4f9b\u7684\u8ba2\u9605 API\u2014\u2014\u56e0\u4e3a\u63a5\u4e0b\u6765\u6b63\u662f\u8981\u501f\u529b&#xff08;piggyback&#xff09;\u8fd9\u4e2a API \u6765\u5b9e\u73b0\u5e94\u7528\u5c42\u7684\u8ba2\u9605\u3002<\/p>\n<p>\u4e00\u822c\u6765\u8bf4&#xff0c;Prisma \u5141\u8bb8\u4f60\u5bf9\u6570\u636e\u6a21\u578b\u4e2d\u7684\u6bcf\u79cd\u7c7b\u578b\u8ba2\u9605\u4e09\u7c7b\u4e8b\u4ef6\u3002\u4ee5 Post \u4e3a\u4f8b&#xff1a;<\/p>\n<ul>\n<li>\u4e00\u4e2a\u65b0\u7684 Post \u88ab\u521b\u5efa<\/li>\n<li>\u4e00\u4e2a\u5df2\u6709\u7684 Post \u88ab\u66f4\u65b0<\/li>\n<li>\u4e00\u4e2a\u5df2\u6709\u7684 Post \u88ab\u5220\u9664<\/li>\n<\/ul>\n<p>\u5bf9\u5e94\u7684 Subscription \u7c7b\u578b\u5b9a\u4e49\u5982\u4e0b&#xff08;\u53ef\u5728 \/src\/generated\/prisma.graphql \u4e2d\u627e\u5230&#xff09;&#xff1a;<\/p>\n<p>type Subscription {<br \/>\n  post(where: PostSubscriptionWhereInput): PostSubscriptionPayload<br \/>\n}<\/p>\n<p>\u5982\u679c\u4e0d\u7528 where \u53c2\u6570\u8fdb\u4e00\u6b65\u7ea6\u675f&#xff0c;post \u8ba2\u9605\u4f1a\u5bf9\u4e0a\u8ff0\u4e09\u7c7b\u4e8b\u4ef6\u5168\u90e8\u89e6\u53d1\u3002<\/p>\n<h4>2.2 \u8fc7\u6ee4\u7279\u5b9a\u4e8b\u4ef6<\/h4>\n<p>where \u53c2\u6570\u5141\u8bb8\u5ba2\u6237\u7aef\u7cbe\u786e\u6307\u5b9a\u81ea\u5df1\u5173\u5fc3\u7684\u4e8b\u4ef6\u3002\u6bd4\u5982&#xff1a;\u67d0\u4e2a\u5ba2\u6237\u7aef\u53ea\u60f3\u5728 Post \u88ab\u5220\u9664\u65f6\u6536\u5230\u901a\u77e5&#xff1b;\u6216\u8005\u53ea\u60f3\u5728 title \u5305\u542b\u7279\u5b9a\u5173\u952e\u8bcd\u7684 Post \u88ab\u521b\u5efa\u65f6\u6536\u5230\u901a\u77e5\u3002\u8fd9\u4e9b\u7ea6\u675f\u90fd\u53ef\u4ee5\u7528 where \u53c2\u6570\u8868\u8fbe\u3002<\/p>\n<p>where \u7684\u7c7b\u578b\u5b9a\u4e49\u5982\u4e0b&#xff1a;<\/p>\n<p>input PostSubscriptionWhereInput {<br \/>\n  # Filter for a specific mutation:<br \/>\n  # CREATED, UPDATED, DELETED<br \/>\n  mutation_in: [MutationType!]<\/p>\n<p>  # Filter for a specific field being updated<br \/>\n  updatedFields_contains: String<br \/>\n  updatedFields_contains_every: [String!]<br \/>\n  updatedFields_contains_some: [String!]<\/p>\n<p>  # Filter for concrete values of the Post being mutated<br \/>\n  node: PostWhereInput<\/p>\n<p>  # Combine several filter conditions<br \/>\n  AND: [PostSubscriptionWhereInput!]<br \/>\n  OR: [PostSubscriptionWhereInput!]<br \/>\n}<\/p>\n<p>\u4e0a\u9762\u63d0\u5230\u7684\u4e24\u4e2a\u4f8b\u5b50&#xff0c;\u53ef\u4ee5\u5728 Prisma API \u4e2d\u7528\u4ee5\u4e0b\u8ba2\u9605\u8868\u8fbe&#xff1a;<\/p>\n<p># \u4ec5\u5728\u88ab_\u5220\u9664_\u7684 Post \u4e0a\u89e6\u53d1<br \/>\nsubscription {<br \/>\n  post(where: {<br \/>\n    mutation_in: [DELETED]<br \/>\n  }) {<br \/>\n    # &#8230; \u9009\u62e9\u96c6\u7a0d\u540e\u8ba8\u8bba<br \/>\n  }<br \/>\n}<\/p>\n<p># \u4ec5\u5728 title \u5305\u542b &#034;GraphQL&#034; \u7684 Post \u88ab_\u521b\u5efa_\u65f6\u89e6\u53d1<br \/>\nsubscription {<br \/>\n  post(where: {<br \/>\n    mutation_in: [CREATED]<br \/>\n    node: {<br \/>\n      title_contains: &#034;GraphQL&#034;<br \/>\n    }<br \/>\n  }) {<br \/>\n    # &#8230; \u9009\u62e9\u96c6\u7a0d\u540e\u8ba8\u8bba<br \/>\n  }<br \/>\n}<\/p>\n<h4>2.3 \u63a2\u7d22\u8ba2\u9605\u7684\u9009\u62e9\u96c6<\/h4>\n<p>PostSubscriptionPayload \u7c7b\u578b\u5b9a\u4e49\u4e86 post \u8ba2\u9605\u4e2d\u53ef\u4ee5\u8bf7\u6c42\u7684\u5b57\u6bb5&#xff1a;<\/p>\n<p>type PostSubscriptionPayload {<br \/>\n  mutation: MutationType!<br \/>\n  node: Post<br \/>\n  updatedFields: [String!]<br \/>\n  previousValues: PostPreviousValues<br \/>\n}<\/p>\n<h5>2.3.1 mutation: MutationType!<\/h5>\n<p>MutationType \u662f\u4e00\u4e2a\u5305\u542b\u4e09\u4e2a\u503c\u7684\u679a\u4e3e&#xff1a;<\/p>\n<p>enum MutationType {<br \/>\n  CREATED<br \/>\n  UPDATED<br \/>\n  DELETED<br \/>\n}<\/p>\n<p>PostSubscriptionPayload \u4e0a\u7684 mutation \u5b57\u6bb5\u56e0\u6b64\u643a\u5e26\u4e86\u201c\u53d1\u751f\u4e86\u4ec0\u4e48\u7c7b\u578b\u7684\u53d8\u66f4\u201d\u8fd9\u4e00\u4fe1\u606f\u3002<\/p>\n<h5>2.3.2 node: Post<\/h5>\n<p>\u8be5\u5b57\u6bb5\u8868\u793a\u88ab\u521b\u5efa\u3001\u66f4\u65b0\u6216\u5220\u9664\u7684 Post \u5143\u7d20&#xff0c;\u5141\u8bb8\u4f60\u68c0\u7d22\u5173\u4e8e\u5b83\u7684\u66f4\u591a\u4fe1\u606f\u3002<\/p>\n<p>\u6ce8\u610f&#xff1a;\u5bf9\u4e8e DELETED \u53d8\u66f4&#xff0c;node \u59cb\u7ec8\u4e3a null\u3002\u5982\u679c\u4f60\u9700\u8981\u4e86\u89e3\u88ab\u5220\u9664 Post \u7684\u66f4\u591a\u7ec6\u8282&#xff0c;\u53ef\u4ee5\u6539\u7528 previousValues \u5b57\u6bb5\u3002<\/p>\n<p>Note&#xff1a;GraphQL \u4e2d\u6709\u65f6\u7528 node \u6307\u4ee3\u5355\u4e2a\u5143\u7d20\u3002\u4e00\u4e2a node \u672c\u8d28\u4e0a\u5bf9\u5e94\u6570\u636e\u5e93\u4e2d\u7684\u4e00\u6761\u8bb0\u5f55&#xff08;record&#xff09;\u3002<\/p>\n<h5>2.3.3 updatedFields: [String!]<\/h5>\n<p>\u5bf9\u4e8e UPDATED \u53d8\u66f4&#xff0c;\u4f60\u53ef\u80fd\u5173\u5fc3\u7684\u662f\u201c\u54ea\u4e9b\u5b57\u6bb5\u88ab\u66f4\u65b0\u4e86\u201d\u2014\u2014\u8fd9\u6b63\u662f updatedFields \u7684\u7528\u9014\u3002<\/p>\n<p>\u5047\u8bbe\u67d0\u5ba2\u6237\u7aef\u7528\u4ee5\u4e0b\u8ba2\u9605\u8ba2\u9605\u4e86 Prisma API&#xff1a;<\/p>\n<p>subscription {<br \/>\n  post {<br \/>\n    updatedFields<br \/>\n  }<br \/>\n}<\/p>\n<p>\u73b0\u5728&#xff0c;\u5047\u8bbe\u670d\u52a1\u5668\u6536\u5230\u5982\u4e0b\u53d8\u66f4&#xff0c;\u66f4\u65b0\u67d0\u4e2a Post \u7684 title&#xff1a;<\/p>\n<p>mutation {<br \/>\n  updatePost(<br \/>\n    where: {<br \/>\n      id: &#034;&#8230;&#034;<br \/>\n    }<br \/>\n    data: {<br \/>\n      title: &#034;Prisma is the best way to build GraphQL servers&#034;<br \/>\n    }<br \/>\n  ) {<br \/>\n    id<br \/>\n  }<br \/>\n}<\/p>\n<p>\u8ba2\u9605\u5ba2\u6237\u7aef\u5c06\u6536\u5230\u5982\u4e0b\u8f7d\u8377&#xff1a;<\/p>\n<p>{<br \/>\n  &#034;data&#034;: {<br \/>\n    &#034;post&#034;: {<br \/>\n      &#034;updatedFields&#034;: [&#034;title&#034;]<br \/>\n    }<br \/>\n  }<br \/>\n}<\/p>\n<p>\u8fd9\u662f\u56e0\u4e3a\u8be5\u53d8\u66f4\u53ea\u66f4\u65b0\u4e86 Post \u7684 title \u5b57\u6bb5\u2014\u2014\u6ca1\u6709\u522b\u7684\u3002<\/p>\n<h5>2.3.4 previousValues: PostPreviousValues<\/h5>\n<p>PostPreviousValues \u7c7b\u578b\u4e0e Post \u672c\u8eab\u975e\u5e38\u76f8\u4f3c&#xff1a;<\/p>\n<p>type PostPreviousValues {<br \/>\n  id: ID!<br \/>\n  title: String!<br \/>\n}<\/p>\n<p>\u5b83\u672c\u8d28\u4e0a\u662f\u4e00\u4e2a\u8f85\u52a9\u7c7b\u578b&#xff0c;\u4ec5\u4ec5\u955c\u50cf Post \u7684\u5b57\u6bb5\u3002<\/p>\n<p>previousValues \u53ea\u7528\u4e8e UPDATED \u548c DELETED \u53d8\u66f4\u3002\u5bf9\u4e8e CREATED \u53d8\u66f4&#xff0c;\u5b83\u59cb\u7ec8\u4e3a null&#xff08;\u539f\u56e0\u4e0e DELETED \u53d8\u66f4\u65f6 node \u4e3a null \u76f8\u540c\u2014\u2014\u4e8b\u4ef6\u53d1\u751f\u65f6\u8be5\u8bb0\u5f55\u8fd8\u4e0d\u5b58\u5728&#xff09;\u3002<\/p>\n<h5>2.3.5 \u7efc\u5408\u793a\u4f8b<\/h5>\n<p>\u518d\u6b21\u8003\u8651 2.3.3 \u8282\u4e2d\u7684 updatePost \u53d8\u66f4&#xff0c;\u4f46\u5047\u8bbe\u8ba2\u9605\u67e5\u8be2\u5305\u542b\u4e0a\u9762\u8ba8\u8bba\u7684\u6240\u6709\u5b57\u6bb5&#xff1a;<\/p>\n<p>subscription {<br \/>\n  post {<br \/>\n    mutation<br \/>\n    updatedFields<br \/>\n    node {<br \/>\n      title<br \/>\n    }<br \/>\n    previousValues {<br \/>\n      title<br \/>\n    }<br \/>\n  }<br \/>\n}<\/p>\n<p>\u670d\u52a1\u5668\u6267\u884c\u4e0a\u8ff0\u53d8\u66f4\u540e&#xff0c;\u63a8\u9001\u7ed9\u5ba2\u6237\u7aef\u7684\u8f7d\u8377\u5982\u4e0b&#xff1a;<\/p>\n<p>{<br \/>\n  &#034;data&#034;: {<br \/>\n    &#034;post&#034;: {<br \/>\n      &#034;mutation&#034;: &#034;UPDATED&#034;,<br \/>\n      &#034;updatedFields&#034;: [&#034;title&#034;],<br \/>\n      &#034;node&#034;: {<br \/>\n        &#034;title&#034;: &#034;Prisma is the best way to build GraphQL servers&#034;,<br \/>\n      },<br \/>\n      &#034;previousValues&#034;: {<br \/>\n        &#034;title&#034;: &#034;GraphQL servers are best built with conventional ORMs&#034;,<br \/>\n      }<br \/>\n    }<br \/>\n  }<br \/>\n}<\/p>\n<p>\u6ce8\u610f&#xff0c;\u8fd9\u91cc\u5047\u8bbe\u88ab\u66f4\u65b0\u7684 Post \u5728\u6267\u884c\u53d8\u66f4\u524d\u7684 title \u662f \u201cGraphQL servers are best built with conventional ORMs\u201d\u3002<\/p>\n<h3>3. \u6dfb\u52a0 publications \u8ba2\u9605<\/h3>\n<p>\u638c\u63e1\u4e86 Prisma \u7684\u8ba2\u9605 API \u4e4b\u540e&#xff0c;\u5c31\u53ef\u4ee5\u6d88\u8d39\u8fd9\u5957 API \u6765\u5728\u5e94\u7528\u5c42\u5b9e\u73b0\u81ea\u5df1\u7684\u8ba2\u9605\u4e86\u3002\u5148\u4ece\u201c\u65b0 Post \u88ab\u521b\u5efa\u6216\u5df2\u6709 Post \u7684 title \u88ab\u66f4\u65b0\u201d\u8fd9\u6761\u8ba2\u9605\u5f00\u59cb\u3002<\/p>\n<h4>3.1 \u6269\u5c55\u5e94\u7528 Schema<\/h4>\n<p>\u7b2c\u4e00\u6b65\u662f\u6269\u5c55\u5e94\u7528\u5c42\u7684 GraphQL Schema&#xff0c;\u6dfb\u52a0\u5bf9\u5e94\u7684\u8ba2\u9605\u5b9a\u4e49\u3002<\/p>\n<p>\u6253\u5f00 schema.graphql&#xff0c;\u6dfb\u52a0\u5982\u4e0b Subscription \u7c7b\u578b&#xff1a;<\/p>\n<p>type Subscription {<br \/>\n  publications: PostSubscriptionPayload<br \/>\n}<\/p>\n<p>\u8fd9\u91cc\u5f15\u7528\u7684 PostSubscriptionPayload \u76f4\u63a5\u53d6\u81ea Prisma GraphQL Schema&#xff0c;\u56e0\u6b64\u8fd8\u9700\u8981\u5728\u6587\u4ef6\u9876\u90e8\u5bfc\u5165\u5b83&#xff1a;<\/p>\n<p># import Post, PostSubscriptionPayload from &#034;.\/generated\/prisma.graphql&#034;<\/p>\n<p>Note&#xff1a;\u8fd9\u79cd\u57fa\u4e8e\u6ce8\u91ca\u7684\u5bfc\u5165\u8bed\u6cd5\u7531 graphql-import \u5305\u63d0\u4f9b\u3002\u622a\u81f3\u76ee\u524d&#xff0c;GraphQL SDL \u8fd8\u6ca1\u6709\u5b98\u65b9\u7684\u8de8\u6587\u4ef6\u7c7b\u578b\u5bfc\u5165\u65b9\u5f0f\u3002<\/p>\n<h4>3.2 \u5b9e\u73b0\u8ba2\u9605\u89e3\u6790\u5668<\/h4>\n<p>\u4e0e\u67e5\u8be2\u3001\u53d8\u66f4\u7c7b\u4f3c&#xff0c;\u6dfb\u52a0\u65b0 API \u529f\u80fd\u7684\u4e0b\u4e00\u6b65\u662f\u5b9e\u73b0\u5bf9\u5e94\u7684\u89e3\u6790\u5668&#xff08;resolver&#xff09;\u3002\u4e0d\u8fc7&#xff0c;\u8ba2\u9605\u7684\u89e3\u6790\u5668\u6709\u4e9b\u4e0d\u540c\u3002<\/p>\n<p>\u8ba2\u9605\u89e3\u6790\u5668\u4e0d\u518d\u53ea\u662f Schema \u5b9a\u4e49\u4e2d\u4e00\u4e2a\u5355\u4e00\u7684\u89e3\u6790\u51fd\u6570&#xff0c;\u800c\u662f\u63d0\u4f9b\u4e00\u4e2a\u5bf9\u8c61&#xff0c;\u5176\u4e2d\u81f3\u5c11\u5305\u542b\u4e00\u4e2a\u540d\u4e3a subscribe \u7684\u5b57\u6bb5\u3002subscribe \u662f\u4e00\u4e2a\u51fd\u6570&#xff0c;\u8fd4\u56de\u4e00\u4e2a AsyncIterator&#xff0c;\u7528\u4e8e\u4e3a\u6bcf\u4e2a\u72ec\u7acb\u4e8b\u4ef6\u4ea7\u51fa\u503c\u3002\u6b64\u5916&#xff0c;\u8fd8\u53ef\u4ee5\u63d0\u4f9b\u4e00\u4e2a resolve \u5b57\u6bb5\u2014\u2014\u4e0b\u4e00\u8282\u4f1a\u8ba8\u8bba\u5b83&#xff0c;\u73b0\u5728\u5148\u805a\u7126 subscribe\u3002<\/p>\n<p>\u66f4\u65b0 index.js \u4e2d\u7684 resolvers \u5bf9\u8c61&#xff0c;\u52a0\u5165 Subscription&#xff1a;<\/p>\n<p>const resolvers &#061; {<br \/>\n  Query: {<br \/>\n    \/\/ &#8230; \u540c\u524d<br \/>\n  },<br \/>\n  Mutation: {<br \/>\n    \/\/ &#8230; \u540c\u524d<br \/>\n  },<br \/>\n  Subscription: {<br \/>\n    publications: {<br \/>\n      subscribe: (parent, args, ctx, info) &#061;&gt; {<br \/>\n        return ctx.db.subscription.post(<br \/>\n          {<br \/>\n            where: {<br \/>\n              mutation_in: [&#039;CREATED&#039;, &#039;UPDATED&#039;],<br \/>\n            },<br \/>\n          },<br \/>\n          info,<br \/>\n        )<br \/>\n      },<br \/>\n    },<br \/>\n  },<br \/>\n}<\/p>\n<p>\u8fd9\u91cc Prisma bindings \u5e2e\u4f60\u5b8c\u6210\u4e86\u7e41\u91cd\u7684\u5de5\u4f5c&#xff1a;db.subscription.post(&#8230;) \u8fd4\u56de\u7684 AsyncIterator \u4f1a\u5728 Post \u7c7b\u578b\u4e0a\u7684\u6bcf\u4e2a\u4e8b\u4ef6\u53d1\u751f\u65f6\u4ea7\u51fa\u4e00\u4e2a\u65b0\u503c\u3002<\/p>\n<p>\u6ce8\u610f&#xff0c;\u8fd9\u91cc\u7279\u610f\u8fc7\u6ee4\u4e86 CREATED \u548c UPDATED \u53d8\u66f4&#xff0c;\u786e\u4fdd publications \u8ba2\u9605\u53ea\u5728\u8fd9\u4e24\u7c7b\u4e8b\u4ef6\u4e0a\u89e6\u53d1\u3002<\/p>\n<h4>3.3 \u6d4b\u8bd5\u8ba2\u9605<\/h4>\n<p>\u6d4b\u8bd5\u8ba2\u9605\u9700\u8981\u5148\u542f\u52a8\u670d\u52a1\u5668\u5e76\u6253\u5f00 Playground\u2014\u2014\u8fd0\u884c yarn dev \u5373\u53ef\u3002<\/p>\n<p>\u5728 Playground \u4e2d\u8fd0\u884c\u5982\u4e0b\u8ba2\u9605&#xff1a;<\/p>\n<p>subscription {<br \/>\n  publications {<br \/>\n    node {<br \/>\n      id<br \/>\n      title<br \/>\n    }<br \/>\n  }<br \/>\n}<\/p>\n<p>Note&#xff1a;GraphQL Playground \u6709\u65f6\u4f1a\u8868\u73b0\u51fa\u4e00\u4e2a\u5df2\u77e5 bug&#xff0c;\u5373\u8ba2\u9605\u76f4\u63a5\u8fd4\u56de null \u8f7d\u8377\u3002\u5982\u679c\u9047\u5230\u8fd9\u79cd\u60c5\u51b5&#xff0c;\u53ef\u4ee5\u5c1d\u8bd5\u8be5 issue \u4e2d\u63d0\u4f9b\u7684\u53d8\u901a\u65b9\u6848\u3002<\/p>\n<p>\u8ba2\u9605\u8fd0\u884c\u540e&#xff0c;\u54cd\u5e94\u9762\u677f\u4f1a\u51fa\u73b0\u52a0\u8f7d\u6307\u793a\u5668&#xff0c;Play \u6309\u94ae\u4f1a\u53d8\u6210\u7ea2\u8272 Stop \u6309\u94ae&#xff0c;\u7528\u4e8e\u505c\u6b62\u8ba2\u9605\u3002<\/p>\n<p>\u6b64\u65f6\u53ef\u4ee5\u518d\u5f00\u4e00\u4e2a\u6807\u7b7e\u9875&#xff0c;\u53d1\u9001\u53d8\u66f4\u6765\u89e6\u53d1\u8ba2\u9605&#xff1a;<\/p>\n<p>mutation {<br \/>\n  writePost(title: &#034;GraphQL subscriptions are awesome&#034;) {<br \/>\n    id<br \/>\n  }<br \/>\n}<\/p>\n<p>\u5207\u56de\u6700\u521d\u7684\u6807\u7b7e\u9875&#xff0c;\u4f60\u4f1a\u770b\u5230\u8ba2\u9605\u6570\u636e\u5df2\u7ecf\u51fa\u73b0\u5728\u54cd\u5e94\u9762\u677f\u4e2d\u3002\u8fd8\u53ef\u4ee5\u7528 updateTitle \u53d8\u66f4\u7ee7\u7eed\u4f53\u9a8c\u3002<\/p>\n<h3>4. \u6dfb\u52a0 postDeleted \u8ba2\u9605<\/h3>\n<p>\u672c\u8282\u5b9e\u73b0\u4e00\u4e2a\u201c\u6bcf\u5f53 Post \u88ab\u5220\u9664\u65f6\u89e6\u53d1\u201d\u7684\u8ba2\u9605\u3002\u6d41\u7a0b\u4e0e publications \u89e3\u6790\u5668\u5927\u4f53\u76f8\u4f3c&#xff0c;\u533a\u522b\u5728\u4e8e&#xff1a;\u8fd9\u6b21\u5c06\u53ea\u8fd4\u56de\u88ab\u5220\u9664\u7684 Post&#xff0c;\u800c\u4e0d\u662f PostSubscriptionPayload \u7c7b\u578b\u7684\u5bf9\u8c61\u3002<\/p>\n<h4>4.1 \u6269\u5c55\u5e94\u7528 Schema<\/h4>\n<p>\u4e0e\u5f80\u5e38\u4e00\u6837&#xff0c;\u4e3a GraphQL API \u6dfb\u52a0\u65b0\u529f\u80fd\u7684\u7b2c\u4e00\u6b65&#xff0c;\u662f\u5728 Schema \u4e2d\u628a\u65b0\u64cd\u4f5c\u8868\u8fbe\u4e3a\u6839\u5b57\u6bb5&#xff08;root field&#xff09;\u3002<\/p>\n<p>\u6253\u5f00 \/src\/schema.graphql&#xff0c;\u5c06 Subscription \u7c7b\u578b\u8c03\u6574\u4e3a&#xff1a;<\/p>\n<p>type Subscription {<br \/>\n  publications: PostSubscriptionPayload<br \/>\n  postDeleted: Post<br \/>\n}<\/p>\n<p>\u5bf9\u4e8e postDeleted&#xff0c;\u4e0d\u518d\u8fd4\u56de PostSubscriptionPayload&#xff0c;\u800c\u662f\u76f4\u63a5\u8fd4\u56de\u88ab\u5220\u9664\u7684 Post \u5bf9\u8c61\u3002<\/p>\n<h4>4.2 \u5b9e\u73b0\u8ba2\u9605\u89e3\u6790\u5668<\/h4>\n<p>\u5728 3.2 \u8282\u4e2d\u66fe\u63d0\u5230&#xff1a;\u5b9e\u73b0\u8ba2\u9605\u89e3\u6790\u5668\u7684\u5bf9\u8c61\u53ef\u4ee5\u6301\u6709\u7b2c\u4e8c\u4e2a\u51fd\u6570 resolve&#xff08;subscribe \u662f\u5fc5\u987b\u7684&#xff09;\u3002\u672c\u8282\u5c06\u5b9e\u9645\u4f7f\u7528\u5b83\u3002<\/p>\n<p>\u4e0b\u9762\u662f\u89e3\u6790 postDeleted \u8ba2\u9605\u65f6 subscribe \u4e0e resolve \u7684\u5b9e\u73b0&#xff1a;<\/p>\n<p>const resolvers &#061; {<br \/>\n  Query: {<br \/>\n    \/\/ &#8230; \u540c\u524d<br \/>\n  },<br \/>\n  Mutation: {<br \/>\n    \/\/ &#8230; \u540c\u524d<br \/>\n  },<br \/>\n  Subscription: {<br \/>\n    publications: {<br \/>\n      \/\/ &#8230; \u540c\u524d<br \/>\n    },<br \/>\n    postDeleted: {<br \/>\n      subscribe: (parent, args, ctx, info) &#061;&gt; {<br \/>\n        const selectionSet &#061; &#096;{ previousValues { id title } }&#096;<br \/>\n        return ctx.db.subscription.post(<br \/>\n          {<br \/>\n            where: {<br \/>\n              mutation_in: [&#039;DELETED&#039;],<br \/>\n            },<br \/>\n          },<br \/>\n          selectionSet,<br \/>\n        )<br \/>\n      },<br \/>\n      resolve: (payload, args, context, info) &#061;&gt; {<br \/>\n        return payload ? payload.post.previousValues : payload<br \/>\n      },<br \/>\n    },<br \/>\n  },<br \/>\n}<\/p>\n<p>\u7406\u89e3 subscribe \u4e0e resolve \u7ec4\u5408\u7684\u5173\u952e\u5728\u4e8e&#xff1a;subscribe \u8fd4\u56de\u7684 AsyncIterator \u4ea7\u51fa\u7684\u503c&#xff0c;\u4f1a\u4f5c\u4e3a payload \u53c2\u6570\u4f20\u5165 resolve&#xff01;\u8fd9\u610f\u5473\u7740\u4f60\u53ef\u4ee5\u7528 resolve \u6309\u9700\u8f6c\u6362\u548c\/\u6216\u8fc7\u6ee4 AsyncIterator \u53d1\u51fa\u7684\u4e8b\u4ef6\u6570\u636e\u3002<\/p>\n<p>\u6ce8\u610f&#xff0c;\u8fd9\u91cc\u7ed9 post \u7ed1\u5b9a\u51fd\u6570\u4f20\u5165\u7684\u662f\u4e00\u4e2a\u786c\u7f16\u7801\u7684\u9009\u62e9\u96c6&#xff0c;\u800c\u4e0d\u662f\u50cf\u5927\u591a\u6570\u60c5\u51b5\u90a3\u6837\u4f20\u5165 info \u5bf9\u8c61\u3002\u56e0\u6b64&#xff0c;\u8fd9\u6b21\u7ed1\u5b9a\u51fd\u6570\u7684\u8c03\u7528\u7b49\u4ef7\u4e8e\u5411 Prisma API \u53d1\u8d77\u5982\u4e0b\u8ba2\u9605\u8bf7\u6c42&#xff1a;<\/p>\n<p>subscription {<br \/>\n  post {<br \/>\n    previousValues {<br \/>\n      id<br \/>\n      title<br \/>\n    }<br \/>\n  }<br \/>\n}<\/p>\n<p>info \u5bf9\u8c61\u643a\u5e26\u7684\u662f\u4f20\u5165 GraphQL \u64cd\u4f5c&#xff08;\u67e5\u8be2\u3001\u53d8\u66f4\u3001\u8ba2\u9605\u7686\u7136&#xff09;\u7684 AST&#xff08;\u4ece\u800c\u5305\u542b\u9009\u62e9\u96c6&#xff09;\u3002\u4f46\u5728\u8fd9\u91cc&#xff0c;\u4f20\u5165\u7684\u9009\u62e9\u96c6\u65e0\u6cd5\u76f4\u63a5\u5957\u7528\u5230 Prisma API \u7684 post \u8ba2\u9605\u4e0a&#xff0c;\u539f\u56e0\u5982\u4e0b&#xff1a;<\/p>\n<ul>\n<li>\u4f20\u5165\u8ba2\u9605\u7684\u8fd4\u56de\u7c7b\u578b\u53ea\u662f Post&#xff08;\u5982\u4f60\u5728 schema.graphql \u4e2d\u6240\u5b9a\u4e49&#xff09;&#xff1b;<\/li>\n<li>Prisma GraphQL API \u7684 post \u8ba2\u9605\u8fd4\u56de\u7c7b\u578b\u662f PostSubscriptionPayload\u3002<\/li>\n<\/ul>\n<p>\u4e5f\u5c31\u662f\u8bf4&#xff0c;\u4f20\u5165\u7684 info \u5bf9\u8c61\u4e0e post \u8ba2\u9605\u6240\u9700\u7684\u7ed3\u6784\u4e0d\u5339\u914d&#xff0c;\u56e0\u6b64\u9700\u8981\u4ee5\u5b57\u7b26\u4e32\u5f62\u5f0f\u624b\u52a8\u6307\u5b9a post \u8ba2\u9605\u7684\u9009\u62e9\u96c6\u3002<\/p>\n<p>Note&#xff1a;\u8fd9\u4e00\u70b9\u521d\u770b\u6709\u4e9b\u7ed5\u3002\u5982\u679c\u4e00\u65f6\u96be\u4ee5\u7406\u89e3&#xff0c;\u53ef\u4ee5\u9605\u8bfb\u8fd9\u7bc7\u5173\u4e8e info \u5bf9\u8c61\u53ca\u5176\u5728 GraphQL \u89e3\u6790\u5668\u4e2d\u4f5c\u7528\u7684\u6280\u672f\u6df1\u6f5c\u6587\u7ae0\u3002<\/p>\n<p>\u5766\u767d\u8bf4&#xff0c;\u8fd9\u79cd\u65b9\u5f0f\u4e5f\u5e76\u4e0d\u5b8c\u7f8e&#xff1a;\u5bf9\u4e8e\u5b57\u6bb5\u5f88\u591a\u7684\u7c7b\u578b&#xff0c;\u786c\u7f16\u7801\u9009\u62e9\u96c6\u4f1a\u5f88\u5feb\u5931\u63a7&#xff1b;\u53e6\u5916&#xff0c;\u4f20\u5165\u7684\u8ba2\u9605\u53ef\u80fd\u5e76\u4e0d\u4f1a\u8bf7\u6c42\u7c7b\u578b\u7684\u6240\u6709\u5b57\u6bb5&#xff0c;\u6b64\u65f6\u5c31\u4f1a\u53d1\u751f\u8fc7\u5ea6\u83b7\u53d6&#xff08;overfetching&#xff09;\u3002\u66f4\u4f18\u7684\u65b9\u6848\u662f\u624b\u52a8\u4ece info \u5bf9\u8c61\u4e2d\u63d0\u53d6\u88ab\u8bf7\u6c42\u7684\u5b57\u6bb5&#xff0c;\u518d\u4f20\u7ed9 post \u8ba2\u9605&#xff08;\u76f8\u5173\u8ba8\u8bba\u89c1 graphql-binding \u7684 issue&#xff09;\u3002<\/p>\n<p>\u65e0\u8bba\u5982\u4f55&#xff0c;\u901a\u8fc7\u786c\u7f16\u7801\u9009\u62e9\u96c6&#xff0c;\u53ef\u4ee5\u4fdd\u8bc1\u4f20\u5165 resolve \u7684 payload \u53c2\u6570\u5177\u6709\u5982\u4e0b\u7ed3\u6784&#xff1a;<\/p>\n<p>{<br \/>\n  &#034;post&#034;: {<br \/>\n    &#034;previousValues&#034;: {<br \/>\n      &#034;id&#034;: &#034;&#8230;&#034;,<br \/>\n      &#034;title&#034;: &#034;&#8230;&#034;,<br \/>\n    }<br \/>\n  }<br \/>\n}<\/p>\n<p>\u6b63\u56e0\u5982\u6b64&#xff0c;\u5728 resolve \u5185\u90e8\u53ea\u9700\u8fd4\u56de payload.post.previousValues&#xff0c;\u5f97\u5230\u7684\u5c31\u662f\u4e00\u4e2a\u7b26\u5408 Post \u7c7b\u578b\u7ed3\u6784\u7684\u5bf9\u8c61\u3002&#xff08;\u6ce8\u610f&#xff1a;\u7528\u4e09\u5143\u8fd0\u7b97\u7b26\u68c0\u67e5 payload \u53ea\u662f\u4e3a\u4e86\u786e\u4fdd\u5b83\u4e0d\u662f undefined&#xff0c;\u56e0\u4e3a undefined \u53ef\u80fd\u7834\u574f\u8ba2\u9605\u3002&#xff09;<\/p>\n<h4>4.3 \u6d4b\u8bd5\u8ba2\u9605<\/h4>\n<p>\u6d4b\u8bd5\u65b0\u8ba2\u9605\u524d\u9700\u8981\u91cd\u542f\u670d\u52a1\u5668&#xff0c;\u786e\u4fdd\u6539\u52a8\u751f\u6548&#xff1a;\u6309 CTRL&#043;C \u7ec8\u6b62\u670d\u52a1\u5668&#xff0c;\u518d\u7528 yarn dev \u91cd\u542f\u3002<\/p>\n<p>\u8ba2\u9605\u8fd0\u884c\u540e&#xff0c;\u53d1\u9001\u5982\u4e0b\u53d8\u66f4&#xff08;\u628a __POST_ID__ \u5360\u4f4d\u7b26\u66ff\u6362\u4e3a\u6570\u636e\u5e93\u4e2d\u5b9e\u9645 Post \u7684 id&#xff09;&#xff1a;<\/p>\n<p>mutation {<br \/>\n  deletePost(id: &#034;__POST_ID__&#034;) {<br \/>\n    id<br \/>\n  }<br \/>\n}<\/p>\n<p>\u5207\u56de\u8ba2\u9605\u6807\u7b7e\u9875&#xff0c;\u4f60\u4f1a\u770b\u5230 id \u4e0e title \u5df2\u6309\u6d3b\u52a8\u8ba2\u9605\u8bf7\u6c42\u7684\u5185\u5bb9\u88ab\u63a8\u9001\u5230\u54cd\u5e94\u9762\u677f\u3002<\/p>\n<h3>5. \u6df1\u5165\u5e95\u5c42&#xff1a;\u4ed3\u5e93\u4e2d\u7684\u5b9e\u73b0\u8bc1\u636e<\/h3>\n<p>\u5e94\u7528\u5c42\u7684\u8fd9\u4e9b API \u4e0e\u884c\u4e3a&#xff0c;\u5728\u5f53\u524d\u4ed3\u5e93&#xff08;Prisma 1.x&#xff09;\u7684\u6e90\u7801\u4e2d\u90fd\u80fd\u627e\u5230\u5bf9\u5e94\u7684\u5b9e\u73b0\u8bc1\u636e\u3002\u672c\u6559\u7a0b\u5c55\u793a\u7684 Prisma bindings \u5ba2\u6237\u7aef&#xff08;db.subscription.post(&#8230;)&#xff09;\u4e0e Prisma \u670d\u52a1\u7aef\u7684\u8ba2\u9605\u5b50\u7cfb\u7edf&#xff0c;\u6784\u6210\u4e86\u201c\u5e94\u7528\u5c42\u7ed1\u5b9a \u2192 WebSocket \u534f\u8bae \u2192 pub\/sub \u4e8b\u4ef6 \u2192 \u6570\u636e\u5e93\u4e8b\u4ef6\u89e3\u6790 \u2192 \u8f7d\u8377\u56de\u63a8\u201d\u7684\u5b8c\u6574\u94fe\u8def\u3002<\/p>\n<h4>5.1 \u5ba2\u6237\u7aef&#xff1a;\u8ba2\u9605\u5982\u4f55\u901a\u8fc7 WebSocket \u4f20\u8f93<\/h4>\n<p>Prisma \u5ba2\u6237\u7aef&#xff08;Prisma bindings \u6240\u4f9d\u8d56\u7684\u5e95\u5c42&#xff09;\u5728 cli\/packages\/prisma-client-lib\/src\/Client.ts \u4e2d\u5b9e\u73b0\u4e86\u8ba2\u9605\u7684\u4f20\u8f93\u903b\u8f91&#xff1a;<\/p>\n<ul>\n<li>\u6784\u9020 SubscriptionClient \u65f6&#xff0c;\u5c06 HTTP endpoint \u66ff\u6362\u4e3a WebSocket \u534f\u8bae&#xff1a;endpoint.replace(\/^http\/, &#039;ws&#039;)&#xff0c;\u5e76\u914d\u7f6e lazy: true\u3001reconnect: true \u4ee5\u53ca 60 \u79d2\u7684 inactivityTimeout&#xff08;Client.ts \u7b2c 89-100 \u884c&#xff09;&#xff1b;<\/li>\n<li>\u5f53\u64cd\u4f5c\u7c7b\u578b\u4e3a subscription \u65f6&#xff0c;execute \u901a\u8fc7 this._subscriptionClient.request({ query, variables }) \u53d1\u8d77\u8ba2\u9605&#xff0c;\u5e76\u628a\u8fd4\u56de\u7684\u53ef\u89c2\u5bdf\u5bf9\u8c61\u8f6c\u6362\u4e3a AsyncIterator&#xff08;Client.ts \u7b2c 227-237 \u884c&#xff09;\u2014\u2014\u8fd9\u6b63\u662f\u6587\u6863 3.2 \u8282\u6240\u8bf4\u201cdb.subscription.post(&#8230;) \u8fd4\u56de AsyncIterator\u201d\u7684\u4ee3\u7801\u6765\u6e90&#xff1b;<\/li>\n<li>\u6bcf\u4e2a\u4e8b\u4ef6\u7684\u8f7d\u8377\u8fd8\u4f1a\u7ecf\u8fc7 mapSubscriptionPayload \/ extractPayload \u5904\u7406&#xff1a;\u6cbf\u5bf9\u8c61\u952e\u9010\u5c42\u89e3\u5305&#xff0c;\u5265\u53bb { __typename } \u4e4b\u7c7b\u7684\u5143\u6570\u636e&#xff0c;\u5f97\u5230\u7eaf\u51c0\u7684\u8ba2\u9605\u8f7d\u8377&#xff08;Client.ts \u7b2c 164-225 \u884c&#xff09;\u3002<\/li>\n<\/ul>\n<p>\u53ef\u89c1&#xff0c;\u5e94\u7528\u5c42\u89e3\u6790\u5668\u62ff\u5230\u7684 AsyncIterator \u548c\u4e8b\u4ef6\u503c&#xff0c;\u662f Prisma bindings \u5728\u5ba2\u6237\u7aef\u5b8c\u6210 WebSocket \u901a\u4fe1\u3001\u534f\u8bae\u5c01\u88c5\u4e0e\u8f7d\u8377\u89e3\u5305\u540e\u7684\u7ed3\u679c\u3002<\/p>\n<h4>5.2 \u670d\u52a1\u7aef&#xff1a;\u8ba2\u9605\u5b50\u7cfb\u7edf\u4e0e\u6d88\u606f\u901a\u9053<\/h4>\n<p>\u4ed3\u5e93\u7684 Scala \u670d\u52a1\u7aef\u5305\u542b\u4e00\u4e2a\u5b8c\u6574\u7684\u8ba2\u9605\u5b50\u7cfb\u7edf&#xff08;server\/servers\/subscriptions&#xff09;&#xff0c;\u7528\u4e8e\u652f\u6491 Prisma API \u7684\u8ba2\u9605\u80fd\u529b&#xff1a;<\/p>\n<ul>\n<li>\u534f\u8bae\u5c42&#xff1a;SubscriptionProtocol \u5b9e\u73b0\u4e86\u4e24\u79cd GraphQL \u8ba2\u9605\u901a\u4fe1\u534f\u8bae\u2014\u2014graphql-ws&#xff08;v0.7&#xff0c;\u542b connection_init\u3001start\u3001data\u3001complete \u7b49\u6d88\u606f\u7c7b\u578b&#xff09;\u4e0e graphql-subscriptions&#xff08;v0.5&#xff0c;\u542b init\u3001subscription_start\u3001subscription_data \u7b49\u6d88\u606f\u7c7b\u578b&#xff09;&#xff0c;\u89c1 protocol\/SubscriptionProtocol.scala&#xff1b;<\/li>\n<li>\u5206\u53d1\u5c42&#xff1a;SubscriptionsManager \u6309\u9879\u76ee\u7ef4\u62a4\u8ba2\u9605\u7ba1\u7406\u5668&#xff0c;SubscriptionsManagerForModel \u5219\u9488\u5bf9\u6bcf\u4e2a\u6570\u636e\u6a21\u578b\u7ba1\u7406\u6d3b\u52a8\u8ba2\u9605\u3002\u5b83\u6309\u201c\u67e5\u8be2\u6587\u672c &#043; \u53d8\u91cf\u201d\u5bf9\u76f8\u540c\u8ba2\u9605\u5206\u7ec4&#xff0c;\u53ea\u6267\u884c\u4e00\u6b21\u6570\u636e\u5e93\u4e8b\u4ef6\u5904\u7406\u5e76\u590d\u7528\u7ed3\u679c\u5e7f\u64ad\u7ed9\u591a\u4e2a\u8ba2\u9605\u8005&#xff08;resolving\/SubscriptionsManagerForModel.scala \u7b2c 117-158 \u884c&#xff09;&#xff1b;<\/li>\n<li>\u4e8b\u4ef6\u901a\u9053&#xff1a;MutationChannelUtil \u4e3a\u6bcf\u4e2a\u6a21\u578b\u7684\u521b\u5efa\/\u66f4\u65b0\/\u5220\u9664\u5206\u522b\u6784\u9020\u9891\u9053\u540d createPost\u3001updatePost\u3001deletePost&#xff0c;\u5e76\u4ee5 subscription:event:$projectId:$channel \u7684\u5f62\u5f0f\u8ba2\u9605 pub\/sub \u6d88\u606f&#xff08;resolving\/MutationChannelUtil.scala&#xff09;&#xff1b;<\/li>\n<li>\u8f7d\u8377\u6784\u9020&#xff1a;SubscriptionResolver \u5c06\u6570\u636e\u5e93\u4e8b\u4ef6\u89e3\u6790\u4e3a DatabaseCreateEvent \/ DatabaseUpdateEvent \/ DatabaseDeleteEvent&#xff0c;\u5176\u4e2d\u66f4\u65b0\u4e8b\u4ef6\u643a\u5e26 changedFields&#xff08;\u5bf9\u5e94 updatedFields&#xff09;\u4e0e previousValues&#xff0c;\u5220\u9664\u4e8b\u4ef6\u643a\u5e26\u5220\u9664\u524d\u7684 node \u4f5c\u4e3a previousValues \u7684\u6570\u636e\u6765\u6e90&#xff08;resolving\/DatabaseEvents.scala \u4e0e resolving\/SubscriptionResolver.scala&#xff09;\u3002\u6ce8\u610f\u670d\u52a1\u7aef\u5bf9\u66f4\u65b0\/\u5220\u9664\u4e8b\u4ef6\u6784\u9020 previousValues\u3001\u5bf9\u521b\u5efa\u4e8b\u4ef6\u4e0d\u6784\u9020&#xff0c;\u8fd9\u4e0e\u6587\u6863 2.3 \u8282\u201cpreviousValues \u5bf9 CREATED \u6052\u4e3a null\u3001node \u5bf9 DELETED \u6052\u4e3a null\u201d\u7684\u8bed\u4e49\u5b8c\u5168\u5bf9\u5e94\u3002<\/li>\n<\/ul>\n<h4>5.3 Schema \u751f\u6210\u5668&#xff1a;\u8ba2\u9605\u7c7b\u578b\u5982\u4f55\u88ab\u81ea\u52a8\u751f\u6210<\/h4>\n<p>Prisma \u7684 GraphQL Schema \u751f\u6210\u5668&#xff08;cli\/packages\/prisma-generate-schema&#xff09;\u8d1f\u8d23\u4e3a\u6bcf\u4e2a\u6570\u636e\u6a21\u578b\u751f\u6210\u8ba2\u9605\u76f8\u5173\u7684 SDL \u7c7b\u578b&#xff0c;\u8fd9\u89e3\u91ca\u4e86 \/src\/generated\/prisma.graphql \u4e2d Subscription\u3001PostSubscriptionPayload\u3001PostSubscriptionWhereInput \u7684\u6765\u6e90&#xff1a;<\/p>\n<ul>\n<li>subscriptionGenerator.ts \u4e3a\u6bcf\u4e2a\u6a21\u578b\u751f\u6210\u5f62\u5982 post(where: PostSubscriptionWhereInput): PostSubscriptionPayload \u7684\u6839\u8ba2\u9605\u5b57\u6bb5&#xff08;src\/generator\/default\/subscription\/subscriptionGenerator.ts&#xff09;&#xff1b;<\/li>\n<li>modelSubscriptionPayloadGenerator.ts \u751f\u6210 mutation\u3001node\u3001updatedFields&#xff0c;\u5e76\u5728\u6a21\u578b\u542b\u6807\u91cf\u5b57\u6bb5\u65f6\u9644\u52a0 previousValues&#xff08;src\/generator\/default\/subscription\/modelSubscriptionPayloadGenerator.ts&#xff09;&#xff1b;<\/li>\n<li>modelSubscriptionWhereInputGenerator.ts \u751f\u6210 mutation_in\u3001updatedFields_contains\u3001updatedFields_contains_every\u3001updatedFields_contains_some\u3001node \u4ee5\u53ca AND\/OR\/NOT \u903b\u8f91\u7ec4\u5408&#xff08;src\/generator\/default\/subscription\/modelSubscriptionWhereInputGenerator.ts&#xff09;\u3002<\/li>\n<\/ul>\n<p>\u751f\u6210\u7ed3\u679c\u7684\u5b9e\u6d4b\u6837\u4f8b\u53ef\u4ee5\u67e5\u770b\u751f\u6210\u5668\u81ea\u5e26\u7684\u9ed1\u76d2\u6d4b\u8bd5 fixture&#xff0c;\u4f8b\u5982 cli\/packages\/prisma-generate-schema\/tests\/blackbox\/cases\/defaultValue\/document.graphql \u4e2d\u7684 ASubscriptionWhereInput&#xff08;\u7b2c 255-277 \u884c&#xff09;\u4e0e ASubscriptionPayload&#xff08;\u7b2c 248-253 \u884c&#xff09;&#xff0c;\u5b83\u4eec\u4e0e\u6587\u6863\u4e2d PostSubscriptionWhereInput \/ PostSubscriptionPayload \u7684\u7ed3\u6784\u4e00\u4e00\u5bf9\u5e94\u3002<\/p>\n<h3>\u603b\u7ed3<\/h3>\n<p>\u5728\u672c\u6559\u7a0b\u4e2d&#xff0c;\u4f60\u5b66\u4f1a\u4e86\u5982\u4f55\u4f7f\u7528 Prisma \u4e0e Prisma bindings \u4e3a GraphQL API \u6dfb\u52a0\u5b9e\u65f6\u8ba2\u9605\u80fd\u529b\u3002<\/p>\n<p>\u4e0e\u4f7f\u7528 Prisma \u5b9e\u73b0\u67e5\u8be2\u548c\u53d8\u66f4\u7c7b\u4f3c&#xff0c;\u4f60\u662f\u5728\u201c\u501f\u529b\u201d Prisma \u7684 GraphQL API&#xff0c;\u628a\u6570\u636e\u5e93\u8bbf\u95ee\u4e0e pub\/sub \u903b\u8f91\u7684\u91cd\u6d3b\u7559\u7ed9 Prisma \u67e5\u8be2\u5f15\u64ce\u627f\u62c5\u3002\u901a\u8fc7\u672c\u6587\u4f60\u5e94\u8be5\u638c\u63e1\u4e86&#xff1a;<\/p>\n<ul>\n<li>Prisma \u8ba2\u9605 API \u7684\u4e09\u7c7b\u4e8b\u4ef6&#xff08;CREATED \/ UPDATED \/ DELETED&#xff09;\u4e0e SubscriptionWhereInput \u7684\u8fc7\u6ee4\u8bed\u4e49&#xff08;mutation_in\u3001updatedFields_*\u3001node\u3001AND\/OR&#xff09;&#xff1b;<\/li>\n<li>SubscriptionPayload \u4e2d mutation\u3001node\u3001updatedFields\u3001previousValues \u56db\u4e2a\u5b57\u6bb5\u5404\u81ea\u7684\u53d6\u503c\u89c4\u5219&#xff1b;<\/li>\n<li>\u5e94\u7528\u5c42\u8ba2\u9605\u89e3\u6790\u5668\u4e2d subscribe&#xff08;\u8fd4\u56de AsyncIterator&#xff09;\u4e0e resolve&#xff08;\u8f6c\u6362\/\u8fc7\u6ee4\u4e8b\u4ef6\u8f7d\u8377&#xff09;\u7684\u5206\u5de5\u4e0e\u914d\u5408&#xff1b;<\/li>\n<li>\u8ba2\u9605\u4e8b\u4ef6\u4ece\u6570\u636e\u5e93\u53d8\u66f4\u3001pub\/sub \u9891\u9053\u5230 WebSocket \u63a8\u9001\u7684\u5b8c\u6574\u94fe\u8def\u5728\u4ed3\u5e93\u6e90\u7801\u4e2d\u7684\u843d\u5730\u4f4d\u7f6e\u3002<\/li>\n<\/ul>\n<p>  <img loading=\"lazy\" decoding=\"async\" class=\"gcb-icon-like\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/09\/20260929074903-6abb6d6f8d66c.svg\" alt=\"\" width=\"16\" height=\"16\" \/> <span class=\"gcb-like-text\">\u8d5e<\/span>  <\/p>\n<p>   <span class=\"gcb-share-text\">\u5206\u4eab<\/span>  <\/p>\n<ul class=\"gcb-tag-list\">\n<li><span class=\"gcb-tag\">\u540e\u7aef<\/span><\/li>\n<li><span class=\"gcb-tag\">\u6570\u636e\u5e93<\/span><\/li>\n<li><span class=\"gcb-tag\">GraphQL<\/span><\/li>\n<\/ul>\n<h3 class=\"gcb-project-title\">\u3010\u514d\u8d39\u4e0b\u8f7d\u94fe\u63a5\u3011prisma1<\/h3>\n<p class=\"gcb-project-desc\">&#x1f4be; Database Tools incl. ORM, Migrations and Admin UI (Postgres, MySQL &amp; MongoDB) [deprecated]<\/p>\n<p>    <span class=\"gcb-project-addr-label\">\u9879\u76ee\u5730\u5740&#xff1a;<\/span><br \/>\n    <span class=\"gcb-project-addr-link\">https:\/\/gitcode.com\/gh_mirrors\/pr\/prisma1<\/span> <\/p>\n<p>  <span class=\"gcb-project-btn\"> <span class=\"gcb-project-btn-main\">\u70b9\u51fb\u67e5\u770b<\/span> <span class=\"gcb-project-btn-sub\">\u514d\u8d39\u4e0b\u8f7d<\/span> <\/span> <\/p>\n<h4 class=\"gcb-related-title\">\u76f8\u5173\u63a8\u8350<\/h4>\n<ul class=\"gcb-related-list\">\n<li class=\"gcb-related-item\">\n<h5 class=\"gcb-related-item-title\">Prisma Binding \u5b9e\u6218\u6307\u5357&#xff1a;\u7528 GraphQL \u59d4\u6258\u89e3\u6790\u5668\u642d\u5efa\u57fa\u4e8e Prisma \u670d\u52a1\u7684 GraphQL \u670d\u52a1\u7aef<\/h5>\n<p class=\"gcb-related-item-desc\">Prisma Binding \u5b9e\u6218\u6307\u5357&#xff1a;\u7528 GraphQL \u59d4\u6258\u89e3\u6790\u5668\u642d\u5efa\u57fa\u4e8e Prisma \u670d\u52a1\u7684 GraphQL \u670d\u52a1\u7aef prisma binding \u662f <\/p>\n<p>     <span class=\"gcb-tag\">\u540e\u7aef<\/span><br \/>\n     <span class=\"gcb-tag\">\u6570\u636e\u5e93<\/span><br \/>\n     <span class=\"gcb-tag\">GraphQL<\/span>\n      <\/li>\n<li class=\"gcb-related-item\">\n<h5 class=\"gcb-related-item-title\">\u5982\u4f55\u5feb\u901f\u642d\u5efaBaiduPCS&#xff1a;\u4ece\u6e90\u7801\u7f16\u8bd1\u5230\u7cfb\u7edf\u5b89\u88c5\u7684\u5b8c\u6574\u6559\u7a0b<\/h5>\n<p class=\"gcb-related-item-desc\">\u5982\u4f55\u5feb\u901f\u642d\u5efaBaiduPCS&#xff1a;\u4ece\u6e90\u7801\u7f16\u8bd1\u5230\u7cfb\u7edf\u5b89\u88c5\u7684\u5b8c\u6574\u6559\u7a0b BaiduPCS\u662f\u4e00\u4e2a\u7528C\/C&#043;&#043;\u7f16\u5199\u7684\u767e\u5ea6\u7f51\u76d8\u547d\u4ee4\u884c\u5de5\u5177&#xff0c;\u652f\u6301\u591a\u7ebf\u7a0b\u4e0b\u8f7d\u3001\u65ad\u70b9\u7eed\u4f20\u3001\u5feb\u901f\u4e0a\u4f20\u7b49\u5f3a<\/p>\n<p>     <span class=\"gcb-tag\">CLI<\/span>\n      <\/li>\n<li class=\"gcb-related-item\">\n<h5 class=\"gcb-related-item-title\">EasyQRCodeJS\u6027\u80fd\u4f18\u5316&#xff1a;\u63d0\u5347\u4e8c\u7ef4\u7801\u751f\u6210\u901f\u5ea6\u548c\u5185\u5b58\u6548\u7387\u768410\u4e2a\u6280\u5de7<\/h5>\n<p class=\"gcb-related-item-desc\">EasyQRCodeJS\u6027\u80fd\u4f18\u5316&#xff1a;\u63d0\u5347\u4e8c\u7ef4\u7801\u751f\u6210\u901f\u5ea6\u548c\u5185\u5b58\u6548\u7387\u768410\u4e2a\u6280\u5de7 EasyQRCodeJS\u662f\u4e00\u6b3e\u5f3a\u5927\u7684JavaScript\u4e8c\u7ef4\u7801\u751f\u6210\u5e93&#xff0c;\u652f\u6301Canva<\/p>\n<\/li>\n<\/ul>\n<p>  <span class=\"gcb-prev-next-label\">\u4e0a\u4e00\u7bc7&#xff1a;<\/span><br \/>\n  Mac\u8fd0\u884cWindows\u8f6f\u4ef6\u7684\u7ec8\u6781\u4f18\u5316\u65b9\u6848&#xff1a;CXPatcher\u6280\u672f\u6df1\u5ea6\u89e3\u6790 <\/p>\n<p>  <span class=\"gcb-prev-next-label\">\u4e0b\u4e00\u7bc7&#xff1a;<\/span><br \/>\n  MediaPipe\u80cc\u666f\u5206\u5272\u7ec8\u6781\u6307\u5357&#xff1a;\u4ece\u6a21\u578b\u9009\u578b\u5230\u5b9e\u6218\u90e8\u7f72 <\/p>\n<p>\u521b\u4f5c\u58f0\u660e\uff1a\u672c\u6587\u90e8\u5206\u5185\u5bb9\u7531AI\u8f85\u52a9\u751f\u6210\uff08AIGC\uff09\uff0c\u4ec5\u4f9b\u53c2\u8003<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u540e\u7aef\u6570\u636e\u5e93GraphQL \u3010\u514d\u8d39\u4e0b\u8f7d\u94fe\u63a5\u3011prisma1 &#x1f4be; Database Tools incl. ORM, Migrations and Admin UI (Postgres, MySQL &amp; MongoDB) [deprecated] \u9879\u76ee\u5730\u5740&#xff1a; https:\/\/gitcode.com\/gh_mirrors\/pr\/prisma1 \u70b9\u51fb\u67e5\u770b \u514d\u8d39\u4e0b\u8f7d  \u672c\u6307\u5357\u57fa\u4e8e Prisma \u5b98\u65b9\u6559\u7a0b\u300aBuild a Realtime GraphQL S<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"topic":[],"class_list":["post-110870","post","type-post","status-publish","format-standard","hentry","category-server"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v20.3 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>\u4f7f\u7528 Prisma \u4e0e Prisma Bindings \u6784\u5efa\u5b9e\u65f6 GraphQL \u670d\u52a1\u5668\uff1aSubscriptions \u5b9e\u6218\u6307\u5357 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.wsisp.com\/helps\/110870.html\" \/>\n<meta property=\"og:locale\" content=\"zh_CN\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"\u4f7f\u7528 Prisma \u4e0e Prisma Bindings \u6784\u5efa\u5b9e\u65f6 GraphQL \u670d\u52a1\u5668\uff1aSubscriptions \u5b9e\u6218\u6307\u5357 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"og:description\" content=\"\u540e\u7aef\u6570\u636e\u5e93GraphQL \u3010\u514d\u8d39\u4e0b\u8f7d\u94fe\u63a5\u3011prisma1 &#x1f4be; Database Tools incl. ORM, Migrations and Admin UI (Postgres, MySQL &amp; MongoDB) [deprecated] \u9879\u76ee\u5730\u5740&#xff1a; https:\/\/gitcode.com\/gh_mirrors\/pr\/prisma1 \u70b9\u51fb\u67e5\u770b \u514d\u8d39\u4e0b\u8f7d \u672c\u6307\u5357\u57fa\u4e8e Prisma \u5b98\u65b9\u6559\u7a0b\u300aBuild a Realtime GraphQL S\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.wsisp.com\/helps\/110870.html\" \/>\n<meta property=\"og:site_name\" content=\"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"article:published_time\" content=\"2026-09-29T07:49:04+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/09\/20260929074903-6abb6d6f8d66c.svg\" \/>\n<meta name=\"author\" content=\"admin\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"\u4f5c\u8005\" \/>\n\t<meta name=\"twitter:data1\" content=\"admin\" \/>\n\t<meta name=\"twitter:label2\" content=\"\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4\" \/>\n\t<meta name=\"twitter:data2\" content=\"8 \u5206\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/110870.html\",\"url\":\"https:\/\/www.wsisp.com\/helps\/110870.html\",\"name\":\"\u4f7f\u7528 Prisma \u4e0e Prisma Bindings \u6784\u5efa\u5b9e\u65f6 GraphQL \u670d\u52a1\u5668\uff1aSubscriptions \u5b9e\u6218\u6307\u5357 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\",\"isPartOf\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#website\"},\"datePublished\":\"2026-09-29T07:49:04+00:00\",\"dateModified\":\"2026-09-29T07:49:04+00:00\",\"author\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41\"},\"breadcrumb\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/110870.html#breadcrumb\"},\"inLanguage\":\"zh-Hans\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.wsisp.com\/helps\/110870.html\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/110870.html#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"\u9996\u9875\",\"item\":\"https:\/\/www.wsisp.com\/helps\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"\u4f7f\u7528 Prisma \u4e0e Prisma Bindings \u6784\u5efa\u5b9e\u65f6 GraphQL \u670d\u52a1\u5668\uff1aSubscriptions \u5b9e\u6218\u6307\u5357\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#website\",\"url\":\"https:\/\/www.wsisp.com\/helps\/\",\"name\":\"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\",\"description\":\"\u9999\u6e2f\u670d\u52a1\u5668_\u9999\u6e2f\u4e91\u670d\u52a1\u5668\u8d44\u8baf_\u670d\u52a1\u5668\u5e2e\u52a9\u6587\u6863_\u670d\u52a1\u5668\u6559\u7a0b\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.wsisp.com\/helps\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"zh-Hans\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41\",\"name\":\"admin\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"zh-Hans\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery\",\"contentUrl\":\"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery\",\"caption\":\"admin\"},\"sameAs\":[\"http:\/\/wp.wsisp.com\"],\"url\":\"https:\/\/www.wsisp.com\/helps\/author\/admin\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"\u4f7f\u7528 Prisma \u4e0e Prisma Bindings \u6784\u5efa\u5b9e\u65f6 GraphQL \u670d\u52a1\u5668\uff1aSubscriptions \u5b9e\u6218\u6307\u5357 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.wsisp.com\/helps\/110870.html","og_locale":"zh_CN","og_type":"article","og_title":"\u4f7f\u7528 Prisma \u4e0e Prisma Bindings \u6784\u5efa\u5b9e\u65f6 GraphQL \u670d\u52a1\u5668\uff1aSubscriptions \u5b9e\u6218\u6307\u5357 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","og_description":"\u540e\u7aef\u6570\u636e\u5e93GraphQL \u3010\u514d\u8d39\u4e0b\u8f7d\u94fe\u63a5\u3011prisma1 &#x1f4be; Database Tools incl. ORM, Migrations and Admin UI (Postgres, MySQL &amp; MongoDB) [deprecated] \u9879\u76ee\u5730\u5740&#xff1a; https:\/\/gitcode.com\/gh_mirrors\/pr\/prisma1 \u70b9\u51fb\u67e5\u770b \u514d\u8d39\u4e0b\u8f7d \u672c\u6307\u5357\u57fa\u4e8e Prisma \u5b98\u65b9\u6559\u7a0b\u300aBuild a Realtime GraphQL S","og_url":"https:\/\/www.wsisp.com\/helps\/110870.html","og_site_name":"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","article_published_time":"2026-09-29T07:49:04+00:00","og_image":[{"url":"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/09\/20260929074903-6abb6d6f8d66c.svg"}],"author":"admin","twitter_card":"summary_large_image","twitter_misc":{"\u4f5c\u8005":"admin","\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4":"8 \u5206"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.wsisp.com\/helps\/110870.html","url":"https:\/\/www.wsisp.com\/helps\/110870.html","name":"\u4f7f\u7528 Prisma \u4e0e Prisma Bindings \u6784\u5efa\u5b9e\u65f6 GraphQL \u670d\u52a1\u5668\uff1aSubscriptions \u5b9e\u6218\u6307\u5357 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","isPartOf":{"@id":"https:\/\/www.wsisp.com\/helps\/#website"},"datePublished":"2026-09-29T07:49:04+00:00","dateModified":"2026-09-29T07:49:04+00:00","author":{"@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41"},"breadcrumb":{"@id":"https:\/\/www.wsisp.com\/helps\/110870.html#breadcrumb"},"inLanguage":"zh-Hans","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.wsisp.com\/helps\/110870.html"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.wsisp.com\/helps\/110870.html#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"\u9996\u9875","item":"https:\/\/www.wsisp.com\/helps"},{"@type":"ListItem","position":2,"name":"\u4f7f\u7528 Prisma \u4e0e Prisma Bindings \u6784\u5efa\u5b9e\u65f6 GraphQL \u670d\u52a1\u5668\uff1aSubscriptions \u5b9e\u6218\u6307\u5357"}]},{"@type":"WebSite","@id":"https:\/\/www.wsisp.com\/helps\/#website","url":"https:\/\/www.wsisp.com\/helps\/","name":"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","description":"\u9999\u6e2f\u670d\u52a1\u5668_\u9999\u6e2f\u4e91\u670d\u52a1\u5668\u8d44\u8baf_\u670d\u52a1\u5668\u5e2e\u52a9\u6587\u6863_\u670d\u52a1\u5668\u6559\u7a0b","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.wsisp.com\/helps\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"zh-Hans"},{"@type":"Person","@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41","name":"admin","image":{"@type":"ImageObject","inLanguage":"zh-Hans","@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/image\/","url":"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery","contentUrl":"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery","caption":"admin"},"sameAs":["http:\/\/wp.wsisp.com"],"url":"https:\/\/www.wsisp.com\/helps\/author\/admin"}]}},"_links":{"self":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts\/110870","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/comments?post=110870"}],"version-history":[{"count":0,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts\/110870\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/media?parent=110870"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/categories?post=110870"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/tags?post=110870"},{"taxonomy":"topic","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/topic?post=110870"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}