phpclassic / php-shopify

PHP SDK for Shopify API
Apache License 2.0
568 stars 211 forks source link

GraphQL pagination not working? #324

Closed KoenLetsigo closed 2 months ago

KoenLetsigo commented 2 months ago

Hi, I am working on a GraphQL query which requires pagination. Here is (part of) my code to achieve it:

`$shopify = new PHPShopify\ShopifySDK($config); $numProduct = 250; $cursor = "eyJsYXN0X2lkIjo4Nzg5OTg2MDUwMzc5LCJsYXN0X3ZhbHVlIjoiODc4OTk4NjA1MDM3OSJ9"; $Cursor = settype($cursor, "string"); $nextPage = 1;

$graphQL = <<<QUERY query { products(first: $numProduct, after: $Cursor) {`

When running the script, I receive an error saying that the type is wrong. PHP Fatal error: Uncaught PHPShopify\Exception\ApiException: message - Argument 'after' on Field 'products' has an invalid value (1). Expected type 'String'., locations - line - 3, column - 5, path - query, products, after, extensions - code - argumentLiteralsIncompatible, typeName - Field, argumentName - after

Despite the fact that I already typecasted the value to a string, I still get the error... Before I did the typecasting, I received an error saying 'unexpected RPAREN (")") ' for the location after $Cursor.

Can anybody help? Thanks in advance!

KoenLetsigo commented 2 months ago

Solved. Had to remove the typecasting and, in the query, enclose $Cursor between brackets.