无法读取Apollo中未定义的属性'subscribeToMore'

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

我正在尝试在Apollo客户端中创建订阅,但是每次保存组件导致刷新时,都会出现此错误:

enter image description here

这是我的代码:

const QUERY = gql`
  {
    getEventsSection(id: "trending") {
      _id,
      events 
    }
  }
`;

const SUBSCRIPTION = gql`
    subscription {
      getEventsSection(id: "trending") {
        _id,
        events 
      }
    }
`;
    const [state, setState] = useState(null);
        const { loading, error, data, subscribeToMore } = useQuery(QUERY);

        useEffect(() => {
            const unsubscribe = subscribeToMore({
                document: SUBSCRIPTION,
                updateQuery: (prev, {subscriptionData}) => {
                    console.log(subscriptionData);
                }
            });
            return () => unsubscribe();
        }, [data])

我在做什么错?谢谢!

reactjs react-native
1个回答
0
投票

您似乎没有在updateQuery回调中返回任何内容。

per docs

请注意,updateQuery回调必须返回与初始查询数据形状相同的对象,否则新数据将不会合并。在这里,新评论将被推送到条目的评论列表中:

也有remove unsubscribe在使用中

© www.soinside.com 2019 - 2024. All rights reserved.