Don't flatten batch results
This commit is contained in:
parent
742fc98cfc
commit
a99ade13c0
3 changed files with 69 additions and 46 deletions
|
@ -220,12 +220,16 @@ function parseMultipart(array $query, Request $request): array
|
||||||
*/
|
*/
|
||||||
function processResult($result, $debugFlags): array
|
function processResult($result, $debugFlags): array
|
||||||
{
|
{
|
||||||
|
// Only one query, return the result
|
||||||
if (!isset($result[1])) {
|
if (!isset($result[1])) {
|
||||||
return $result[0]->toArray($debugFlags);
|
return $result[0]->toArray($debugFlags);
|
||||||
}
|
}
|
||||||
|
|
||||||
return \array_merge_recursive(...\array_map(
|
// Batched queries, return an array of results
|
||||||
static fn ($item) => $item->toArray($debugFlags),
|
return \array_map(
|
||||||
|
static function ($item) use ($debugFlags) {
|
||||||
|
return $item->toArray($debugFlags);
|
||||||
|
},
|
||||||
$result
|
$result
|
||||||
));
|
);
|
||||||
}
|
}
|
||||||
|
|
|
@ -27,12 +27,14 @@ class BatchTest extends Scope
|
||||||
'x-appwrite-project' => $projectId,
|
'x-appwrite-project' => $projectId,
|
||||||
], $this->getHeaders()), $graphQLPayload);
|
], $this->getHeaders()), $graphQLPayload);
|
||||||
|
|
||||||
$this->assertIsArray($response['body']['data']);
|
$this->assertIsArray($response['body'][0]['data']);
|
||||||
$this->assertArrayNotHasKey('errors', $response['body']);
|
$this->assertIsArray($response['body'][1]['data']);
|
||||||
$this->assertArrayHasKey('localeListCountries', $response['body']['data']);
|
$this->assertArrayNotHasKey('errors', $response['body'][0]);
|
||||||
$this->assertArrayHasKey('localeListContinents', $response['body']['data']);
|
$this->assertArrayNotHasKey('errors', $response['body'][1]);
|
||||||
$this->assertEquals(194, $response['body']['data']['localeListCountries']['total']);
|
$this->assertArrayHasKey('localeListCountries', $response['body'][0]['data']);
|
||||||
$this->assertEquals(7, $response['body']['data']['localeListContinents']['total']);
|
$this->assertArrayHasKey('localeListContinents', $response['body'][1]['data']);
|
||||||
|
$this->assertEquals(194, $response['body'][0]['data']['localeListCountries']['total']);
|
||||||
|
$this->assertEquals(7, $response['body'][1]['data']['localeListContinents']['total']);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testArrayBatchedQueriesOfSameType()
|
public function testArrayBatchedQueriesOfSameType()
|
||||||
|
@ -48,12 +50,14 @@ class BatchTest extends Scope
|
||||||
'x-appwrite-project' => $projectId,
|
'x-appwrite-project' => $projectId,
|
||||||
], $this->getHeaders()), $graphQLPayload);
|
], $this->getHeaders()), $graphQLPayload);
|
||||||
|
|
||||||
$this->assertIsArray($response['body']['data']);
|
$this->assertIsArray($response['body'][0]['data']);
|
||||||
$this->assertArrayNotHasKey('errors', $response['body']);
|
$this->assertIsArray($response['body'][1]['data']);
|
||||||
$this->assertArrayHasKey('localeListCountries', $response['body']['data']);
|
$this->assertArrayNotHasKey('errors', $response['body'][0]);
|
||||||
$this->assertEquals(194, $response['body']['data']['localeListCountries']['total'][0]);
|
$this->assertArrayNotHasKey('errors', $response['body'][1]);
|
||||||
$this->assertEquals(194, $response['body']['data']['localeListCountries']['total'][1]);
|
$this->assertArrayHasKey('localeListCountries', $response['body'][0]['data']);
|
||||||
$this->assertEquals(388, \count($response['body']['data']['localeListCountries']['countries']));
|
$this->assertArrayHasKey('localeListCountries', $response['body'][1]['data']);
|
||||||
|
$this->assertEquals(194, $response['body'][0]['data']['localeListCountries']['total']);
|
||||||
|
$this->assertEquals(194, $response['body'][1]['data']['localeListCountries']['total']);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testArrayBatchedMutations()
|
public function testArrayBatchedMutations()
|
||||||
|
@ -90,12 +94,14 @@ class BatchTest extends Scope
|
||||||
'x-appwrite-project' => $projectId,
|
'x-appwrite-project' => $projectId,
|
||||||
], $this->getHeaders()), $graphQLPayload);
|
], $this->getHeaders()), $graphQLPayload);
|
||||||
|
|
||||||
$this->assertIsArray($response['body']['data']);
|
$this->assertIsArray($response['body'][0]['data']);
|
||||||
$this->assertArrayNotHasKey('errors', $response['body']);
|
$this->assertIsArray($response['body'][1]['data']);
|
||||||
$this->assertArrayHasKey('accountCreate', $response['body']['data']);
|
$this->assertArrayNotHasKey('errors', $response['body'][0]);
|
||||||
$this->assertArrayHasKey('teamsCreate', $response['body']['data']);
|
$this->assertArrayNotHasKey('errors', $response['body'][1]);
|
||||||
$this->assertEquals('Tester 1', $response['body']['data']['accountCreate']['name']);
|
$this->assertArrayHasKey('accountCreate', $response['body'][0]['data']);
|
||||||
$this->assertEquals('Team 1', $response['body']['data']['teamsCreate']['name']);
|
$this->assertArrayHasKey('teamsCreate', $response['body'][1]['data']);
|
||||||
|
$this->assertEquals('Tester 1', $response['body'][0]['data']['accountCreate']['name']);
|
||||||
|
$this->assertEquals('Team 1', $response['body'][1]['data']['teamsCreate']['name']);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testArrayBatchedMutationsOfSameType()
|
public function testArrayBatchedMutationsOfSameType()
|
||||||
|
@ -135,10 +141,12 @@ class BatchTest extends Scope
|
||||||
'x-appwrite-project' => $projectId,
|
'x-appwrite-project' => $projectId,
|
||||||
], $this->getHeaders()), $graphQLPayload);
|
], $this->getHeaders()), $graphQLPayload);
|
||||||
|
|
||||||
$this->assertIsArray($response['body']['data']);
|
$this->assertIsArray($response['body'][0]['data']);
|
||||||
$this->assertArrayNotHasKey('errors', $response['body']);
|
$this->assertIsArray($response['body'][1]['data']);
|
||||||
$this->assertArrayHasKey('accountCreate', $response['body']['data']);
|
$this->assertArrayNotHasKey('errors', $response['body'][0]);
|
||||||
$this->assertEquals(2, \count($response['body']['data']['accountCreate']['_id']));
|
$this->assertArrayNotHasKey('errors', $response['body'][1]);
|
||||||
|
$this->assertArrayHasKey('accountCreate', $response['body'][0]['data']);
|
||||||
|
$this->assertArrayHasKey('accountCreate', $response['body'][1]['data']);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testArrayBatchedMixed()
|
public function testArrayBatchedMixed()
|
||||||
|
@ -167,14 +175,18 @@ class BatchTest extends Scope
|
||||||
'x-appwrite-project' => $projectId,
|
'x-appwrite-project' => $projectId,
|
||||||
], $this->getHeaders()), $graphQLPayload);
|
], $this->getHeaders()), $graphQLPayload);
|
||||||
|
|
||||||
$this->assertIsArray($response['body']['data']);
|
$this->assertIsArray($response['body'][0]['data']);
|
||||||
$this->assertArrayNotHasKey('errors', $response['body']);
|
$this->assertIsArray($response['body'][1]['data']);
|
||||||
$this->assertArrayHasKey('localeListCountries', $response['body']['data']);
|
$this->assertIsArray($response['body'][2]['data']);
|
||||||
$this->assertArrayHasKey('localeListContinents', $response['body']['data']);
|
$this->assertArrayNotHasKey('errors', $response['body'][0]);
|
||||||
$this->assertArrayHasKey('accountCreate', $response['body']['data']);
|
$this->assertArrayNotHasKey('errors', $response['body'][1]);
|
||||||
$this->assertEquals(194, $response['body']['data']['localeListCountries']['total']);
|
$this->assertArrayNotHasKey('errors', $response['body'][2]);
|
||||||
$this->assertEquals(7, $response['body']['data']['localeListContinents']['total']);
|
$this->assertArrayHasKey('localeListCountries', $response['body'][0]['data']);
|
||||||
$this->assertEquals('Tester 1', $response['body']['data']['accountCreate']['name']);
|
$this->assertArrayHasKey('localeListContinents', $response['body'][1]['data']);
|
||||||
|
$this->assertArrayHasKey('accountCreate', $response['body'][2]['data']);
|
||||||
|
$this->assertEquals(194, $response['body'][0]['data']['localeListCountries']['total']);
|
||||||
|
$this->assertEquals(7, $response['body'][1]['data']['localeListContinents']['total']);
|
||||||
|
$this->assertEquals('Tester 1', $response['body'][2]['data']['accountCreate']['name']);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testArrayBatchedMixedOfSameType()
|
public function testArrayBatchedMixedOfSameType()
|
||||||
|
@ -204,13 +216,18 @@ class BatchTest extends Scope
|
||||||
'x-appwrite-project' => $projectId,
|
'x-appwrite-project' => $projectId,
|
||||||
], $this->getHeaders()), $graphQLPayload);
|
], $this->getHeaders()), $graphQLPayload);
|
||||||
|
|
||||||
$this->assertIsArray($response['body']['data']);
|
$this->assertIsArray($response['body'][0]['data']);
|
||||||
$this->assertArrayNotHasKey('errors', $response['body']);
|
$this->assertIsArray($response['body'][1]['data']);
|
||||||
$this->assertArrayHasKey('localeListCountries', $response['body']['data']);
|
$this->assertIsArray($response['body'][2]['data']);
|
||||||
$this->assertArrayHasKey('accountCreate', $response['body']['data']);
|
$this->assertArrayNotHasKey('errors', $response['body'][0]);
|
||||||
$this->assertEquals(194, $response['body']['data']['localeListCountries']['total'][0]);
|
$this->assertArrayNotHasKey('errors', $response['body'][1]);
|
||||||
$this->assertEquals(388, \count($response['body']['data']['localeListCountries']['countries']));
|
$this->assertArrayNotHasKey('errors', $response['body'][2]);
|
||||||
$this->assertArrayHasKey('_id', $response['body']['data']['accountCreate']);
|
$this->assertArrayHasKey('localeListCountries', $response['body'][0]['data']);
|
||||||
|
$this->assertArrayHasKey('localeListCountries', $response['body'][1]['data']);
|
||||||
|
$this->assertArrayHasKey('accountCreate', $response['body'][2]['data']);
|
||||||
|
$this->assertEquals(194, $response['body'][0]['data']['localeListCountries']['total']);
|
||||||
|
$this->assertEquals(194, $response['body'][1]['data']['localeListCountries']['total']);
|
||||||
|
$this->assertArrayHasKey('_id', $response['body'][2]['data']['accountCreate']);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testQueryBatchedQueries()
|
public function testQueryBatchedQueries()
|
||||||
|
|
|
@ -63,12 +63,14 @@ class ContentTypeTest extends Scope
|
||||||
'x-appwrite-project' => $projectId,
|
'x-appwrite-project' => $projectId,
|
||||||
], $this->getHeaders()), $graphQLPayload);
|
], $this->getHeaders()), $graphQLPayload);
|
||||||
|
|
||||||
$this->assertIsArray($response['body']['data']);
|
$this->assertIsArray($response['body'][0]['data']);
|
||||||
$this->assertArrayNotHasKey('errors', $response['body']);
|
$this->assertIsArray($response['body'][1]['data']);
|
||||||
$this->assertArrayHasKey('localeListCountries', $response['body']['data']);
|
$this->assertArrayNotHasKey('errors', $response['body'][0]);
|
||||||
$this->assertArrayHasKey('localeListContinents', $response['body']['data']);
|
$this->assertArrayNotHasKey('errors', $response['body'][1]);
|
||||||
$this->assertEquals(194, $response['body']['data']['localeListCountries']['total']);
|
$this->assertArrayHasKey('localeListCountries', $response['body'][0]['data']);
|
||||||
$this->assertEquals(7, $response['body']['data']['localeListContinents']['total']);
|
$this->assertArrayHasKey('localeListContinents', $response['body'][1]['data']);
|
||||||
|
$this->assertEquals(194, $response['body'][0]['data']['localeListCountries']['total']);
|
||||||
|
$this->assertEquals(7, $response['body'][1]['data']['localeListContinents']['total']);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testQueryBatchedJSONContentType()
|
public function testQueryBatchedJSONContentType()
|
||||||
|
|
Loading…
Reference in a new issue