Apollo 客户端 useQuery 挂钩上的轮询间隔选项不起作用

Ale*_*len 5 javascript reactjs apollo-server apollo-client

我有一个使用 apollo 服务器和客户端(react)的简单的类似论坛的应用程序,并且我尝试使用 useQuery 挂钩上的 pollInterval 选项定期更新主页上的帖子。它似乎实际上没有做任何事情,当我发表新帖子时,页面没有更新。

这是我获取数据库中所有帖子的查询,

  const { loading, data } = useQuery(QUERY_POSTS, {
    pollInterval: 1000,
  });
Run Code Online (Sandbox Code Playgroud)

我正在通过这里的数据进行映射

{loading && <div>loading....</div>}

        {data?.posts.map((post) => (
          <Card className="mb-5 w-50 " key={post._id}>
            {post.imgUrl && <Card.Img variant="top" src={post.imgUrl} />}

            <Card.Body>
              <Card.Text>{post.postText}</Card.Text>
              <Button
                variant="warning"
                type="button"
                onClick={(e) => handlePostLike(post._id, e)}
              >
                {post.likeCount} <BsFillEmojiSunglassesFill />
              </Button>
            </Card.Body>
          </Card>
        ))}
Run Code Online (Sandbox Code Playgroud)

不确定我是否应该使用订阅,或者我是否只是错误地使用了轮询功能。