Skip to content

Commit 651ee47

Browse files
author
Daniël van der Linden
committed
Improve pagination exception & add total pages to page_info
1 parent b55989d commit 651ee47

File tree

2 files changed

+6
-4
lines changed

2 files changed

+6
-4
lines changed

app/code/Magento/CatalogGraphQl/Model/Resolver/Products.php

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -110,10 +110,10 @@ public function resolve(
110110

111111
$currentPage = $searchCriteria->getCurrentPage();
112112
if ($searchCriteria->getCurrentPage() > $maxPages && $searchResult->getTotalCount() > 0) {
113-
$currentPage = new GraphQlInputException(
113+
throw new GraphQlInputException(
114114
__(
115-
'currentPage value %1 specified is greater than the number of pages available.',
116-
[$maxPages]
115+
'currentPage value %1 specified is greater than the %2 page(s) available.',
116+
[$currentPage, $maxPages]
117117
)
118118
);
119119
}
@@ -123,7 +123,8 @@ public function resolve(
123123
'items' => $searchResult->getProductsSearchResult(),
124124
'page_info' => [
125125
'page_size' => $searchCriteria->getPageSize(),
126-
'current_page' => $currentPage
126+
'current_page' => $currentPage,
127+
'total_pages' => $maxPages
127128
],
128129
'filters' => $this->filtersDataProvider->getData($layerType)
129130
];

app/code/Magento/GraphQl/etc/schema.graphqls

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ input FilterTypeInput @doc(description: "FilterTypeInput specifies which action
2929
type SearchResultPageInfo @doc(description: "SearchResultPageInfo provides navigation for the query response") {
3030
page_size: Int @doc(description: "Specifies the maximum number of items to return")
3131
current_page: Int @doc(description: "Specifies which page of results to return")
32+
total_pages: Int @doc(description: "Total amount of pages")
3233
}
3334

3435
enum SortEnum @doc(description: "This enumeration indicates whether to return results in ascending or descending order") {

0 commit comments

Comments
 (0)