小编i-G*_*uru的帖子

Apollo 客户端在 next.js、javascript、graphql、react js 中出现问题

如果我首先访问主页或刷新主页,我无法在解析器中获取配置文件,因为 cache.readQuery 不起作用。

以及它无限地调用api。

如果我移动到另一个页面并再次回到主页,cache.readQuery 工作并正确获取帖子的个人资料和投票状态。

有没有人遇到过这个问题?home.tsx 是我项目的主页。

此外, useQuery(@apollo/react-hooks) 获取每个页面上的旧数据。

如果您有经验,请帮助我。

  • 主页.tsx
    ...
    const GET_POSTS = graphql`
      query posts($accountname: String!, $page: Int, $pathBuilder: any, $postsStatus: String) {
        posts(accountname: $accountname, page: $page, postsStatus: $postsStatus)
          @rest(type: "Post", pathBuilder: $pathBuilder) {
          post_id
          author
          voteStatus(accountname: $accountname) @client
          created_at
        }
      }
    `;
    interface Props {
      author: string;
    }
    const Home: NextPage<Props> = ({ author }) => {
      const { data, fetchMore, loading } = useQuery(GET_POSTS, {
        variables: {
          accountname: author,
          page: 1,
          postsStatus: 'home', …
Run Code Online (Sandbox Code Playgroud)

javascript caching apollo reactjs graphql

11
推荐指数
1
解决办法
817
查看次数

标签 统计

apollo ×1

caching ×1

graphql ×1

javascript ×1

reactjs ×1