PHP code example of fo3nix / shopify-graphql-php-app
1. Go to this page and download the library: Download fo3nix/shopify-graphql-php-app library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
fo3nix / shopify-graphql-php-app example snippets
// Assuming your client and generated classes are autoloaded.
// The namespace will correspond to the API version.
use YourVendor\ShopifyAdmin202507\RootQueryObject;
use YourVendor\ShopifyAdmin202507\RootCustomersArgumentsObject;
use YourVendor\ShopifyAdmin202507\CustomerOrdersArgumentsObject;
// 1. Initialize your GraphQL client
$client = new \GraphQL\Client(
'https://{your-shop-name}[.myshopify.com/admin/api/2025-07/graphql.json](https://.myshopify.com/admin/api/2025-07/graphql.json)',
['X-Shopify-Access-Token' => '{your-admin-api-token}']
);
// 2. Build the query using the RootQueryObject
$queryRoot = new RootQueryObject();
$queryRoot->selectCustomers(
(new RootCustomersArgumentsObject())->setFirst(5)
)
->selectEdges()
->selectNode()
->selectId()
->selectFirstName()
->selectLastName()
->selectEmail()
->selectOrders((new CustomerOrdersArgumentsObject())->setFirst(3))
->selectEdges()
->selectNode()
->selectId()
->selectName()
->selectTotalPriceSet()
->selectShopMoney()
->selectAmount()
->selectCurrencyCode();
// 3. Run the query
// The second argument 'true' tells the client to return an associative array.
$results = $client->runQuery($queryRoot->getQuery(), true);
// The raw data is now ready to be mapped to result objects.
$customersData = $results->getData()['customers']['edges'];
// Use your generated result classes
use YourVendor\ShopifyAdmin202507\Customer;
// $customersData is the result from the query execution example above.
// 1. Hydrate the raw array into an array of Customer objects
$customers = array_map(function ($customerEdge) {
// The fromArray() method handles all nested objects recursively
return Customer::fromArray($customerEdge['node']);
}, $customersData);
// 2. Use the type-hinted objects with full IDE autocompletion
echo "Customer List:\n";
foreach ($customers as $customer) {
/** @var Customer $customer */
echo "====================\n";
echo "Customer ID: " . $customer->getId() . "\n";
echo "Name: " . $customer->getFirstName() . " " . $customer->getLastName() . "\n";
echo "Email: " . $customer->getEmail() . "\n";
echo "Recent Orders:\n";
if ($customer->getOrders() && $customer->getOrders()->getEdges()) {
foreach ($customer->getOrders()->getEdges() as $orderEdge) {
$order = $orderEdge->getNode(); // This is now a strongly-typed Order object
echo " - Order #" . $order->getName() . "\n";
echo " Total: " . $order->getTotalPriceSet()->getShopMoney()->getAmount() . " " . $order->getTotalPriceSet()->getShopMoney()->getCurrencyCode() . "\n";
}
} else {
echo " No orders found.\n";
}
}
// You can also convert objects back to an array if needed
// $customerArray = $customers[0]->asArray();
// print_r($customerArray);
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.