2222
2323import graphql .schema .GraphQLSchema ;
2424import graphql .schema .idl .RuntimeWiring ;
25- import graphql .schema .idl .SchemaGenerator ;
2625import org .assertj .core .api .AbstractAssert ;
2726import org .junit .jupiter .api .Nested ;
2827import org .junit .jupiter .api .Test ;
2928import reactor .core .publisher .Mono ;
3029
3130import org .springframework .context .annotation .AnnotationConfigApplicationContext ;
31+ import org .springframework .data .domain .OffsetScrollPosition ;
32+ import org .springframework .data .domain .Window ;
3233import org .springframework .graphql .Author ;
3334import org .springframework .graphql .Book ;
35+ import org .springframework .graphql .GraphQlSetup ;
3436import org .springframework .graphql .data .method .annotation .Argument ;
3537import org .springframework .graphql .data .method .annotation .MutationMapping ;
3638import org .springframework .graphql .data .method .annotation .QueryMapping ;
4547 * Tests for {@link SchemaMappingInspector}.
4648 *
4749 * @author Brian Clozel
50+ * @author Rossen Stoyanchev
4851 */
4952class SchemaMappingInspectorTests {
5053
@@ -91,6 +94,23 @@ void inspectTypeForCollections() {
9194 assertThatReport (report ).hasSize (1 ).missesFields ("Book" , "missing" );
9295 }
9396
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+
94114 @ Test
95115 void inspectExtensionTypesForQueries () {
96116 String schema = """
@@ -413,6 +433,11 @@ public List<Book> allBooks() {
413433 return List .of (new Book ());
414434 }
415435
436+ @ QueryMapping
437+ public Window <Book > paginatedBooks () {
438+ return Window .from (List .of (new Book ()), OffsetScrollPosition ::of );
439+ }
440+
416441 @ SchemaMapping
417442 public String fetcher (Book book ) {
418443 return "custom fetcher" ;
@@ -457,12 +482,20 @@ record TeamMember(String name, Team team) {
457482 }
458483
459484 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 ());
463496 }
464497
465- RuntimeWiring . Builder createRuntimeWiring (Class <?>... handlerTypes ) {
498+ private RuntimeWiringConfigurer createRuntimeWiring (Class <?>... handlerTypes ) {
466499 AnnotationConfigApplicationContext appContext = new AnnotationConfigApplicationContext ();
467500 for (Class <?> handlerType : handlerTypes ) {
468501 appContext .registerBean (handlerType );
@@ -473,9 +506,7 @@ RuntimeWiring.Builder createRuntimeWiring(Class<?>... handlerTypes) {
473506 configurer .setApplicationContext (appContext );
474507 configurer .afterPropertiesSet ();
475508
476- RuntimeWiring .Builder wiringBuilder = RuntimeWiring .newRuntimeWiring ();
477- configurer .configure (wiringBuilder );
478- return wiringBuilder ;
509+ return configurer ;
479510 }
480511
481512 static SchemaInspectionReportAssert assertThatReport (SchemaMappingInspector .Report actual ) {
0 commit comments