Reactjs Graphql查询中的参数无效
我收到一个阵列,包含13000个对象。我想用阿波罗钩子进行分页,并将限制设置为10Reactjs Graphql查询中的参数无效,reactjs,graphql,apollo,react-apollo,Reactjs,Graphql,Apollo,React Apollo,我收到一个阵列,包含13000个对象。我想用阿波罗钩子进行分页,并将限制设置为10 export const GET_PRODUCTS = gql` query GetProducts($type: String, $offset: Int, $limit: Int!) { products @rest( type: "Products" path: "/a-third-party-api"
export const GET_PRODUCTS = gql`
query GetProducts($type: String, $offset: Int, $limit: Int!) {
products
@rest(
type: "Products"
path: "/a-third-party-api"
) {
productFeed(offset: $offset, limit: $limit) {
productName
productPrice
productImage
}
}
}
`;
这将返回13.000个对象,我确实希望极限变量将其设置为10
function MyComponent() {
const { loading, error, data, fetchMore } = useQuery(GET_PRODUCTS, {
variables: { type: "feed", offset: 0, limit: 10 },
fetchPolicy: "cache-and-network",
});
console.log(data)
...
}
值得一提的是,它是一个第三方api,我正在使用apollo rest链接。反应很好
是否可以使用限制并与第三方进行分页?API是否支持分页?您不能在url中添加设置限制的查询,因此不,我不认为如此,但您将如何处理该大小的请求,要减少加载时间?如果REST API支持分页,则将一些分页变量注入到
path
字符串中,或在pathBuilder
选项中使用一些fn