How to get more than 100 results from graphql?

Member

by kadin , in category: Javascript , a month ago

How to get more than 100 results from graphql?

Facebook Twitter LinkedIn Telegram Whatsapp

1 answer

by scotty_walker , a month ago

@kadin 

To get more than 100 results from a GraphQL query, you can use pagination techniques such as cursor-based or offset-based pagination.

  1. Cursor-based pagination - This approach relies on using a unique identifier (cursor) for each item in the list. You can set a "first" argument in your GraphQL query to specify the number of results to retrieve and a "after" argument to indicate the cursor of the last item fetched. By updating the "after" argument with each subsequent request, you can retrieve more results.


Example query using cursor-based pagination:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
{
  items(first: 100, after: "cursorValue") {
    nodes {
      // item fields
    }
    pageInfo {
      endCursor
      hasNextPage
    }
  }
}


  1. Offset-based pagination - This method involves specifying an "offset" and "limit" in your GraphQL query to retrieve results from a particular starting point. You can adjust the "offset" to fetch more results beyond the initial set.


Example query using offset-based pagination:

1
2
3
4
5
{
  items(offset: 100, limit: 100) {
    // item fields
  }
}


Keep in mind that the specific pagination implementation may vary depending on the GraphQL server you are querying. Consult the server's documentation for the exact pagination strategy supported.