diff --git a/inc/Integrations/Shopify/Queries/SearchProducts.graphql b/inc/Integrations/Shopify/Queries/SearchProducts.graphql index 7666fcd3..4711b3c6 100644 --- a/inc/Integrations/Shopify/Queries/SearchProducts.graphql +++ b/inc/Integrations/Shopify/Queries/SearchProducts.graphql @@ -1,5 +1,16 @@ -query SearchProducts($search: String) { - products(first: 10, query: $search, sortKey: BEST_SELLING) { +query SearchProducts($search: String!, $limit: Int!, $cursor_next: String) { + products( + first: $limit + after: $cursor_next + query: $search + sortKey: BEST_SELLING + ) { + pageInfo { + hasNextPage + hasPreviousPage + startCursor + endCursor + } edges { node { id diff --git a/inc/Integrations/Shopify/ShopifyIntegration.php b/inc/Integrations/Shopify/ShopifyIntegration.php index 52cd75af..fe2b2466 100644 --- a/inc/Integrations/Shopify/ShopifyIntegration.php +++ b/inc/Integrations/Shopify/ShopifyIntegration.php @@ -86,6 +86,19 @@ public static function get_queries( ShopifyDataSource $data_source ): array { 'search' => [ 'type' => 'ui:search_input', ], + 'limit' => [ + 'default_value' => 8, + 'name' => 'Items per page', + 'type' => 'ui:pagination_per_page', + ], + 'cursor_next' => [ + 'name' => 'Next page cursor', + 'type' => 'ui:pagination_cursor_next', + ], + 'cursor_previous' => [ + 'name' => 'Previous page cursor', + 'type' => 'ui:pagination_cursor_previous', + ], ], 'output_schema' => [ 'path' => '$.data.products.edges[*]', @@ -113,6 +126,18 @@ public static function get_queries( ShopifyDataSource $data_source ): array { ], ], ], + 'pagination_schema' => [ + 'cursor_next' => [ + 'name' => 'Next page cursor', + 'path' => '$.data.products.pageInfo.endCursor', + 'type' => 'string', + ], + 'cursor_previous' => [ + 'name' => 'Previous page cursor', + 'path' => '$.data.products.pageInfo.startCursor', + 'type' => 'string', + ], + ], 'graphql_query' => file_get_contents( __DIR__ . '/Queries/SearchProducts.graphql' ), ] ), ]; diff --git a/inc/Validation/ConfigSchemas.php b/inc/Validation/ConfigSchemas.php index 45c5b2a4..3351cb64 100644 --- a/inc/Validation/ConfigSchemas.php +++ b/inc/Validation/ConfigSchemas.php @@ -291,11 +291,13 @@ private static function generate_http_query_config_schema(): array { // items available in paginated results. This field must be defined // in order present to enable pagination support of any type, // including cursor-based pagination. - 'total_items' => Types::object( [ + 'total_items' => Types::nullable( + Types::object( [ 'name' => Types::nullable( Types::string() ), 'path' => Types::json_path(), 'type' => Types::enum( 'integer' ), ] ), + ), // This field provides a pagination cursor for the next page of // paginated results, or a null value if there is no next page. This // field must be defined in order to enable cursor-based pagination.