Skip to content

Commit

Permalink
Update shopify to include pagination
Browse files Browse the repository at this point in the history
Signed-off-by: brookewp <[email protected]>
  • Loading branch information
brookewp committed Feb 25, 2025
1 parent 07d3b6a commit d91e9bd
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 3 deletions.
15 changes: 13 additions & 2 deletions inc/Integrations/Shopify/Queries/SearchProducts.graphql
Original file line number Diff line number Diff line change
@@ -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
Expand Down
25 changes: 25 additions & 0 deletions inc/Integrations/Shopify/ShopifyIntegration.php
Original file line number Diff line number Diff line change
Expand Up @@ -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[*]',
Expand Down Expand Up @@ -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' ),
] ),
];
Expand Down
4 changes: 3 additions & 1 deletion inc/Validation/ConfigSchemas.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit d91e9bd

Please sign in to comment.