How can I display n items in GraphQL? | Community
Skip to main content
Level 2
September 7, 2022

How can I display n items in GraphQL?

  • September 7, 2022
  • 1 reply
  • 799 views

I want to get only n results of a query in GraphiQL Explorer.
The GraphQL documentation says that I can use first, but when I try to use it in GraphiQL Explorer, I get an error.

 

query allEventsTest { eventsTestList(first:10) { items { _path } } }
This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.

1 reply

HeenaMadan
Community Advisor and Adobe Champion
Community Advisor and Adobe Champion
September 9, 2022

You can use limit and offset. Let's say you need 10 pages only. This will fetch 10 blog posts starting from the 1st record.

query { blogPosts(limit: 10, offset: 0) { title author { name authorImage } } }

For second page, use limit: 10, offset: 10, This will fetch 10 records starting from the 11th record and so on.

satoshi1Author
Level 2
September 9, 2022

Hi HeenaMadan,

I tried the following query in GraphiQL Explorer and got an error "Unknown argument "limit" on field "QueryType.eventList"".

 query {
   eventsTestList(limit: 10, offset: 0) {
    items {
      _path
    }
  }
}

 

From the answers to the following questions, it appears that Paging/Sorting is not yet supported.

https://experienceleaguecommunities.adobe.com/t5/adobe-experience-manager/aem-headless-graphql-sort/td-p/542222