Skip to content

Commit

Permalink
Merge 8d47f08 into 3af8b92
Browse files Browse the repository at this point in the history
  • Loading branch information
cwdt committed Mar 23, 2021
2 parents 3af8b92 + 8d47f08 commit 3c1b6de
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 38 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
@@ -1,6 +1,8 @@
# Changelog

#### Unreleased
Fix:
- Allow sending both query and queryId, ignore queryId in that case (#789)

#### 14.5.1

Expand Down
2 changes: 1 addition & 1 deletion docs/executing-queries.md
Expand Up @@ -102,7 +102,7 @@ fieldResolver | `callable` | A resolver function to use when one is not provided
validationRules | `array` or `callable` | A set of rules for query validation step. The default value is all available rules. The empty array would allow skipping query validation (may be convenient for persisted queries which are validated before persisting and assumed valid during execution).<br><br>Pass `callable` to return different validation rules for different queries (e.g. empty array for persisted query and a full list of rules for regular queries). When passed, it is expected to have the following signature: <br><br> **function ([OperationParams](reference.md#graphqlserveroperationparams) $params, DocumentNode $node, $operationType): array**
queryBatching | `bool` | Flag indicating whether this server supports query batching ([apollo-style](https://dev-blog.apollodata.com/query-batching-in-apollo-63acfd859862)).<br><br> Defaults to **false**
debug | `int` | Debug flags. See [docs on error debugging](error-handling.md#debugging-tools) (flag values are the same).
persistentQueryLoader | `callable` | A function which is called to fetch actual query when server encounters **queryId** in request vs **query**.<br><br> The server does not implement persistence part (which you will have to build on your own), but it allows you to execute queries which were persisted previously.<br><br> Expected function signature:<br> **function ($queryId, [OperationParams](reference.md#graphqlserveroperationparams) $params)** <br><br>Function is expected to return query **string** or parsed **DocumentNode** <br><br> [Read more about persisted queries](https://dev-blog.apollodata.com/persisted-graphql-queries-with-apollo-client-119fd7e6bba5).
persistentQueryLoader | `callable` | A function which is called to fetch actual query when server encounters a **queryId** without a **query**.<br><br> The server does not implement persistence part (which you will have to build on your own), but it allows you to execute queries which were persisted previously.<br><br> Expected function signature:<br> **function ($queryId, [OperationParams](reference.md#graphqlserveroperationparams) $params)** <br><br>Function is expected to return query **string** or parsed **DocumentNode** <br><br> [Read more about persisted queries](https://dev-blog.apollodata.com/persisted-graphql-queries-with-apollo-client-119fd7e6bba5).
errorFormatter | `callable` | Custom error formatter. See [error handling docs](error-handling.md#custom-error-handling-and-formatting).
errorsHandler | `callable` | Custom errors handler. See [error handling docs](error-handling.md#custom-error-handling-and-formatting).
promiseAdapter | [`PromiseAdapter`](reference.md#graphqlexecutorpromisepromiseadapter) | Required for [Async PHP](data-fetching/#async-php) only.
Expand Down
15 changes: 0 additions & 15 deletions phpstan-baseline.neon
Expand Up @@ -55,21 +55,6 @@ parameters:
count: 2
path: src/Server/Helper.php

-
message: "#^Only booleans are allowed in &&, string given on the left side\\.$#"
count: 1
path: src/Server/Helper.php

-
message: "#^Only booleans are allowed in &&, string given on the right side\\.$#"
count: 1
path: src/Server/Helper.php

-
message: "#^Only booleans are allowed in a ternary operator condition, string given\\.$#"
count: 1
path: src/Server/Helper.php

-
message: "#^Only booleans are allowed in an if condition, \\(callable\\)\\|null given\\.$#"
count: 1
Expand Down
6 changes: 1 addition & 5 deletions src/Server/Helper.php
Expand Up @@ -162,10 +162,6 @@ public function validateOperationParams(OperationParams $params)
$errors[] = new RequestError('GraphQL Request must include at least one of those two parameters: "query" or "queryId"');
}

if ($params->query && $params->queryId) {
$errors[] = new RequestError('GraphQL Request parameters "query" and "queryId" are mutually exclusive');
}

if ($params->query !== null && ! is_string($params->query)) {
$errors[] = new RequestError(
'GraphQL Request parameter "query" must be string, but got ' .
Expand Down Expand Up @@ -281,7 +277,7 @@ static function (RequestError $err) : Error {
);
}

$doc = $op->queryId
$doc = $op->queryId !== null && $op->query === null
? $this->loadPersistedQuery($config, $op)
: $op->query;

Expand Down
19 changes: 15 additions & 4 deletions tests/Server/QueryExecutionTest.php
Expand Up @@ -47,17 +47,28 @@ public function testSimpleQueryExecution() : void
$this->assertQueryResultEquals($expected, $query);
}

private function assertQueryResultEquals($expected, $query, $variables = null)
public function testExecutesQueryWhenQueryAndQueryIdArePassed() : void
{
$result = $this->executeQuery($query, $variables);
$query = '{f1}';

$expected = [
'data' => ['f1' => 'f1'],
];

$this->assertQueryResultEquals($expected, $query, [], 'some-id');
}

private function assertQueryResultEquals($expected, $query, $variables = null, $queryId = null)
{
$result = $this->executeQuery($query, $variables, false, $queryId);
self::assertArraySubset($expected, $result->toArray(DebugFlag::INCLUDE_DEBUG_MESSAGE));

return $result;
}

private function executeQuery($query, $variables = null, $readonly = false)
private function executeQuery($query, $variables = null, $readonly = false, $queryId = null)
{
$op = OperationParams::create(['query' => $query, 'variables' => $variables], $readonly);
$op = OperationParams::create(['query' => $query, 'variables' => $variables, 'queryId' => $queryId], $readonly);
$helper = new Helper();
$result = $helper->executeOperation($this->config, $op);
self::assertInstanceOf(ExecutionResult::class, $result);
Expand Down
13 changes: 0 additions & 13 deletions tests/Server/RequestValidationTest.php
Expand Up @@ -71,19 +71,6 @@ private function assertInputError($parsedRequest, $expectedMessage)
}
}

public function testFailsWhenBothQueryAndQueryIdArePresent() : void
{
$parsedBody = OperationParams::create([
'query' => '{my query}',
'queryId' => 'my-query-id',
]);

$this->assertInputError(
$parsedBody,
'GraphQL Request parameters "query" and "queryId" are mutually exclusive'
);
}

public function testFailsWhenQueryParameterIsNotString() : void
{
$parsedBody = OperationParams::create([
Expand Down

0 comments on commit 3c1b6de

Please sign in to comment.