chengwl 5 дней назад
Родитель
Сommit
8b933ea38e

+ 3 - 5
packages/Webkul/BagistoApi/src/Models/CountryState.php

@@ -24,6 +24,7 @@ use Webkul\Core\Models\CountryState as BaseCountryState;
 // Subresource nested collection: /countries/{country_id}/states
 #[ApiResource(
     routePrefix: '/api/shop',
+    paginationEnabled: false,
     uriTemplate: '/countries/{country_id}/states',
     uriVariables: [
         'country_id' => new Link(
@@ -58,6 +59,7 @@ use Webkul\Core\Models\CountryState as BaseCountryState;
 #[ApiResource(
     routePrefix: '/api/shop',
     shortName: 'CountryState',
+    paginationEnabled: false,
     uriTemplate: '/country-states',
     operations: [
         new GetCollection,
@@ -65,16 +67,12 @@ use Webkul\Core\Models\CountryState as BaseCountryState;
     graphQlOperations: [
         new QueryCollection(
             provider: CountryStateCollectionProvider::class,
-            paginationType: 'cursor',
+            paginationEnabled: false,
             args: [
                 'countryId' => [
                     'type'        => 'Int!',
                     'description' => 'Filter states by country ID (required)',
                 ],
-                'first'  => ['type' => 'Int', 'description' => 'Limit results (forward pagination)'],
-                'last'   => ['type' => 'Int', 'description' => 'Limit results (backward pagination)'],
-                'after'  => ['type' => 'String', 'description' => 'Cursor for forward pagination'],
-                'before' => ['type' => 'String', 'description' => 'Cursor for backward pagination'],
             ]
         ),
     ]

+ 10 - 16
packages/Webkul/BagistoApi/src/State/CountryStateCollectionProvider.php

@@ -13,7 +13,7 @@ use Webkul\BagistoApi\Models\CountryState;
 /**
  * Collection provider for CountryState
  *
- * Provides cursor-based pagination for country states
+ * Returns all states for a country by default (pagination disabled).
  * - Subresource: /countries/{country_id}/states (country_id provided via URI)
  * - Direct query: countryStates(countryId: 244) (countryId REQUIRED in args for GraphQL and REST)
  */
@@ -42,22 +42,20 @@ class CountryStateCollectionProvider implements ProviderInterface
             );
         }
 
+        $query = CountryState::where('country_id', $countryId)
+            ->with('translations')
+            ->orderBy('id', 'asc');
+
+        if ($this->pagination->isEnabled($operation, $context) === false) {
+            return $query->get();
+        }
+
         $first = isset($args['first']) ? (int) $args['first'] : null;
         $last = isset($args['last']) ? (int) $args['last'] : null;
         $after = $args['after'] ?? null;
         $before = $args['before'] ?? null;
 
-        $defaultPerPage = 10;
-
-        // Determine page size
-        if ($first !== null) {
-            $perPage = $first;
-        } elseif ($last !== null) {
-            $perPage = $last;
-        } else {
-            $perPage = $defaultPerPage;
-        }
-
+        $perPage = $first ?? $last ?? 10;
         $offset = 0;
 
         if ($after) {
@@ -71,10 +69,6 @@ class CountryStateCollectionProvider implements ProviderInterface
             $offset = max(0, $cursor - $perPage);
         }
 
-        $query = CountryState::where('country_id', $countryId)
-            ->with('translations')
-            ->orderBy('id', 'asc');
-
         $total = (clone $query)->count();
 
         if ($offset > $total) {