@4c/graphql-relay-subscription 中文文档教程

发布于 3年前 浏览 24 项目主页 更新于 3年前

graphql-relay-subscription Travisnpm

中继 GraphQL.js 订阅助手

CodecovDiscord

Usage

与 graphql-relay-js 中的 mutationWithClientId 一样,subscriptionWithClientId 使用单个输入和客户端订阅 ID 创建订阅。

import { parse, subscribe } from 'graphql';
import { subscriptionWithClientId } from 'graphql-relay-subscription';

/* ... */

const UpdateWidgetSubscription = subscriptionWithClientId({
  name: 'UpdateWidgetSubscription',
  inputFields: {
    widgetId: { type: GraphQLString },
  },
  outputFields: {
    widget: Widget,
  },
  subscribe: ({ widgetId }) =>
    createSubscription(`widgets:${widgetId}:updated`),
});

const subscription = await subscribe(
  schema,
  parse(`
    subscription ($input_0: UpdateWidgetSubscriptionInput!) {
      updateWidget(input: $input_0) {
        widget {
          name
        }
        clientSubscriptionId
      }
    }
  `),
  null,
  null,
  {
    input_0: {
      widgetId: 'foo',
      clientSubscriptionId: '0',
    },
  },
);

graphql-relay-subscription Travisnpm

Relay subscription helper for GraphQL.js.

CodecovDiscord

Usage

As with mutationWithClientId in graphql-relay-js, subscriptionWithClientId creates subscriptions with single inputs and client subscription IDs.

import { parse, subscribe } from 'graphql';
import { subscriptionWithClientId } from 'graphql-relay-subscription';

/* ... */

const UpdateWidgetSubscription = subscriptionWithClientId({
  name: 'UpdateWidgetSubscription',
  inputFields: {
    widgetId: { type: GraphQLString },
  },
  outputFields: {
    widget: Widget,
  },
  subscribe: ({ widgetId }) =>
    createSubscription(`widgets:${widgetId}:updated`),
});

const subscription = await subscribe(
  schema,
  parse(`
    subscription ($input_0: UpdateWidgetSubscriptionInput!) {
      updateWidget(input: $input_0) {
        widget {
          name
        }
        clientSubscriptionId
      }
    }
  `),
  null,
  null,
  {
    input_0: {
      widgetId: 'foo',
      clientSubscriptionId: '0',
    },
  },
);
    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文