PHP code example of luminarix / laravel-shopify-graphql
1. Go to this page and download the library: Download luminarix/laravel-shopify-graphql 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/ */
luminarix / laravel-shopify-graphql example snippets
use Luminarix\Shopify\GraphQLClient\Facades\GraphQLClient;
use Luminarix\Shopify\GraphQLClient\Authenticators\ShopifyApp;
$authenticator = new ShopifyApp($shopDomain, $accessToken);
$client = GraphQLClient::factory()->create($authenticator);
// Query
$response = $client->query('
query {
shop {
name
email
}
}
');
$data = $response->toArray();
// Mutation
$response = $client->mutate('
mutation orderMarkAsPaid($input: OrderMarkAsPaidInput!) {
orderMarkAsPaid(input: $input) {
order {
id
}
userErrors {
field
message
}
}
}
', [
'input' => [
'id' => 'gid://shopify/Order/123456789',
],
]);
namespace App\Services;
use App\Models\ShopifyShop;
use Luminarix\Shopify\GraphQLClient\Facades\GraphQLClient;
use Luminarix\Shopify\GraphQLClient\Authenticators\ShopifyApp;
use Luminarix\Shopify\GraphQLClient\GraphQLClientMethods;
class ShopifyGraphQLService
{
public function with(ShopifyShop $shop): GraphQLClientMethods
{
$authenticator = new ShopifyApp($shop->domain, $shop->access_token);
return GraphQLClient::factory()->create($authenticator);
}
}
namespace App\Traits;
use App\Services\ShopifyGraphQLService;
use Luminarix\Shopify\GraphQLClient\GraphQLClientMethods;
trait InteractsWithShopifyGraphQL
{
public function graphql(): GraphQLClientMethods
{
return app(ShopifyGraphQLService::class)->with($this);
}
}
namespace App\Models;
use App\Traits\InteractsWithShopifyGraphQL;
use Illuminate\Database\Eloquent\Model;
class ShopifyShop extends Model
{
use InteractsWithShopifyGraphQL;
}
// Start a bulk operation
$result = $client->createBulkOperation('
{
products {
edges {
node {
id
title
}
}
}
}
');
// Check current bulk operation status
$status = $client->getCurrentBulkOperation();
// Get a specific bulk operation by ID
$operation = $client->getBulkOperation($numericId);
// Cancel running bulk operation
$client->cancelBulkOperation();
use Luminarix\Shopify\GraphQLClient\Contracts\RateLimitable;
class CustomRateLimitService implements RateLimitable
{
public function getRateLimitInfo(): array { /* ... */ }
public function updateRateLimitInfo(array $data): void { /* ... */ }
public function calculateWaitTime(float $requestedQueryCost): float { /* ... */ }
public function waitIfNecessary(float $requestedQueryCost): void { /* ... */ }
}
$client = GraphQLClient::factory()->create($authenticator, new CustomRateLimitService());
// config/shopify-graphql.php
return [
// Shopify API version (format: YYYY-MM)
'api_version' => env('SHOPIFY_API_VERSION', '2025-01'),
// Fail immediately when throttled (vs. waiting and retrying)
'fail_on_throttled' => env('SHOPIFY_FAIL_ON_THROTTLED', true),
// Max retry attempts when throttled
'throttle_max_tries' => env('SHOPIFY_THROTTLE_MAX_TRIES', 5),
];