wpjshop/graphql-client

GraphQL client for WPJ GraphQL API.

v2.0.1 2024-02-28 09:39 UTC

This package is auto-updated.

Last update: 2024-05-28 10:23:25 UTC


README

Installation

composer require wpjshop/graphql-client

Documentation

GraphQL API documentation here

Instantiate a client

<?php
$client = new \WpjShop\GraphQL\Client('https://your-domain/admin/graphql', '<authentication-token>');

Using the GraphQL Client

Simple use:

<?php
// Returns product data by ID.
$result = $client->product->get(1);
// Returns products collection.
$result = $client->product->list();
// Returns an array with result status and created product.
$result = $client->product->create(['title' => 'New product']);
// Returns an array with result status and updated product.
$result = $client->product->update(1, ['price' => ['priceWithoutVat' => 100]]);

// Returns parameter data by ID.
$result = $client->parameter->get(1);
// ...

Usage with custom field selection:

<?php
// Returns an array with data defined by `setSelection` method
$result = $client->product
    ->setSelection(
        [
            'id',
            'variations' => [
                'id',
                'price' => [
                    'withVat',
                    'vat',
                    'currency' => [
                        'code',
                    ],
                ],
            ],
        ]
)->get(1);

GraphQL Client Reference

Each service has at least 4 basic methods:

<?php
$client->{service}->get(int $id); // gets item by ID
$client->{service}->list(int $offset = 0, int $limit = 100); // items collection
$client->{service}->create(array $data); // create new item
$client->{service}->update(int $id, array $data); // updates item by ID

Services may have additional methods that are specific to them. For example update of product parameter:

<?php
$client->product->updateParameter(int $productId, int $parameterId, array $values, bool $append = false);

You can build custom query using this library that is a part of this client.

<?php
$client->runQuery($query, bool $resultsAsArray = false, array $variables = []);
$client->runRawQuery(string $queryString, $resultsAsArray = false, array $variables = []);