apollo客户端onSubscriptionData无法正常工作

问题描述 投票:1回答:1

我正在关注apollo subscriptions tutorial并且我的订阅正在运行,但我没有使用onSubscriptionData数据回调。

这是我的代码:

const MESSAGE_CREATED = gql`
  subscription {
    messageCreated {
      id
      content
    }
  }
`;

const MyComponent = () => (
  <Subscription
      subscription={MESSAGE_CREATED}
      onSubscriptionData={() => {
        console.log('subs');
      }}
    >
      {({ data, loading }) => {
        if (loading && !data) return <View />;
        return (
          <Text>New comment: {!loading && data.messageCreated.content}</Text>
        );
      }}
    </Subscription>
);

我没有在我的控制台上获得子日志。

reactjs react-native graphql apollo react-apollo
1个回答
2
投票

此功能仅适用于“主”分支。我只是测试了它,'onSubscriptionData'道具正在按需运行。如果你想测试它,你应该:

  1. 将'react-apollo'软件包版本更新为'master',如下所示:“react-apollo”:“apollographql / react-apollo”
  2. 编译执行的TS代码:cd node_modules / react-apollo && yarn && yarn compile
  3. 将所有导入路径从“react-apollo”重构为“react-apollo / lib”,如下所示:从“react-apollo / lib”导入{Subscription}
© www.soinside.com 2019 - 2024. All rights reserved.