8

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

This link 1 is obsolete. I don't know if this is a policy from Strapi's or GraphQL's new version. 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
                  }
                }
              }
            }
        }
    }
  }
`

1 Answers1

17

The documentation for Strapi v4 is available here.

Could you try with:

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

The default and maximum values for pagination[limit] can be configured in the ./config/plugins.js file with the graphql.config.defaultLimit and graphql.config.maxLimit keys.

idmean
  • 14,540
  • 9
  • 54
  • 83
Pierre
  • 986
  • 8
  • 13
  • great tip, Pierre! these is one of those things that you spend a lot of time debugging. – TOPAiiN May 07 '22 at 00:27
  • Great, thank you! Kept wondering why I only ever received ten items and not more, no matter what I had configured. There are even a couple of PRs that address problems with limit/amountLimit, but they are quite old and didn't help with my queries. – Gorgsenegger Dec 11 '22 at 11:38