{"id":136104,"date":"2025-08-13T09:21:49","date_gmt":"2025-08-13T06:21:49","guid":{"rendered":"https:\/\/www.javacodegeeks.com\/?p=136104"},"modified":"2025-08-13T09:21:51","modified_gmt":"2025-08-13T06:21:51","slug":"paginating-data-in-spring-boot-graphql","status":"publish","type":"post","link":"https:\/\/www.javacodegeeks.com\/paginating-data-in-spring-boot-graphql.html","title":{"rendered":"Paginating Data in Spring Boot GraphQL"},"content":{"rendered":"<p>GraphQL APIs can return large datasets, and without pagination, performance issues may arise. Spring Boot provides excellent support for GraphQL through the <code>spring-boot-starter-graphql<\/code> dependency. Let us delve into understanding spring boot graphql pagination and how it enhances data fetching efficiency in modern applications.<\/p>\n<h2><a name=\"section-1\"><\/a>1. What is GraphQL?<\/h2>\n<p>GraphQL is an open-source query language for your API and a runtime for executing those queries with your existing data. Developed by Facebook, it allows clients to request exactly the data they need, reducing over-fetching and under-fetching common with traditional REST APIs. Instead of having multiple endpoints for different data sets, <a href=\"https:\/\/graphql.org\/learn\/\" target=\"_blank\" rel=\"noopener\">GraphQL<\/a> consolidates data fetching into a single flexible endpoint. Clients can compose complex queries, nest resources, and request related data in one round trip.<\/p>\n<h3>1.1 What is Pagination?<\/h3>\n<p><a href=\"https:\/\/graphql.org\/learn\/pagination\/\" target=\"_blank\" rel=\"noopener\">Pagination<\/a> is a technique used in APIs to break large datasets into smaller, more manageable chunks. This improves performance, reduces memory consumption, and avoids overloading clients and servers with too much data at once. In <a href=\"https:\/\/graphql.org\/learn\/pagination\/\" target=\"_blank\" rel=\"noopener\">GraphQL pagination<\/a>, it is commonly implemented using either:<\/p>\n<ul>\n<li>Page-based pagination: where data is divided by pages (e.g., page number and size).<\/li>\n<li>Cursor-based pagination: where data is fetched using a cursor or ID from the last record of the previous batch.<\/li>\n<\/ul>\n<h4>1.1.1 Use Cases and Importance of Pagination<\/h4>\n<ul>\n<li>Pagination helps divide large datasets into manageable chunks, improving both server and client performance.<\/li>\n<li>It minimizes memory consumption and reduces the data transferred over the network.<\/li>\n<li>It enhances user experience by loading content faster and allowing incremental content access (e.g., infinite scroll or pages).<\/li>\n<li>Pagination reduces database load by limiting the number of rows processed in a single query.<\/li>\n<\/ul>\n<h4>1.1.2 Page-based vs Cursor-based Pagination<\/h4>\n<ul>\n<li>Page-based Pagination: Ideal for simple UI needs such as numbered pages or when jumping to a specific page is required.<\/li>\n<li>Best used when data changes infrequently or consistency isn&#8217;t a concern.<\/li>\n<li>Cursor-based Pagination: Suitable for high-performance scenarios and large datasets where sorting is consistent and stable.<\/li>\n<li>Prevents issues with data shifting during pagination, making it reliable in dynamic datasets (e.g., social feeds, logs).<\/li>\n<\/ul>\n<h2><a name=\"section-2\"><\/a>2. Code Example<\/h2>\n<p>This section walks through a complete Spring Boot GraphQL application with support for page-based pagination using an H2 in-memory database. Additionally, we show how to fetch results after a certain ID using a custom repository method.<\/p>\n<h3>2.1 Setting up the Project<\/h3>\n<p>Start by adding the required Spring Boot and GraphQL dependencies to your Maven <code>pom.xml<\/code> file.<\/p>\n<pre class=\"brush:xml; wrap-lines:false;\">&lt;dependencies&gt;\n    &lt;dependency&gt;\n        &lt;groupId&gt;org.springframework.boot&lt;\/groupId&gt;\n        &lt;artifactId&gt;spring-boot-starter-graphql&lt;\/artifactId&gt;\n    &lt;\/dependency&gt;\n    &lt;dependency&gt;\n        &lt;groupId&gt;org.springframework.boot&lt;\/groupId&gt;\n        &lt;artifactId&gt;spring-boot-starter-data-jpa&lt;\/artifactId&gt;\n    &lt;\/dependency&gt;\n    &lt;dependency&gt;\n        &lt;groupId&gt;com.h2database&lt;\/groupId&gt;\n        &lt;artifactId&gt;h2&lt;\/artifactId&gt;\n        &lt;scope&gt;runtime&lt;\/scope&gt;\n    &lt;\/dependency&gt;\n&lt;\/dependencies&gt;\n<\/pre>\n<h3>2.2 Create support Classes<\/h3>\n<p>Define a simple JPA entity <code>Book<\/code> with fields for ID, title, and author.<\/p>\n<pre class=\"brush:java; wrap-lines:false;\">@Entity\npublic class Book {\n    @Id\n    @GeneratedValue(strategy = GenerationType.IDENTITY)\n    private Long id;\n    private String title;\n    private String author;\n\n    \/\/ Constructors\n    public Book() {}\n    public Book(String title, String author) {\n        this.title = title;\n        this.author = author;\n    }\n\n    \/\/ Getters and setters\n}\n<\/pre>\n<p>Create the POJO class which will encapsulate paginated results with metadata.<\/p>\n<pre class=\"brush:java; wrap-lines:false;\">import java.util.List;\n\npublic class BookPage {\n    private List&lt;Book&gt; content;\n    private int totalPages;\n    private long totalElements;\n    private int currentPage;\n    private int pageSize;\n\n    public BookPage() {}\n\n    public BookPage(List content, int totalPages, long totalElements, int currentPage, int pageSize) {\n        this.content = content;\n        this.totalPages = totalPages;\n        this.totalElements = totalElements;\n        this.currentPage = currentPage;\n        this.pageSize = pageSize;\n    }\n\n    \/\/ Getters and Setters\n}\n<\/pre>\n<h3>2.3 Create the Repository Interface<\/h3>\n<p>Create a Spring Data JPA repository with a custom query for pagination starting after a specific ID.<div style=\"display:inline-block; margin: 15px 0;\"> <div id=\"adngin-JavaCodeGeeks_incontent_video-0\" style=\"display:inline-block;\"><\/div> <\/div><\/p>\n<pre class=\"brush:java; wrap-lines:false;\">@Repository\npublic interface BookRepository extends JpaRepository&lt;Book, Long&gt; {\n\n    @Query(\"SELECT b FROM Book b WHERE b.id &gt; :afterId ORDER BY b.id ASC\")\n    List&lt;Book&gt; findTopNAfterId(@Param(\"afterId\") Long afterId, Pageable pageable);\n}\n<\/pre>\n<h4>2.3.1 Code Explanation<\/h4>\n<p>The BookRepository interface extends JpaRepository to provide CRUD operations for the Book entity. It includes a custom query method, findTopNAfterId, which retrieves a list of Book records where the ID is greater than a given afterId. This method uses a JPQL query annotated with @Query to filter and order results by ascending ID, supporting cursor-based pagination. The Pageable parameter controls the number of results returned, enabling efficient slicing of data sets in a GraphQL pagination scenario.<\/p>\n<h3>2.4 GraphQL Pagination Schema<\/h3>\n<p>Define the GraphQL schema in <code>schema.graphqls<\/code> to support a paginated <code>books<\/code> query with optional cursor-based support.<\/p>\n<pre class=\"brush:plain; wrap-lines:false;\"># schema.graphqls\ntype Book {\n    id: ID\n    title: String\n    author: String\n}\n\ntype BookPage {\n    content: [Book]\n    totalPages: Int\n    totalElements: Int\n    currentPage: Int\n    pageSize: Int\n}\n\ntype Query {\n    books(page: Int, size: Int, afterId: ID): BookPage\n}\n<\/pre>\n<h4>2.4.1 Code Explanation<\/h4>\n<p>The <code>schema.graphqls<\/code> file defines the GraphQL schema for handling book-related queries with pagination support. It introduces a <code>Book<\/code> type representing individual books with fields like <code>id<\/code>, <code>title<\/code>, and <code>author<\/code>. To support pagination, the <code>BookPage<\/code> type wraps a list of books under <code>content<\/code> along with metadata such as <code>totalPages<\/code>, <code>totalElements<\/code>, <code>currentPage<\/code>, and <code>pageSize<\/code>. The <code>Query<\/code> type exposes a <code>books<\/code> query that accepts optional arguments <code>page<\/code>, <code>size<\/code>, and <code>afterId<\/code>, enabling both page-based and cursor-based pagination in the Spring Boot GraphQL application.<\/p>\n<h3>2.5 Implementing Pagination Resolver<\/h3>\n<p>Implement the query resolver to call the custom repository method and return a <code>BookPage<\/code>.<\/p>\n<pre class=\"brush:java; wrap-lines:false;\">@Component\npublic class BookQueryResolver implements GraphQLQueryResolver {\n\n    @Autowired\n    private BookRepository bookRepository;\n\n    public BookPage getBooks(Integer page, Integer size, Long afterId) {\n        Pageable pageable = PageRequest.of(page != null ? page : 0, size != null ? size : 5);\n\n        List&lt;Book&gt; books;\n        long totalElements;\n        int totalPages;\n\n        if (afterId != null) {\n            books = bookRepository.findTopNAfterId(afterId, pageable);\n            totalElements = books.size();\n            totalPages = (int) Math.ceil((double) totalElements \/ pageable.getPageSize());\n        } else {\n            Page&lt;Book&gt; bookPage = bookRepository.findAll(pageable);\n            books = bookPage.getContent();\n            totalElements = bookPage.getTotalElements();\n            totalPages = bookPage.getTotalPages();\n        }\n\n        return new BookPage(books, totalPages, totalElements, pageable.getPageNumber(), pageable.getPageSize());\n    }\n}\n<\/pre>\n<h4>2.5.1 Code Explanation<\/h4>\n<p>The BookQueryResolver class is a Spring component that implements GraphQLQueryResolver to handle GraphQL queries. It defines the getBooks method, which supports both page-based and cursor-based pagination. The method accepts optional parameters: page, size, and afterId. If afterId is provided, it uses the custom repository method findTopNAfterId to return a slice of books starting after a specific ID, enabling cursor-based pagination. Otherwise, it uses the standard findAll method with PageRequest to return a Page object for page-based pagination. The response is wrapped in a BookPage object containing the book list, total pages, total elements, current page, and page size, making it suitable for GraphQL pagination implementations.<\/p>\n<h3>2.6 Create a Controller Class<\/h3>\n<p>Although optional for GraphQL, you can include a REST controller for testing or additional exposure.<\/p>\n<pre class=\"brush:java; wrap-lines:false;\">@RestController\n@RequestMapping(\"\/api\")\npublic class BookController {\n\n    @Autowired\n    private BookRepository bookRepository;\n\n    @GetMapping(\"\/books\")\n    public List&lt;Book&gt; getAllBooks() {\n        return bookRepository.findAll();\n    }\n}\n<\/pre>\n<h3>2.7 Create a Main Class and Adding Mock Data in H2<\/h3>\n<p>Create the Spring Boot entry point and preload mock data into the H2 database using the <code>CommandLineRunner<\/code>.<\/p>\n<pre class=\"brush:java; wrap-lines:false;\">@SpringBootApplication\npublic class BookServiceApplication implements CommandLineRunner {\n\n    @Autowired\n    private BookRepository bookRepository;\n\n    public static void main(String[] args) {\n        SpringApplication.run(BookServiceApplication.class, args);\n    }\n\n    @Override\n    public void run(String... args) throws Exception {\n        bookRepository.save(new Book(\"The Hobbit\", \"J.R.R. Tolkien\"));\n        bookRepository.save(new Book(\"1984\", \"George Orwell\"));\n        bookRepository.save(new Book(\"To Kill a Mockingbird\", \"Harper Lee\"));\n        bookRepository.save(new Book(\"The Catcher in the Rye\", \"J.D. Salinger\"));\n        bookRepository.save(new Book(\"The Great Gatsby\", \"F. Scott Fitzgerald\"));\n    }\n}\n<\/pre>\n<h3>2.8 application.properties Configuration<\/h3>\n<p>Below is the minimal configuration required in <code>src\/main\/resources\/application.properties<\/code> for setting up the Spring Boot application with GraphQL and JPA:<\/p>\n<pre class=\"brush:plain; wrap-lines:false;\"># Server configuration\nserver.port=8080\n\n# H2 Database configuration\nspring.datasource.url=jdbc:h2:mem:testdb\nspring.datasource.driverClassName=org.h2.Driver\nspring.datasource.username=sa\nspring.datasource.password=\nspring.h2.console.enabled=true\n\n# Hibernate and JPA configuration\nspring.jpa.database-platform=org.hibernate.dialect.H2Dialect\nspring.jpa.show-sql=true\nspring.jpa.hibernate.ddl-auto=create-drop\n\n# GraphQL configuration\nspring.graphql.schema.locations=classpath:graphql\/\nspring.graphql.graphiql.enabled=true\nspring.graphql.graphiql.path=\/graphiql\n<\/pre>\n<p>You can access the GraphQL Playground at <code>http:\/\/localhost:8080\/graphiql<\/code> after starting the application.<\/p>\n<h3>2.9 Code Run and Output<\/h3>\n<p>Once the application is running, you can test it using GraphQL Playground at <code>http:\/\/localhost:8080\/graphiql<\/code>. Below are examples demonstrating both page-based and cursor-based pagination queries along with sample responses.<\/p>\n<h4>2.9.1 Basic Pagination<\/h4>\n<p>This GraphQL query demonstrates page-based pagination by fetching the first page of book records with a page size of 3. It uses the <code>page<\/code> and <code>size<\/code> arguments to specify which page of data to retrieve and how many records each page should contain.<\/p>\n<pre class=\"brush:plain; wrap-lines:false;\">query {\n  books(page: 0, size: 3) {\n    content {\n      id\n      title\n      author\n    }\n    totalPages\n    totalElements\n    currentPage\n    pageSize\n  }\n}\n<\/pre>\n<p>The response contains a paginated set of books with three entries in the <code>content<\/code> array, representing the first page of results with books titled &#8220;The Great Gatsby,&#8221; &#8220;1984,&#8221; and &#8220;To Kill a Mockingbird,&#8221; each having their respective IDs and authors. The <code>totalElements<\/code> field indicates there are 7 books in total in the dataset, while <code>totalPages<\/code> shows that these are divided into 3 pages based on the page size of 3. The <code>currentPage<\/code> is 0, confirming this is the first page of results, and <code>pageSize<\/code> confirms that each page contains 3 books. This structure helps clients understand both the data returned and the overall dataset size for effective navigation through pages.<\/p>\n<pre class=\"brush:plain; wrap-lines:false;\">{\n  \"data\": {\n    \"books\": {\n      \"content\": [\n        {\n          \"id\": \"1\",\n          \"title\": \"The Great Gatsby\",\n          \"author\": \"F. Scott Fitzgerald\"\n        },\n        {\n          \"id\": \"2\",\n          \"title\": \"1984\",\n          \"author\": \"George Orwell\"\n        },\n        {\n          \"id\": \"3\",\n          \"title\": \"To Kill a Mockingbird\",\n          \"author\": \"Harper Lee\"\n        }\n      ],\n      \"totalPages\": 3,\n      \"totalElements\": 7,\n      \"currentPage\": 0,\n      \"pageSize\": 3\n    }\n  }\n}\n<\/pre>\n<h4>2.9.2 Cursor-Based Pagination (After ID)<\/h4>\n<p>This GraphQL query uses cursor-based pagination by specifying an <code>afterId<\/code> parameter to fetch the next set of books starting after the book with ID 2. The <code>size<\/code> parameter limits the result to 2 books, allowing clients to efficiently load subsequent data slices without relying on page numbers. This approach is ideal for handling dynamic datasets where record positions might change frequently.<\/p>\n<pre class=\"brush:plain; wrap-lines:false;\">query {\n  books(afterId: 2, size: 2) {\n    content {\n      id\n      title\n      author\n    }\n    totalPages\n    totalElements\n    currentPage\n    pageSize\n  }\n}\n<\/pre>\n<p>The response returns a list of 2 books in the <code>content<\/code> array\u2014&#8221;To Kill a Mockingbird&#8221; with ID 3 and &#8220;The Catcher in the Rye&#8221; with ID 4\u2014representing the records after the specified cursor. The metadata shows <code>totalElements<\/code> as 2 (the number of books returned), <code>totalPages<\/code> as 1 since this is a single slice of data, <code>currentPage<\/code> as 0 indicating the first result batch, and <code>pageSize<\/code> as 2 matching the requested size. This structure allows clients to progressively fetch data in a performant and consistent manner.<\/p>\n<pre class=\"brush:plain; wrap-lines:false;\">{\n  \"data\": {\n    \"books\": {\n      \"content\": [\n        {\n          \"id\": \"3\",\n          \"title\": \"To Kill a Mockingbird\",\n          \"author\": \"Harper Lee\"\n        },\n        {\n          \"id\": \"4\",\n          \"title\": \"The Catcher in the Rye\",\n          \"author\": \"J.D. Salinger\"\n        }\n      ],\n      \"totalPages\": 1,\n      \"totalElements\": 2,\n      \"currentPage\": 0,\n      \"pageSize\": 2\n    }\n  }\n}\n<\/pre>\n<h2><a name=\"section-3\"><\/a>3. Conclusion<\/h2>\n<p>Pagination is crucial for performance and scalability in GraphQL APIs. Spring Boot makes it seamless to implement both page-based and cursor-based pagination strategies. With just a few classes and a well-defined schema, you can support efficient querying of large datasets.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>GraphQL APIs can return large datasets, and without pagination, performance issues may arise. Spring Boot provides excellent support for GraphQL through the spring-boot-starter-graphql dependency. Let us delve into understanding spring boot graphql pagination and how it enhances data fetching efficiency in modern applications. 1. What is GraphQL? GraphQL is an open-source query language for your &hellip;<\/p>\n","protected":false},"author":26931,"featured_media":117826,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[8],"tags":[1458,4133,1185,2794,4353,1114,854,3811,4132],"class_list":["post-136104","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-enterprise-java","tag-graphql","tag-graphql-schema","tag-h2","tag-h2-database","tag-pagination","tag-spring-zh-hans","tag-spring-boot","tag-spring-boot-graphql","tag-spring-graphql"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.5 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Paginating Data in Spring Boot GraphQL - Java Code Geeks<\/title>\n<meta name=\"description\" content=\"Spring boot graphql pagination: Implement efficient Spring Boot GraphQL pagination using page-based and cursor-based strategies.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.javacodegeeks.com\/paginating-data-in-spring-boot-graphql.html\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Paginating Data in Spring Boot GraphQL - Java Code Geeks\" \/>\n<meta property=\"og:description\" content=\"Spring boot graphql pagination: Implement efficient Spring Boot GraphQL pagination using page-based and cursor-based strategies.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.javacodegeeks.com\/paginating-data-in-spring-boot-graphql.html\" \/>\n<meta property=\"og:site_name\" content=\"Java Code Geeks\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/javacodegeeks\" \/>\n<meta property=\"article:published_time\" content=\"2025-08-13T06:21:49+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2025-08-13T06:21:51+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2023\/06\/graphql-logo.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"150\" \/>\n\t<meta property=\"og:image:height\" content=\"150\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"Yatin Batra\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@javacodegeeks\" \/>\n<meta name=\"twitter:site\" content=\"@javacodegeeks\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Yatin Batra\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"6 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/paginating-data-in-spring-boot-graphql.html#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/paginating-data-in-spring-boot-graphql.html\"},\"author\":{\"name\":\"Yatin Batra\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#\\\/schema\\\/person\\\/cda31a4c1965373fed40c8907dc09b8d\"},\"headline\":\"Paginating Data in Spring Boot GraphQL\",\"datePublished\":\"2025-08-13T06:21:49+00:00\",\"dateModified\":\"2025-08-13T06:21:51+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/paginating-data-in-spring-boot-graphql.html\"},\"wordCount\":1152,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#organization\"},\"image\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/paginating-data-in-spring-boot-graphql.html#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2023\\\/06\\\/graphql-logo.jpg\",\"keywords\":[\"GraphQL\",\"graphql-schema\",\"H2\",\"H2 Database\",\"pagination\",\"Spring\",\"Spring Boot\",\"Spring Boot GraphQL\",\"spring-graphql\"],\"articleSection\":[\"Enterprise Java\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/www.javacodegeeks.com\\\/paginating-data-in-spring-boot-graphql.html#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/paginating-data-in-spring-boot-graphql.html\",\"url\":\"https:\\\/\\\/www.javacodegeeks.com\\\/paginating-data-in-spring-boot-graphql.html\",\"name\":\"Paginating Data in Spring Boot GraphQL - Java Code Geeks\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/paginating-data-in-spring-boot-graphql.html#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/paginating-data-in-spring-boot-graphql.html#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2023\\\/06\\\/graphql-logo.jpg\",\"datePublished\":\"2025-08-13T06:21:49+00:00\",\"dateModified\":\"2025-08-13T06:21:51+00:00\",\"description\":\"Spring boot graphql pagination: Implement efficient Spring Boot GraphQL pagination using page-based and cursor-based strategies.\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/paginating-data-in-spring-boot-graphql.html#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/www.javacodegeeks.com\\\/paginating-data-in-spring-boot-graphql.html\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/paginating-data-in-spring-boot-graphql.html#primaryimage\",\"url\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2023\\\/06\\\/graphql-logo.jpg\",\"contentUrl\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2023\\\/06\\\/graphql-logo.jpg\",\"width\":150,\"height\":150},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/paginating-data-in-spring-boot-graphql.html#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/www.javacodegeeks.com\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Java\",\"item\":\"https:\\\/\\\/www.javacodegeeks.com\\\/category\\\/java\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"Enterprise Java\",\"item\":\"https:\\\/\\\/www.javacodegeeks.com\\\/category\\\/java\\\/enterprise-java\"},{\"@type\":\"ListItem\",\"position\":4,\"name\":\"Paginating Data in Spring Boot GraphQL\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#website\",\"url\":\"https:\\\/\\\/www.javacodegeeks.com\\\/\",\"name\":\"Java Code Geeks\",\"description\":\"Java Developers Resource Center\",\"publisher\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#organization\"},\"alternateName\":\"JCG\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/www.javacodegeeks.com\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#organization\",\"name\":\"Exelixis Media P.C.\",\"url\":\"https:\\\/\\\/www.javacodegeeks.com\\\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#\\\/schema\\\/logo\\\/image\\\/\",\"url\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2022\\\/06\\\/exelixis-logo.png\",\"contentUrl\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2022\\\/06\\\/exelixis-logo.png\",\"width\":864,\"height\":246,\"caption\":\"Exelixis Media P.C.\"},\"image\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#\\\/schema\\\/logo\\\/image\\\/\"},\"sameAs\":[\"https:\\\/\\\/www.facebook.com\\\/javacodegeeks\",\"https:\\\/\\\/x.com\\\/javacodegeeks\"]},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#\\\/schema\\\/person\\\/cda31a4c1965373fed40c8907dc09b8d\",\"name\":\"Yatin Batra\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2022\\\/12\\\/Yatin.batra_.jpg\",\"url\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2022\\\/12\\\/Yatin.batra_.jpg\",\"contentUrl\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2022\\\/12\\\/Yatin.batra_.jpg\",\"caption\":\"Yatin Batra\"},\"description\":\"An experience full-stack engineer well versed with Core Java, Spring\\\/Springboot, MVC, Security, AOP, Frontend (Angular &amp; React), and cloud technologies (such as AWS, GCP, Jenkins, Docker, K8).\",\"sameAs\":[\"https:\\\/\\\/www.javacodegeeks.com\"],\"url\":\"https:\\\/\\\/www.javacodegeeks.com\\\/author\\\/yatin-batra\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Paginating Data in Spring Boot GraphQL - Java Code Geeks","description":"Spring boot graphql pagination: Implement efficient Spring Boot GraphQL pagination using page-based and cursor-based strategies.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.javacodegeeks.com\/paginating-data-in-spring-boot-graphql.html","og_locale":"en_US","og_type":"article","og_title":"Paginating Data in Spring Boot GraphQL - Java Code Geeks","og_description":"Spring boot graphql pagination: Implement efficient Spring Boot GraphQL pagination using page-based and cursor-based strategies.","og_url":"https:\/\/www.javacodegeeks.com\/paginating-data-in-spring-boot-graphql.html","og_site_name":"Java Code Geeks","article_publisher":"https:\/\/www.facebook.com\/javacodegeeks","article_published_time":"2025-08-13T06:21:49+00:00","article_modified_time":"2025-08-13T06:21:51+00:00","og_image":[{"width":150,"height":150,"url":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2023\/06\/graphql-logo.jpg","type":"image\/jpeg"}],"author":"Yatin Batra","twitter_card":"summary_large_image","twitter_creator":"@javacodegeeks","twitter_site":"@javacodegeeks","twitter_misc":{"Written by":"Yatin Batra","Est. reading time":"6 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.javacodegeeks.com\/paginating-data-in-spring-boot-graphql.html#article","isPartOf":{"@id":"https:\/\/www.javacodegeeks.com\/paginating-data-in-spring-boot-graphql.html"},"author":{"name":"Yatin Batra","@id":"https:\/\/www.javacodegeeks.com\/#\/schema\/person\/cda31a4c1965373fed40c8907dc09b8d"},"headline":"Paginating Data in Spring Boot GraphQL","datePublished":"2025-08-13T06:21:49+00:00","dateModified":"2025-08-13T06:21:51+00:00","mainEntityOfPage":{"@id":"https:\/\/www.javacodegeeks.com\/paginating-data-in-spring-boot-graphql.html"},"wordCount":1152,"commentCount":0,"publisher":{"@id":"https:\/\/www.javacodegeeks.com\/#organization"},"image":{"@id":"https:\/\/www.javacodegeeks.com\/paginating-data-in-spring-boot-graphql.html#primaryimage"},"thumbnailUrl":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2023\/06\/graphql-logo.jpg","keywords":["GraphQL","graphql-schema","H2","H2 Database","pagination","Spring","Spring Boot","Spring Boot GraphQL","spring-graphql"],"articleSection":["Enterprise Java"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.javacodegeeks.com\/paginating-data-in-spring-boot-graphql.html#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.javacodegeeks.com\/paginating-data-in-spring-boot-graphql.html","url":"https:\/\/www.javacodegeeks.com\/paginating-data-in-spring-boot-graphql.html","name":"Paginating Data in Spring Boot GraphQL - Java Code Geeks","isPartOf":{"@id":"https:\/\/www.javacodegeeks.com\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.javacodegeeks.com\/paginating-data-in-spring-boot-graphql.html#primaryimage"},"image":{"@id":"https:\/\/www.javacodegeeks.com\/paginating-data-in-spring-boot-graphql.html#primaryimage"},"thumbnailUrl":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2023\/06\/graphql-logo.jpg","datePublished":"2025-08-13T06:21:49+00:00","dateModified":"2025-08-13T06:21:51+00:00","description":"Spring boot graphql pagination: Implement efficient Spring Boot GraphQL pagination using page-based and cursor-based strategies.","breadcrumb":{"@id":"https:\/\/www.javacodegeeks.com\/paginating-data-in-spring-boot-graphql.html#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.javacodegeeks.com\/paginating-data-in-spring-boot-graphql.html"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.javacodegeeks.com\/paginating-data-in-spring-boot-graphql.html#primaryimage","url":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2023\/06\/graphql-logo.jpg","contentUrl":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2023\/06\/graphql-logo.jpg","width":150,"height":150},{"@type":"BreadcrumbList","@id":"https:\/\/www.javacodegeeks.com\/paginating-data-in-spring-boot-graphql.html#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.javacodegeeks.com\/"},{"@type":"ListItem","position":2,"name":"Java","item":"https:\/\/www.javacodegeeks.com\/category\/java"},{"@type":"ListItem","position":3,"name":"Enterprise Java","item":"https:\/\/www.javacodegeeks.com\/category\/java\/enterprise-java"},{"@type":"ListItem","position":4,"name":"Paginating Data in Spring Boot GraphQL"}]},{"@type":"WebSite","@id":"https:\/\/www.javacodegeeks.com\/#website","url":"https:\/\/www.javacodegeeks.com\/","name":"Java Code Geeks","description":"Java Developers Resource Center","publisher":{"@id":"https:\/\/www.javacodegeeks.com\/#organization"},"alternateName":"JCG","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.javacodegeeks.com\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/www.javacodegeeks.com\/#organization","name":"Exelixis Media P.C.","url":"https:\/\/www.javacodegeeks.com\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.javacodegeeks.com\/#\/schema\/logo\/image\/","url":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png","contentUrl":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png","width":864,"height":246,"caption":"Exelixis Media P.C."},"image":{"@id":"https:\/\/www.javacodegeeks.com\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/javacodegeeks","https:\/\/x.com\/javacodegeeks"]},{"@type":"Person","@id":"https:\/\/www.javacodegeeks.com\/#\/schema\/person\/cda31a4c1965373fed40c8907dc09b8d","name":"Yatin Batra","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2022\/12\/Yatin.batra_.jpg","url":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2022\/12\/Yatin.batra_.jpg","contentUrl":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2022\/12\/Yatin.batra_.jpg","caption":"Yatin Batra"},"description":"An experience full-stack engineer well versed with Core Java, Spring\/Springboot, MVC, Security, AOP, Frontend (Angular &amp; React), and cloud technologies (such as AWS, GCP, Jenkins, Docker, K8).","sameAs":["https:\/\/www.javacodegeeks.com"],"url":"https:\/\/www.javacodegeeks.com\/author\/yatin-batra"}]}},"_links":{"self":[{"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/posts\/136104","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/users\/26931"}],"replies":[{"embeddable":true,"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/comments?post=136104"}],"version-history":[{"count":0,"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/posts\/136104\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/media\/117826"}],"wp:attachment":[{"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/media?parent=136104"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/categories?post=136104"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/tags?post=136104"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}