webtize/shopify-graphql-sdk
Composer 安装命令:
composer require webtize/shopify-graphql-sdk
包简介
Modern PHP SDK for Shopify GraphQL Admin API
关键字:
README 文档
README
A modern, PSR-compliant PHP SDK for interacting with Shopify's GraphQL Admin API. This SDK provides a clean, object-oriented interface with automatic HTTP client discovery, rate limiting, error handling, and convenient resource helpers.
Features
- 🚀 Modern PHP 8.1+ with strict typing and best practices
- 🔌 PSR-18/17 Compliant - Works with any HTTP client (Guzzle, Symfony, etc.)
- 🛡️ Automatic Rate Limiting with exponential backoff and retry logic
- 🎯 Type-Safe GraphQL operations with query builder
- 📦 Resource Helpers for common operations (Products, Orders, etc.)
- ⚡ Auto-Discovery of HTTP clients and factories
- 🔍 Comprehensive Error Handling with specific exceptions
- 📖 Extensive Documentation and examples
Installation
Install via Composer:
composer require webtize/shopify-graphql-sdk:@dev
For HTTP client support, also install one of the following:
# For Guzzle (recommended) composer require php-http/guzzle7-adapter # For Symfony HTTP Client composer require symfony/http-client php-http/httplug-bundle # For cURL adapter composer require php-http/curl-client php-http/message
Quick Start
Basic Setup
use ShopifyGraphQL\ClientFactory; // Simple setup with auto-discovery $client = ClientFactory::create( 'your-store.myshopify.com', // or just 'your-store' 'your-access-token-here' ); // Get shop information $response = $client->getShopInfo(); if ($response->isSuccessful()) { $shop = $response->get('shop'); echo "Shop: " . $shop['name']; }
Using Resource Helpers
use ShopifyGraphQL\Products; $products = new Products($client); // List products $response = $products->list(10); foreach ($response->get('products.edges', []) as $edge) { echo $edge['node']['title'] . "\n"; } // Get single product $product = $products->get('gid://shopify/Product/123'); echo $product->get('product.title'); // Create product $newProduct = $products->create([ 'title' => 'New Product', 'productType' => 'Electronics', 'vendor' => 'ACME Corp' ]);
Custom Queries with Query Builder
use ShopifyGraphQL\QueryBuilder; $query = QueryBuilder::query('GetCustomers') ->variable('first', 'Int!', 10) ->field('customers', function($builder) { $builder->field('edges', function($edge) { $edge->field('node', [ 'id', 'email', 'firstName', 'lastName' ]); }); }); $response = $client->query($query->build(), ['first' => 5]);
Configuration Options
$client = ClientFactory::create( 'your-store.myshopify.com', 'your-access-token', [ 'timeout' => 30, // Request timeout in seconds 'max_retries' => 3, // Max retry attempts for rate limits 'headers' => [ // Additional headers 'X-Custom-Header' => 'value' ] ] );
Advanced Usage
Custom HTTP Client
use GuzzleHttp\Client as GuzzleClient;use Http\Adapter\Guzzle7\Client as GuzzleAdapter;use Nyholm\Psr7\Factory\Psr17Factory;use ShopifyGraphQL\ClientFactory; $httpClient = new GuzzleAdapter(new GuzzleClient([ 'timeout' => 60, 'verify' => true ])); $factory = new Psr17Factory(); $client = ClientFactory::createWithHttpClient( $httpClient, $factory, // Request factory $factory, // Stream factory 'your-store.myshopify.com', 'your-access-token' );
Error Handling
use ShopifyGraphQL\AuthenticationException;use ShopifyGraphQL\RateLimitException;use ShopifyGraphQL\ShopifyGraphQLException; try { $response = $client->query($query); } catch (AuthenticationException $e) { echo "Invalid credentials: " . $e->getMessage(); } catch (RateLimitException $e) { echo "Rate limited. Retry after: " . $e->getRetryAfter() . " seconds"; } catch (ShopifyGraphQLException $e) { echo "GraphQL Error: " . $e->getMessage(); if ($e->hasGraphqlErrors()) { foreach ($e->getGraphqlErrors() as $error) { echo "- " . $error['message'] . "\n"; } } }
Pagination
$products = new Products($client); $allProducts = []; $cursor = null; do { $response = $products->list(50, $cursor); if (!$response->isSuccessful()) { break; } $data = $response->get('products'); $edges = $data['edges'] ?? []; foreach ($edges as $edge) { $allProducts[] = $edge['node']; $cursor = $edge['cursor']; } $hasNextPage = $data['pageInfo']['hasNextPage'] ?? false; } while ($hasNextPage);
Available Resources
Currently implemented resource helpers:
Products- Product management operations
More resources coming soon:
- Orders
- Customers
- Collections
- Inventory
- Fulfillments
GraphQL Query Builder
The included query builder provides a fluent interface for constructing GraphQL queries:
$query = QueryBuilder::query('GetProductsAndVariants') ->variable('productId', 'ID!') ->variable('first', 'Int', 10) ->field('product', function($builder) { $builder->field('id') ->field('title') ->field('variants', function($variantBuilder) { $variantBuilder->field('edges', [ 'node' => ['id', 'title', 'price'] ]); }); }) ->build();
Rate Limiting
The SDK automatically handles Shopify's rate limiting:
- Detects 429 (rate limit) responses
- Implements exponential backoff retry strategy
- Respects
Retry-Afterheaders - Configurable max retry attempts
Testing
Run the test suite:
composer test
Run static analysis:
composer phpstan
Fix code style:
composer cs-fix
Requirements
- PHP 8.1 or higher
- A PSR-18 HTTP client implementation
- Valid Shopify store and access token
Contributing
- Fork the repository
- Create your feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add some amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
License
This project is licensed under the MIT License - see the LICENSE file for details.
Support
Changelog
v1.0.0
- Initial release
- Core GraphQL client with PSR-18 support
- Query builder with fluent interface
- Products resource helper
- Automatic rate limiting and retries
- Comprehensive error handling
shopify-graphql-php-sdk
webtize/shopify-graphql-sdk 适用场景与选型建议
webtize/shopify-graphql-sdk 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 95 次下载、GitHub Stars 达 1, 最近一次更新时间为 2025 年 08 月 15 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「api」 「sdk」 「shopify」 「e-commerce」 「graphql」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 webtize/shopify-graphql-sdk 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 webtize/shopify-graphql-sdk 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 webtize/shopify-graphql-sdk 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
A PSR-7 compatible library for making CRUD API endpoints
Shopify package for Laravel to aide in app development
A basic Shopify API wrapper with REST and GraphQL support.
A set of APIs to retrieve data from Shopify
PHP SDK for Shopify API
A simple API wrapper for Shopify using Guzzle for REST
统计信息
- 总下载量: 95
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 1
- 点击次数: 12
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2025-08-15