Skip to content

Commit 999696a

Browse files
committed
Adding support for complex GraphQL types in "outputType" parameter
Currently, the "outputType" parameter of the Field/Query/Mutation annotations only supports Scalar or ObjectType. We should instead support all possible types in the GraphQL syntax. For instance: ``` @field(outputType="[User!]!") ``` This first commit contains a failing test showcasing the issue.
1 parent bd09f5a commit 999696a

File tree

3 files changed

+30
-10
lines changed

3 files changed

+30
-10
lines changed

src/FieldsBuilder.php

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -524,11 +524,6 @@ private function mapParameters(array $refParameters, DocBlock $docBlock): array
524524
return $args;
525525
}
526526

527-
/**
528-
* @param Type $type
529-
* @param Type|null $docBlockType
530-
* @return GraphQLType
531-
*/
532527
private function mapType(Type $type, ?Type $docBlockType, bool $isNullable, bool $mapToInputType): GraphQLType
533528
{
534529
$graphQlType = null;

tests/FieldsBuilderTest.php

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ public function testQueryProvider()
5555

5656
$queries = $queryProvider->getQueries($controller);
5757

58-
$this->assertCount(6, $queries);
58+
$this->assertCount(7, $queries);
5959
$usersQuery = $queries[0];
6060
$this->assertSame('test', $usersQuery->name);
6161

@@ -146,12 +146,29 @@ public function testQueryProviderWithFixedReturnType()
146146

147147
$queries = $queryProvider->getQueries($controller);
148148

149-
$this->assertCount(6, $queries);
149+
$this->assertCount(7, $queries);
150150
$fixedQuery = $queries[1];
151151

152152
$this->assertInstanceOf(IDType::class, $fixedQuery->getType());
153153
}
154154

155+
public function testQueryProviderWithComplexFixedReturnType()
156+
{
157+
$controller = new TestController();
158+
159+
$queryProvider = $this->buildFieldsBuilder();
160+
161+
$queries = $queryProvider->getQueries($controller);
162+
163+
$this->assertCount(7, $queries);
164+
$fixedQuery = $queries[6];
165+
166+
$this->assertInstanceOf(NonNull::class, $fixedQuery->getType());
167+
$this->assertInstanceOf(ListOfType::class, $fixedQuery->getType()->getWrappedType());
168+
$this->assertInstanceOf(NonNull::class, $fixedQuery->getType()->getWrappedType()->getWrappedType());
169+
$this->assertInstanceOf(IDType::class, $fixedQuery->getType()->getWrappedType()->getWrappedType()->getWrappedType());
170+
}
171+
155172
public function testNameFromAnnotation()
156173
{
157174
$controller = new TestController();
@@ -312,7 +329,7 @@ public function testQueryProviderWithIterableClass()
312329

313330
$queries = $queryProvider->getQueries($controller);
314331

315-
$this->assertCount(6, $queries);
332+
$this->assertCount(7, $queries);
316333
$iterableQuery = $queries[3];
317334

318335
$this->assertInstanceOf(NonNull::class, $iterableQuery->getType());
@@ -328,7 +345,7 @@ public function testQueryProviderWithIterable()
328345

329346
$queries = $queryProvider->getQueries(new TestController());
330347

331-
$this->assertCount(6, $queries);
348+
$this->assertCount(7, $queries);
332349
$iterableQuery = $queries[4];
333350

334351
$this->assertInstanceOf(NonNull::class, $iterableQuery->getType());
@@ -353,7 +370,7 @@ public function testQueryProviderWithUnion()
353370

354371
$queries = $queryProvider->getQueries($controller);
355372

356-
$this->assertCount(6, $queries);
373+
$this->assertCount(7, $queries);
357374
$unionQuery = $queries[5];
358375

359376
$this->assertInstanceOf(NonNull::class, $unionQuery->getType());

tests/Fixtures/TestController.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,4 +107,12 @@ public function testUnion()
107107
{
108108
return new TestObject2('foo');
109109
}
110+
111+
/**
112+
* @Query(outputType="[ID!]!")
113+
*/
114+
public function testFixComplexReturnType(): array
115+
{
116+
return ['42'];
117+
}
110118
}

0 commit comments

Comments
 (0)