Skip to content

Commit 3566f63

Browse files
authored
Merge pull request #125 from TomHAnderson/feature/shared-type-manager3
Use shared type manager for multiple drivers
2 parents 787f8ad + 7beea86 commit 3566f63

3 files changed

Lines changed: 48 additions & 7 deletions

File tree

src/Type/PageInfo.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,6 @@
77
use GraphQL\Type\Definition\ObjectType;
88
use GraphQL\Type\Definition\Type;
99

10-
use function uniqid;
11-
1210
class PageInfo extends ObjectType
1311
{
1412
public function __construct()
@@ -21,7 +19,7 @@ public function __construct()
2119
* GraphQL spec:ification.
2220
* https://relay.dev/graphql/connections.htm#sec-Connection-Types.Fields.PageInfo
2321
*/
24-
'name' => 'PageInfo_' . uniqid(), // must start with a letter
22+
'name' => 'PageInfo',
2523
'description' => 'Page information',
2624
'fields' => [
2725
'startCursor' => [

src/Type/Pagination.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,12 @@
77
use GraphQL\Type\Definition\InputObjectType;
88
use GraphQL\Type\Definition\Type;
99

10-
use function uniqid;
11-
1210
class Pagination extends InputObjectType
1311
{
1412
public function __construct()
1513
{
1614
$configuration = [
17-
'name' => 'Pagination_' . uniqid(), // must start with a letter
15+
'name' => 'Pagination',
1816
'description' => 'Pagination fields for the GraphQL Complete Connection Model',
1917
'fields' => [
2018
'first' => [

test/Feature/Criteria/CriteriaTypeCollisionTest.php

Lines changed: 46 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
use ApiSkeletons\Doctrine\GraphQL\Config;
88
use ApiSkeletons\Doctrine\GraphQL\Driver;
9+
use ApiSkeletons\Doctrine\GraphQL\Type\TypeManager;
910
use ApiSkeletonsTest\Doctrine\GraphQL\AbstractTest;
1011
use ApiSkeletonsTest\Doctrine\GraphQL\Entity\Performance;
1112
use GraphQL\GraphQL;
@@ -19,6 +20,8 @@ public function testCriteriaTypeCollision(): void
1920
$driver1 = new Driver($this->getEntityManager());
2021
$driver2 = new Driver($this->getEntityManager(), new Config(['group' => 'ExcludeCriteriaTest']));
2122

23+
$driver2->set(TypeManager::class, $driver1->get(TypeManager::class));
24+
2225
$schema = new Schema([
2326
'query' => new ObjectType([
2427
'name' => 'query',
@@ -43,11 +46,53 @@ public function testCriteriaTypeCollision(): void
4346
]),
4447
]);
4548

46-
$query = '{ one: performance1 ( filter: { id: { eq: 2 } } ) { edges { node { id } } }, two: performance2 ( filter: { id: { eq: 2 } } ) { edges { node { id } } } }';
49+
$query = '{
50+
one: performance1 (
51+
filter: {
52+
id: {
53+
eq: 2
54+
}
55+
}
56+
) {
57+
edges {
58+
node {
59+
id
60+
}
61+
}
62+
pageInfo {
63+
hasNextPage
64+
}
65+
},
66+
two: performance2 (
67+
filter: {
68+
id: {
69+
eq: 2
70+
}
71+
}
72+
) {
73+
edges {
74+
node {
75+
id
76+
}
77+
}
78+
pageInfo {
79+
hasNextPage
80+
}
81+
}
82+
}';
4783
$result = GraphQL::executeQuery($schema, $query);
4884

4985
$data = $result->toArray()['data'];
5086

5187
$this->assertEquals($data['one']['edges'][0]['node']['id'], $data['two']['edges'][0]['node']['id']);
88+
$this->assertSame($driver1->get(TypeManager::class), $driver2->get(TypeManager::class));
89+
$this->assertSame(
90+
$driver1->get(TypeManager::class)->get('pageinfo'),
91+
$driver2->get(TypeManager::class)->get('pageinfo'),
92+
);
93+
$this->assertSame(
94+
$driver1->get(TypeManager::class)->get('pagination'),
95+
$driver2->get(TypeManager::class)->get('pagination'),
96+
);
5297
}
5398
}

0 commit comments

Comments
 (0)