arrowsphere/catalog-graphql-client 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

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

arrowsphere/catalog-graphql-client

最新稳定版本:0.7.8

Composer 安装命令:

composer require arrowsphere/catalog-graphql-client

包简介

The official PHP client for ArrowSphere's Catalog GraphQL API

README 文档

README

Latest Stable Version Minimum PHP Version Build Status

This package provides a PHP client for ArrowSphere's Catalog GraphQL API. It should be the only way to make calls to ArrowSphere's Catalog GraphQL API with PHP code.

To use this package, you need valid access to ArrowSphere, with a valid token from the ArrowSphere's authentication platform.

Installation

Install the latest version with

$ composer require arrowsphere/catalog-graphql-client

Basic usage

<?php

use ArrowSphere\CatalogGraphQLClient\CatalogGraphQLClient;
use ArrowSphere\CatalogGraphQLClient\Input\SearchBody;
use ArrowSphere\CatalogGraphQLClient\Types\ArrowsphereIdentifier;
use ArrowSphere\CatalogGraphQLClient\Types\Identifiers;
use ArrowSphere\CatalogGraphQLClient\Types\Product;
use ArrowSphere\CatalogGraphQLClient\Types\Program;
use ArrowSphere\CatalogGraphQLClient\Types\VendorIdentifier;

const URL = 'https://your-url-to-arrowsphere.example.com';

$token = 'my token'; // The logic to get the token is not implemented in this package

$client = new CatalogGraphQLClient(URL, $token);

// The filters are defined as a nested array
// They allow you to limit the data you want to see
$filters = [
    Product::CLASSIFICATION => 'SaaS',
    Product::IDENTIFIERS => [
        Identifiers::VENDOR => [
            VendorIdentifier::SKU => '031C9E47-4802-4248-838E-778FB1D2CC05',
        ],
    ],
    Product::PROGRAM => [
        Program::LEGACY_CODE => 'microsoft',
    ],
];

// The fields are also defined as a nested array
// They allow you to limit the fields returned by the GraphQL API, to see only the necessary fields for your need
$fields = [
    Product::NAME,
    Product::IDENTIFIERS => [
        Identifiers::ARROWSPHERE => [
            ArrowsphereIdentifier::ORDERABLE_SKU,
        ],
        Identifiers::VENDOR => [
            VendorIdentifier::SKU,
        ]
    ]
];

$searchBody = [
    SearchBody::MARKETPLACE => 'US',
    SearchBody::FILTERS     => $filters,
];

$result = $client->find($searchBody, $fields);

$products = $result->getProducts();
if (count($products) === 1) {
    $product = $products[0];
    echo sprintf(
        "Product SKU %s : name = %s, orderable SKU = %s",
        $product->getIdentifiers()->getVendor()->getSku(),
        $product->getName(),
        $product->getIdentifiers()->getArrowsphere()->getOrderableSku()
     ) . PHP_EOL;
}

More information

This library returns a result based on the entities defined in the ArrowSphere\CatalogGraphQLClient\Types namespace.

The find method from the CatalogGraphQLClient class is a simplified method that calls the getProducts query from the API and returns as instance of PaginatedProducts which allows you to access to any field you requested in the original query.

Please note that each field is nullable, you need to request a field for it to be populated by the API.

There is also a generic call method in the CatalogGraphQLClient class that allows you to perform any query on the GraphQL API. This method doesn't provide any help, so it's a bit complicated to use "as is". The usage of the find method is recommended.

统计信息

  • 总下载量: 31.58k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 3
  • 点击次数: 3
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 3
  • Watchers: 4
  • Forks: 11
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 未知

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固