为别名实现apollo fetchMore

时间:2019-12-20 20:36:28

标签: reactjs apollo react-apollo react-apollo-hooks

我在React中实现了apollo客户端,而我试图对查询进行批处理。 我想批处理这两个查询(请参阅下面的架构),然后添加单独的分页。 所以我想为每个别名实现fetchMore。 是否可以仅获取更多(例如仅历史别名)?

模式:

export const TEST = gql`
  query getUserAction(
    $historic: Boolean!
    $active: Boolean!
    $userId: ID!
    $cursor: Int
    $limit: Int
  ) {
    active: getUserAction(
      historic: $historic
      userId: $userId
      cursor: $cursor
      limit: $limit
    ) {
      next
      count
      data {
        msg {
          id
          text
          action
        }
      }
    }

    historic: getUserAction(
      historic: $historic
      userId: $userId
      cursor: $cursor
      limit: $limit
    ) {
      next
      count
      data {
        msg {
          id
          text
          action
        }
      }
    }
  }
`;

查询组件:

const { loading, data, fetchMore } = useQuery(TEST, {
    fetchPolicy: 'network-only',
    variables: {
        historic: true,
        active: false,
        userId: userId,
        cursor: 0,
        limit: 10,
    },
    onCompleted: data => {
        console.log(data)
    }
});

0 个答案:

没有答案