GraphQL - 从 Strapi 中仅检索最多 10 个项目

11 reactjs graphql strapi

我将 React 与 Strapi 和 GrapqQL 结合使用,以便从 Strapi 检索我的数据。看来我的查询最多只检索 10 个项目。API 在这个新版本中发生了变化,我不允许first:100在查询中使用。 在此输入图像描述

此链接1已过时。我不知道这是 Strapi 还是 GraphQL 新版本的政策。 1 https://graphql.org/learn/pagination/

const REVIEWS = gql`
  query GetReviews {
    reviews (sort: "createdAt:desc") {
        data{
            id
            attributes{
              title
              rating
              body
              createdAt
              categories{
                data{
                  id
                  attributes
                  {
                    name
                  }
                }
              }
            }
        }
    }
  }
`
Run Code Online (Sandbox Code Playgroud)

Pie*_*rre 21

Strapi v4 的文档可在此处获取。

你能尝试一下:

const REVIEWS = gql`
  query GetReviews {
    reviews (sort: "createdAt:desc", pagination: { limit: 100 }) {
        data{
            id
            attributes{
              title
              rating
              body
              createdAt
              categories{
                data{
                  id
                  attributes
                  {
                    name
                  }
                }
              }
            }
        }
    }
  }
`
Run Code Online (Sandbox Code Playgroud)

的默认值和最大值pagination[limit]可以使用和键./config/plugins.js文件中配置。graphql.config.defaultLimitgraphql.config.maxLimit