Home > Software design >  GraphQL - retrieves only maximum 10 items from Strapi
GraphQL - retrieves only maximum 10 items from Strapi

Time:01-18

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
                  }
                }
              }
            }
        }
    }
  }
`

CodePudding user response:

The documentation for Strapi v4 is available here.

Could you try with:

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
                  }
                }
              }
            }
        }
    }
  }
`

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.

  •  Tags:  
  • Related