arrowsphere / catalog-graphql-client
The official PHP client for ArrowSphere's Catalog GraphQL API
Installs: 20 924
Dependents: 0
Suggesters: 0
Security: 0
Stars: 2
Watchers: 6
Forks: 9
Open Issues: 1
Requires
- php: >=7.2.0
- ext-json: *
- gmostafa/php-graphql-client: ^1.9
- symfony/polyfill-php80: ^1.22
- symfony/polyfill-php81: ^1.22
Requires (Dev)
- illuminate/validation: ^5.5 || ^6.0 || ^7.0
- phpunit/phpunit: ^8.5.14 || ^9.3
README
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.