phpclassic / php-shopify

PHP SDK for Shopify API
Apache License 2.0
571 stars 210 forks source link

GraphQL mutation example returns syntax error unexpected COLON(":") #326

Open Vacune opened 5 months ago

Vacune commented 5 months ago

I'm testing GraphQL calls, and the following example from the documentation:

`<?php // Mutation test $graphQL = <<<Query mutation ($input: CustomerInput!) { customerCreate(input: $input) { customer { id displayName } userErrors { field message } } } Query;

$variables = [ "input" => [ "firstName" => "Greg", "lastName" => "Variables", "email" => "gregvariables@teleworm.us" ] ] $shopify->GraphQL->post($graphQL, null, null, $variables); ?>`

it returns the error:

PHP Fatal error: Uncaught PHPShopify\\Exception\\ApiException: message - syntax error, unexpected COLON (":"), expecting VAR_SIGN at [1, 11], locations - line - 1, column - 11 in /var/www/html/test-app/vendor/phpclassic/php-shopify/lib/ShopifyResource.php:540\nStack trace:\n#0 /var/www/html/test-app/vendor/phpclassic/php-shopify/lib/GraphQL.php(49): PHPShopify\\ShopifyResource->processResponse()\n#1 /var/www/html/test-app/installed.php(86): PHPShopify\\GraphQL->post()\n#2 {main}\n thrown in /var/www/html/test-app/vendor/phpclassic/php-shopify/lib/ShopifyResource.php on line 540, referer: https://admin.shopify.com/

Where is the problem?

Thanks for your cooperation

Vacune commented 5 months ago

I have formed the query like this and it works: $graphQL = 'mutation ($input: CustomerInput!) { customerCreate(input: $input) { customer { id displayName } userErrors { field message } } }';