【问题标题】:GraphQL - retrieves only maximum 10 items from StrapiGraphQL - 从 Strapi 仅检索最多 10 个项目
【发布时间】:2022-01-18 17:23:26
【问题描述】:

我将 React 与 Strapi 和 GrapqQL 一起使用,以便从 Strapi 检索我的数据。 似乎我的查询最多只能检索 10 个项目。这个新版本更改了 API,我不允许在查询中使用 first:100

此链接1 已过时。我不知道这是来自 Strapi 还是 GraphQL 新版本的策略。 1https://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
                  }
                }
              }
            }
        }
    }
  }
`

【问题讨论】:

    标签: reactjs graphql strapi


    【解决方案1】:

    Strapi v4 的文档在here 可用。

    你可以试试:

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

    pagination[limit] 的默认值和最大值可以是带有graphql.config.defaultLimitgraphql.config.maxLimit 键的configured in the ./config/plugins.js 文件。

    【讨论】:

    • 伟大的秘诀,皮埃尔!这些是您花费大量时间调试的事情之一。
    猜你喜欢
    • 2021-12-12
    • 1970-01-01
    • 2019-04-26
    • 2012-05-16
    • 2019-08-02
    • 1970-01-01
    • 1970-01-01
    • 2021-04-13
    相关资源
    最近更新 更多