PHP code example of wpjshop / graphql-client

1. Go to this page and download the library: Download wpjshop/graphql-client library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

wpjshop / graphql-client example snippets



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


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


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


$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


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


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