2424use TheCodingMachine \GraphQLite \Fixtures \TestControllerWithInvalidReturnType ;
2525use TheCodingMachine \GraphQLite \Fixtures \TestControllerWithIterableParam ;
2626use TheCodingMachine \GraphQLite \Fixtures \TestControllerWithIterableReturnType ;
27+ use TheCodingMachine \GraphQLite \Fixtures \TestFieldBadOutputType ;
2728use TheCodingMachine \GraphQLite \Fixtures \TestObject ;
2829use TheCodingMachine \GraphQLite \Fixtures \TestSelfType ;
30+ use TheCodingMachine \GraphQLite \Fixtures \TestSourceFieldBadOutputType ;
31+ use TheCodingMachine \GraphQLite \Fixtures \TestSourceFieldBadOutputType2 ;
2932use TheCodingMachine \GraphQLite \Fixtures \TestType ;
3033use TheCodingMachine \GraphQLite \Fixtures \TestTypeId ;
3134use TheCodingMachine \GraphQLite \Fixtures \TestTypeMissingAnnotation ;
3639use TheCodingMachine \GraphQLite \Containers \EmptyContainer ;
3740use TheCodingMachine \GraphQLite \Containers \BasicAutoWiringContainer ;
3841use TheCodingMachine \GraphQLite \Mappers \CannotMapTypeException ;
42+ use TheCodingMachine \GraphQLite \Mappers \CannotMapTypeExceptionInterface ;
3943use TheCodingMachine \GraphQLite \Reflection \CachedDocBlockFactory ;
4044use TheCodingMachine \GraphQLite \Security \AuthenticationServiceInterface ;
4145use TheCodingMachine \GraphQLite \Security \AuthorizationServiceInterface ;
@@ -55,7 +59,7 @@ public function testQueryProvider()
5559
5660 $ queries = $ queryProvider ->getQueries ($ controller );
5761
58- $ this ->assertCount (6 , $ queries );
62+ $ this ->assertCount (7 , $ queries );
5963 $ usersQuery = $ queries [0 ];
6064 $ this ->assertSame ('test ' , $ usersQuery ->name );
6165
@@ -146,12 +150,29 @@ public function testQueryProviderWithFixedReturnType()
146150
147151 $ queries = $ queryProvider ->getQueries ($ controller );
148152
149- $ this ->assertCount (6 , $ queries );
153+ $ this ->assertCount (7 , $ queries );
150154 $ fixedQuery = $ queries [1 ];
151155
152156 $ this ->assertInstanceOf (IDType::class, $ fixedQuery ->getType ());
153157 }
154158
159+ public function testQueryProviderWithComplexFixedReturnType ()
160+ {
161+ $ controller = new TestController ();
162+
163+ $ queryProvider = $ this ->buildFieldsBuilder ();
164+
165+ $ queries = $ queryProvider ->getQueries ($ controller );
166+
167+ $ this ->assertCount (7 , $ queries );
168+ $ fixedQuery = $ queries [6 ];
169+
170+ $ this ->assertInstanceOf (NonNull::class, $ fixedQuery ->getType ());
171+ $ this ->assertInstanceOf (ListOfType::class, $ fixedQuery ->getType ()->getWrappedType ());
172+ $ this ->assertInstanceOf (NonNull::class, $ fixedQuery ->getType ()->getWrappedType ()->getWrappedType ());
173+ $ this ->assertInstanceOf (IDType::class, $ fixedQuery ->getType ()->getWrappedType ()->getWrappedType ()->getWrappedType ());
174+ }
175+
155176 public function testNameFromAnnotation ()
156177 {
157178 $ controller = new TestController ();
@@ -312,7 +333,7 @@ public function testQueryProviderWithIterableClass()
312333
313334 $ queries = $ queryProvider ->getQueries ($ controller );
314335
315- $ this ->assertCount (6 , $ queries );
336+ $ this ->assertCount (7 , $ queries );
316337 $ iterableQuery = $ queries [3 ];
317338
318339 $ this ->assertInstanceOf (NonNull::class, $ iterableQuery ->getType ());
@@ -328,7 +349,7 @@ public function testQueryProviderWithIterable()
328349
329350 $ queries = $ queryProvider ->getQueries (new TestController ());
330351
331- $ this ->assertCount (6 , $ queries );
352+ $ this ->assertCount (7 , $ queries );
332353 $ iterableQuery = $ queries [4 ];
333354
334355 $ this ->assertInstanceOf (NonNull::class, $ iterableQuery ->getType ());
@@ -353,7 +374,7 @@ public function testQueryProviderWithUnion()
353374
354375 $ queries = $ queryProvider ->getQueries ($ controller );
355376
356- $ this ->assertCount (6 , $ queries );
377+ $ this ->assertCount (7 , $ queries );
357378 $ unionQuery = $ queries [5 ];
358379
359380 $ this ->assertInstanceOf (NonNull::class, $ unionQuery ->getType ());
@@ -471,4 +492,28 @@ public function testSourceFieldWithFailWith()
471492
472493 $ this ->assertInstanceOf (StringType::class, $ fields ['test ' ]->getType ());
473494 }
495+
496+ public function testSourceFieldBadOutputTypeException ()
497+ {
498+ $ queryProvider = $ this ->buildFieldsBuilder ();
499+ $ this ->expectException (CannotMapTypeExceptionInterface::class);
500+ $ this ->expectExceptionMessage ('For @SourceField "test" declared in "TheCodingMachine\GraphQLite\Fixtures\TestSourceFieldBadOutputType", cannot find GraphQL type "[NotExists]". Check your TypeMapper configuration. ' );
501+ $ queryProvider ->getFields (new TestSourceFieldBadOutputType (), true );
502+ }
503+
504+ public function testSourceFieldBadOutputType2Exception ()
505+ {
506+ $ queryProvider = $ this ->buildFieldsBuilder ();
507+ $ this ->expectException (CannotMapTypeExceptionInterface::class);
508+ $ this ->expectExceptionMessage ('For @SourceField "test" declared in "TheCodingMachine\GraphQLite\Fixtures\TestSourceFieldBadOutputType2", Syntax Error: Expected ], found <EOF> ' );
509+ $ queryProvider ->getFields (new TestSourceFieldBadOutputType2 (), true );
510+ }
511+
512+ public function testBadOutputTypeException ()
513+ {
514+ $ queryProvider = $ this ->buildFieldsBuilder ();
515+ $ this ->expectException (CannotMapTypeExceptionInterface::class);
516+ $ this ->expectExceptionMessage ('For return type of TheCodingMachine\GraphQLite\Fixtures\TestFieldBadOutputType::test, cannot find GraphQL type "[NotExists]". Check your TypeMapper configuration. ' );
517+ $ queryProvider ->getFields (new TestFieldBadOutputType (), true );
518+ }
474519}
0 commit comments