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

2023-11-27

I am using React with Strapi and GrapqQL in order to retreive my data from Strapi. Seems that my query retrieves only maximum 10 items. The API is changed with this new version and I am not allowed to use first:100 in the query. enter image description here

这个链接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
                  }
                }
              }
            }
        }
    }
  }
`

Strapi v4 的文档可用here.

你可以尝试一下:

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

默认值和最大值pagination[limit] can be 配置在./config/plugins.js文件与graphql.config.defaultLimit and graphql.config.maxLimit keys.

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

GraphQL - 从 Strapi 中仅检索最多 10 个项目 的相关文章

随机推荐