Skip to content

Commit d91e9bd

Browse files
committed
Update shopify to include pagination
Signed-off-by: brookewp <[email protected]>
1 parent 07d3b6a commit d91e9bd

File tree

3 files changed

+41
-3
lines changed

3 files changed

+41
-3
lines changed

inc/Integrations/Shopify/Queries/SearchProducts.graphql

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,16 @@
1-
query SearchProducts($search: String) {
2-
products(first: 10, query: $search, sortKey: BEST_SELLING) {
1+
query SearchProducts($search: String!, $limit: Int!, $cursor_next: String) {
2+
products(
3+
first: $limit
4+
after: $cursor_next
5+
query: $search
6+
sortKey: BEST_SELLING
7+
) {
8+
pageInfo {
9+
hasNextPage
10+
hasPreviousPage
11+
startCursor
12+
endCursor
13+
}
314
edges {
415
node {
516
id

inc/Integrations/Shopify/ShopifyIntegration.php

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,19 @@ public static function get_queries( ShopifyDataSource $data_source ): array {
8686
'search' => [
8787
'type' => 'ui:search_input',
8888
],
89+
'limit' => [
90+
'default_value' => 8,
91+
'name' => 'Items per page',
92+
'type' => 'ui:pagination_per_page',
93+
],
94+
'cursor_next' => [
95+
'name' => 'Next page cursor',
96+
'type' => 'ui:pagination_cursor_next',
97+
],
98+
'cursor_previous' => [
99+
'name' => 'Previous page cursor',
100+
'type' => 'ui:pagination_cursor_previous',
101+
],
89102
],
90103
'output_schema' => [
91104
'path' => '$.data.products.edges[*]',
@@ -113,6 +126,18 @@ public static function get_queries( ShopifyDataSource $data_source ): array {
113126
],
114127
],
115128
],
129+
'pagination_schema' => [
130+
'cursor_next' => [
131+
'name' => 'Next page cursor',
132+
'path' => '$.data.products.pageInfo.endCursor',
133+
'type' => 'string',
134+
],
135+
'cursor_previous' => [
136+
'name' => 'Previous page cursor',
137+
'path' => '$.data.products.pageInfo.startCursor',
138+
'type' => 'string',
139+
],
140+
],
116141
'graphql_query' => file_get_contents( __DIR__ . '/Queries/SearchProducts.graphql' ),
117142
] ),
118143
];

inc/Validation/ConfigSchemas.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -291,11 +291,13 @@ private static function generate_http_query_config_schema(): array {
291291
// items available in paginated results. This field must be defined
292292
// in order present to enable pagination support of any type,
293293
// including cursor-based pagination.
294-
'total_items' => Types::object( [
294+
'total_items' => Types::nullable(
295+
Types::object( [
295296
'name' => Types::nullable( Types::string() ),
296297
'path' => Types::json_path(),
297298
'type' => Types::enum( 'integer' ),
298299
] ),
300+
),
299301
// This field provides a pagination cursor for the next page of
300302
// paginated results, or a null value if there is no next page. This
301303
// field must be defined in order to enable cursor-based pagination.

0 commit comments

Comments
 (0)