定制 fo3nix/shopify-graphql-php-app 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

fo3nix/shopify-graphql-php-app

Composer 安装命令:

composer require fo3nix/shopify-graphql-php-app

包简介

A PHP Library to interact with the GraphQLAdmin API of Shopify

README 文档

README

This is a strongly-typed PHP client library for interacting with the Shopify GraphQL API. For every GraphQL object, we have generated corresponding query builders and result classes, enabling a fluent, intuitive, and type-safe development experience.

Stop guessing field names and start leveraging your IDE's autocompletion!

Supported Shopify GraphQL APIs

  • Admin API Version: 2025-07

Features

  • Fluent Query Builder: Construct complex GraphQL queries with a simple and readable PHP object interface.
  • Strongly-Typed Result Objects: Automatically map API responses to dedicated PHP classes.
  • IDE Autocompletion: Get full autocompletion for queries and results, reducing errors and speeding up development.
  • Automatic Type Handling: Includes automatic handling of date/time fields with Carbon and recursive handling of nested objects.

Installation

composer require fo3nix/php-shopify-graphql-client

Usage

Example: Query Builder and Execution

The following example demonstrates how to build a query to fetch the first 5 customers and their last 3 orders, then execute it.

<?php

// 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'];

Example: Mapping Results to Objects

This example takes the raw array from the previous step and hydrates it into strongly-typed Customer and Order objects.

<?php

// 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);

fo3nix/shopify-graphql-php-app 适用场景与选型建议

fo3nix/shopify-graphql-php-app 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 984 次下载、GitHub Stars 达 1, 最近一次更新时间为 2025 年 09 月 16 日, 在 PHP 生态内属于活跃度较高的组件。

我们在过去多个企业项目中使用过 fo3nix/shopify-graphql-php-app 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 fo3nix/shopify-graphql-php-app 我们能提供哪些服务?
定制开发 / 二次开发

基于 fo3nix/shopify-graphql-php-app 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 984
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 1
  • 点击次数: 5
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 1
  • Watchers: 0
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: GPL-3.0-only
  • 更新时间: 2025-09-16