Ver Fonte

让产品 search 的 currentPage 按驼峰字段输出,避免非空字段返回 null。

Co-authored-by: Cursor <cursoragent@cursor.com>
chengwl há 17 horas atrás
pai
commit
d500563b19

+ 8 - 2
packages/Webkul/BagistoApi/src/Dto/ProductSearch/ProductSearchPageInfoDto.php

@@ -17,11 +17,17 @@ class ProductSearchPageInfoDto
 
     /**
      * Current page number (1-based). Available when using the `page` arg.
+     *
+     * CamelCase on purpose: ProductSearch nested selections are not denormalized,
+     * so this must match the GraphQL field name `currentPage`.
      */
-    public int $current_page = 1;
+    public int $currentPage = 1;
 
     /**
      * Total number of pages. Available when using the `page` arg.
+     *
+     * CamelCase on purpose: ProductSearch nested selections are not denormalized,
+     * so this must match the GraphQL field name `totalPages`.
      */
-    public int $total_pages = 1;
+    public int $totalPages = 1;
 }

+ 2 - 2
packages/Webkul/BagistoApi/src/Resolver/ProductSearchResolver.php

@@ -118,8 +118,8 @@ class ProductSearchResolver implements QueryItemResolverInterface
             : $paginator->getCurrentPage() < $paginator->getLastPage();
         $pageInfo->startCursor = $edges[0]->cursor ?? null;
         $pageInfo->endCursor = $edges[array_key_last($edges)]->cursor ?? null;
-        $pageInfo->current_page = $total > 0 ? (int) floor($offset / $limit) + 1 : 1;
-        $pageInfo->total_pages = $total > 0 ? (int) ceil($total / $limit) : 1;
+        $pageInfo->currentPage = $total > 0 ? (int) floor($offset / $limit) + 1 : 1;
+        $pageInfo->totalPages = $total > 0 ? (int) ceil($total / $limit) : 1;
 
         return $pageInfo;
     }

+ 4 - 4
packages/Webkul/BagistoApi/tests/Unit/Resolver/ProductSearchResolverTest.php

@@ -56,8 +56,8 @@ class ProductSearchResolverTest extends TestCase
         $this->assertSame($third, $result->edges[1]->node);
         $this->assertTrue($result->page_info->hasPreviousPage);
         $this->assertTrue($result->page_info->hasNextPage);
-        $this->assertSame(2, $result->page_info->current_page);
-        $this->assertSame(3, $result->page_info->total_pages);
+        $this->assertSame(2, $result->page_info->currentPage);
+        $this->assertSame(3, $result->page_info->totalPages);
     }
 
     public function test_first_page_does_not_send_an_after_cursor(): void
@@ -84,8 +84,8 @@ class ProductSearchResolverTest extends TestCase
             ],
         ]);
 
-        $this->assertSame(1, $result->page_info->current_page);
-        $this->assertSame(1, $result->page_info->total_pages);
+        $this->assertSame(1, $result->page_info->currentPage);
+        $this->assertSame(1, $result->page_info->totalPages);
         $this->assertFalse($result->page_info->hasPreviousPage);
         $this->assertSame(base64_encode('0'), $result->edges[0]->cursor);
     }