22
22
23
23
import graphql .schema .GraphQLSchema ;
24
24
import graphql .schema .idl .RuntimeWiring ;
25
- import graphql .schema .idl .SchemaGenerator ;
26
25
import org .assertj .core .api .AbstractAssert ;
27
26
import org .junit .jupiter .api .Nested ;
28
27
import org .junit .jupiter .api .Test ;
29
28
import reactor .core .publisher .Mono ;
30
29
31
30
import org .springframework .context .annotation .AnnotationConfigApplicationContext ;
31
+ import org .springframework .data .domain .OffsetScrollPosition ;
32
+ import org .springframework .data .domain .Window ;
32
33
import org .springframework .graphql .Author ;
33
34
import org .springframework .graphql .Book ;
35
+ import org .springframework .graphql .GraphQlSetup ;
34
36
import org .springframework .graphql .data .method .annotation .Argument ;
35
37
import org .springframework .graphql .data .method .annotation .MutationMapping ;
36
38
import org .springframework .graphql .data .method .annotation .QueryMapping ;
45
47
* Tests for {@link SchemaMappingInspector}.
46
48
*
47
49
* @author Brian Clozel
50
+ * @author Rossen Stoyanchev
48
51
*/
49
52
class SchemaMappingInspectorTests {
50
53
@@ -91,6 +94,23 @@ void inspectTypeForCollections() {
91
94
assertThatReport (report ).hasSize (1 ).missesFields ("Book" , "missing" );
92
95
}
93
96
97
+ @ Test
98
+ void inspectTypeForConnection () {
99
+ String schema = """
100
+ type Query {
101
+ paginatedBooks: BookConnection
102
+ }
103
+
104
+ type Book {
105
+ id: ID
106
+ name: String
107
+ missing: Boolean
108
+ }
109
+ """ ;
110
+ SchemaMappingInspector .Report report = inspectSchema (schema , BookController .class );
111
+ assertThatReport (report ).hasSize (1 ).missesFields ("Book" , "missing" );
112
+ }
113
+
94
114
@ Test
95
115
void inspectExtensionTypesForQueries () {
96
116
String schema = """
@@ -413,6 +433,11 @@ public List<Book> allBooks() {
413
433
return List .of (new Book ());
414
434
}
415
435
436
+ @ QueryMapping
437
+ public Window <Book > paginatedBooks () {
438
+ return Window .from (List .of (new Book ()), OffsetScrollPosition ::of );
439
+ }
440
+
416
441
@ SchemaMapping
417
442
public String fetcher (Book book ) {
418
443
return "custom fetcher" ;
@@ -457,12 +482,20 @@ record TeamMember(String name, Team team) {
457
482
}
458
483
459
484
SchemaMappingInspector .Report inspectSchema (String schemaContent , Class <?>... controllers ) {
460
- GraphQLSchema schema = SchemaGenerator .createdMockedSchema (schemaContent );
461
- RuntimeWiring .Builder builder = createRuntimeWiring (controllers );
462
- return new SchemaMappingInspector ().inspectSchemaMappings (schema , builder .build ());
485
+ RuntimeWiringConfigurer wiringConfigurer = createRuntimeWiring (controllers );
486
+ RuntimeWiring .Builder wiringBuilder = RuntimeWiring .newRuntimeWiring ();
487
+ wiringConfigurer .configure (wiringBuilder );
488
+
489
+ GraphQLSchema schema = GraphQlSetup .schemaContent (schemaContent )
490
+ .runtimeWiring (wiringConfigurer )
491
+ .typeDefinitionConfigurer (new ConnectionTypeDefinitionConfigurer ())
492
+ .toGraphQlSource ()
493
+ .schema ();
494
+
495
+ return new SchemaMappingInspector ().inspectSchemaMappings (schema , wiringBuilder .build ());
463
496
}
464
497
465
- RuntimeWiring . Builder createRuntimeWiring (Class <?>... handlerTypes ) {
498
+ private RuntimeWiringConfigurer createRuntimeWiring (Class <?>... handlerTypes ) {
466
499
AnnotationConfigApplicationContext appContext = new AnnotationConfigApplicationContext ();
467
500
for (Class <?> handlerType : handlerTypes ) {
468
501
appContext .registerBean (handlerType );
@@ -473,9 +506,7 @@ RuntimeWiring.Builder createRuntimeWiring(Class<?>... handlerTypes) {
473
506
configurer .setApplicationContext (appContext );
474
507
configurer .afterPropertiesSet ();
475
508
476
- RuntimeWiring .Builder wiringBuilder = RuntimeWiring .newRuntimeWiring ();
477
- configurer .configure (wiringBuilder );
478
- return wiringBuilder ;
509
+ return configurer ;
479
510
}
480
511
481
512
static SchemaInspectionReportAssert assertThatReport (SchemaMappingInspector .Report actual ) {
0 commit comments