Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
"require": {
"php": "^7.1 || ^8.0",
"ext-json": "*",
"psr/http-message": "^1.0",
"psr/http-message": "^1.0 || ^2.0",
"psr/http-client": "^1.0",
"guzzlehttp/guzzle": "^6.3|^7.0.1"
},
Expand Down
9 changes: 8 additions & 1 deletion examples/query_example.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

require_once __DIR__ . '/../vendor/autoload.php';

use GraphQL\ArgumentObject;
use GraphQL\Client;
use GraphQL\Exception\QueryError;
use GraphQL\Query;
Expand All @@ -15,7 +16,13 @@

// Create the GraphQL query
$gql = (new Query('pokemon'))
->setArguments(['name' => 'Pikachu'])
->setArguments([
'name' => 'Pikachu',
'age' => new ArgumentObject([
'min' => 7,
'max' => 20
]),
])
->setSelectionSet(
[
'id',
Expand Down
39 changes: 39 additions & 0 deletions src/ArgumentObject.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?php

namespace GraphQL;

use GraphQL\Util\StringLiteralFormatter;

class ArgumentObject
{

/**
* @var array
*/
private $input;

/**
* @param array $input
*/
public function __construct(array $input)
{
$this->input = $input;
}


public function __toString(): string
{
$result = [];
foreach ($this->input as $key => $value) {
if (is_scalar($value) || $value === null) {
$value = StringLiteralFormatter::formatValueForRHS($value);
} elseif (is_array($value)) {
$value = StringLiteralFormatter::formatArrayForGQLQuery($value);
}

$result[] = "${key}: ${value}";
}

return '{' . implode(', ', $result) . '}';
}
}