Skip to content

[FEATURE] addArguments() & addPrefix() to last item in selectionSet - helpers for mghoneimy/php-graphql-oqm #12

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 7 commits into from
Closed
8 changes: 4 additions & 4 deletions src/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,10 @@ public function __construct(string $endpointUrl, array $authorizationHeaders = [
* @param bool $resultsAsArray
* @param array $variables
*
* @return Results|null
* @return Results
* @throws QueryError
*/
public function runQuery($query, bool $resultsAsArray = false, array $variables = []): ?Results
public function runQuery($query, bool $resultsAsArray = false, array $variables = []): Results
{
if ($query instanceof QueryBuilderInterface) {
$query = $query->getQuery();
Expand All @@ -68,10 +68,10 @@ public function runQuery($query, bool $resultsAsArray = false, array $variables
* @param bool $resultsAsArray
* @param array $variables
*
* @return Results|null
* @return Results
* @throws QueryError
*/
public function runRawQuery(string $queryString, $resultsAsArray = false, array $variables = []): ?Results
public function runRawQuery(string $queryString, $resultsAsArray = false, array $variables = []): Results
{
// Set request headers for authorization and content type
if (!empty($this->authorizationHeaders)) {
Expand Down
2 changes: 1 addition & 1 deletion src/Query.php
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ protected function constructArguments(): string
}

// Convert argument values to graphql string literal equivalent
if (is_scalar($value)) {
if (is_scalar($value) || $value === null) {
// Convert scalar value to its literal in graphql
$value = StringLiteralFormatter::formatValueForRHS($value);
} elseif (is_array($value)) {
Expand Down
25 changes: 25 additions & 0 deletions tests/QueryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -353,6 +353,31 @@ public function testBooleanArgumentValue(Query $query)
return $query;
}

/**
* @depends clone testEmptyArguments
*
* @covers \GraphQL\Query::setArguments
* @covers \GraphQL\Query::constructArguments
*
* @param Query $query
*
* @return Query
*/
public function testNullArgumentValue(Query $query)
{
$query->setArguments(['arg1' => null]);
$this->assertEquals(
"query {
Object(arg1: null) {

}
}"
, (string) $query
);

return $query;
}

/**
* @depends clone testEmptyArguments
*
Expand Down