24
24
use TheCodingMachine \GraphQLite \Fixtures \TestControllerWithInvalidReturnType ;
25
25
use TheCodingMachine \GraphQLite \Fixtures \TestControllerWithIterableParam ;
26
26
use TheCodingMachine \GraphQLite \Fixtures \TestControllerWithIterableReturnType ;
27
+ use TheCodingMachine \GraphQLite \Fixtures \TestFieldBadOutputType ;
27
28
use TheCodingMachine \GraphQLite \Fixtures \TestObject ;
28
29
use TheCodingMachine \GraphQLite \Fixtures \TestSelfType ;
30
+ use TheCodingMachine \GraphQLite \Fixtures \TestSourceFieldBadOutputType ;
31
+ use TheCodingMachine \GraphQLite \Fixtures \TestSourceFieldBadOutputType2 ;
29
32
use TheCodingMachine \GraphQLite \Fixtures \TestType ;
30
33
use TheCodingMachine \GraphQLite \Fixtures \TestTypeId ;
31
34
use TheCodingMachine \GraphQLite \Fixtures \TestTypeMissingAnnotation ;
36
39
use TheCodingMachine \GraphQLite \Containers \EmptyContainer ;
37
40
use TheCodingMachine \GraphQLite \Containers \BasicAutoWiringContainer ;
38
41
use TheCodingMachine \GraphQLite \Mappers \CannotMapTypeException ;
42
+ use TheCodingMachine \GraphQLite \Mappers \CannotMapTypeExceptionInterface ;
39
43
use TheCodingMachine \GraphQLite \Reflection \CachedDocBlockFactory ;
40
44
use TheCodingMachine \GraphQLite \Security \AuthenticationServiceInterface ;
41
45
use TheCodingMachine \GraphQLite \Security \AuthorizationServiceInterface ;
@@ -55,7 +59,7 @@ public function testQueryProvider()
55
59
56
60
$ queries = $ queryProvider ->getQueries ($ controller );
57
61
58
- $ this ->assertCount (6 , $ queries );
62
+ $ this ->assertCount (7 , $ queries );
59
63
$ usersQuery = $ queries [0 ];
60
64
$ this ->assertSame ('test ' , $ usersQuery ->name );
61
65
@@ -146,12 +150,29 @@ public function testQueryProviderWithFixedReturnType()
146
150
147
151
$ queries = $ queryProvider ->getQueries ($ controller );
148
152
149
- $ this ->assertCount (6 , $ queries );
153
+ $ this ->assertCount (7 , $ queries );
150
154
$ fixedQuery = $ queries [1 ];
151
155
152
156
$ this ->assertInstanceOf (IDType::class, $ fixedQuery ->getType ());
153
157
}
154
158
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
+
155
176
public function testNameFromAnnotation ()
156
177
{
157
178
$ controller = new TestController ();
@@ -312,7 +333,7 @@ public function testQueryProviderWithIterableClass()
312
333
313
334
$ queries = $ queryProvider ->getQueries ($ controller );
314
335
315
- $ this ->assertCount (6 , $ queries );
336
+ $ this ->assertCount (7 , $ queries );
316
337
$ iterableQuery = $ queries [3 ];
317
338
318
339
$ this ->assertInstanceOf (NonNull::class, $ iterableQuery ->getType ());
@@ -328,7 +349,7 @@ public function testQueryProviderWithIterable()
328
349
329
350
$ queries = $ queryProvider ->getQueries (new TestController ());
330
351
331
- $ this ->assertCount (6 , $ queries );
352
+ $ this ->assertCount (7 , $ queries );
332
353
$ iterableQuery = $ queries [4 ];
333
354
334
355
$ this ->assertInstanceOf (NonNull::class, $ iterableQuery ->getType ());
@@ -353,7 +374,7 @@ public function testQueryProviderWithUnion()
353
374
354
375
$ queries = $ queryProvider ->getQueries ($ controller );
355
376
356
- $ this ->assertCount (6 , $ queries );
377
+ $ this ->assertCount (7 , $ queries );
357
378
$ unionQuery = $ queries [5 ];
358
379
359
380
$ this ->assertInstanceOf (NonNull::class, $ unionQuery ->getType ());
@@ -471,4 +492,28 @@ public function testSourceFieldWithFailWith()
471
492
472
493
$ this ->assertInstanceOf (StringType::class, $ fields ['test ' ]->getType ());
473
494
}
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
+ }
474
519
}
0 commit comments