From 8eccb205179132b5d4ddef45873cc78f915362cb Mon Sep 17 00:00:00 2001 From: Eduards Gruberts Date: Tue, 26 Aug 2025 11:19:21 +0300 Subject: [PATCH 1/3] Added ArgumentObject class to describe more complex input objects --- src/ArgumentObject.php | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 src/ArgumentObject.php diff --git a/src/ArgumentObject.php b/src/ArgumentObject.php new file mode 100644 index 0000000..7202f6c --- /dev/null +++ b/src/ArgumentObject.php @@ -0,0 +1,39 @@ +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) . '}'; + } +} From 0788ed91db0a6ebdb09fa2dbc4831f0b45e402d5 Mon Sep 17 00:00:00 2001 From: Eduards Gruberts Date: Tue, 26 Aug 2025 11:21:59 +0300 Subject: [PATCH 2/3] modified example to demonstrate usage of ArgumentObject --- examples/query_example.php | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/examples/query_example.php b/examples/query_example.php index 7abc472..c038fa7 100644 --- a/examples/query_example.php +++ b/examples/query_example.php @@ -2,6 +2,7 @@ require_once __DIR__ . '/../vendor/autoload.php'; +use GraphQL\ArgumentObject; use GraphQL\Client; use GraphQL\Exception\QueryError; use GraphQL\Query; @@ -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', From 8c2826dd349977060f842c0ce7fd1c31ce9f86e0 Mon Sep 17 00:00:00 2001 From: Eduards Gruberts Date: Tue, 26 Aug 2025 11:40:53 +0300 Subject: [PATCH 3/3] update psr/http-message --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index d372cec..53a67e3 100644 --- a/composer.json +++ b/composer.json @@ -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" },