diff --git a/graphql-spring-boot-starter/src/main/java/org/springframework/graphql/boot/GraphQlAutoConfiguration.java b/graphql-spring-boot-starter/src/main/java/org/springframework/graphql/boot/GraphQlAutoConfiguration.java index bb250cb1..1d61f141 100644 --- a/graphql-spring-boot-starter/src/main/java/org/springframework/graphql/boot/GraphQlAutoConfiguration.java +++ b/graphql-spring-boot-starter/src/main/java/org/springframework/graphql/boot/GraphQlAutoConfiguration.java @@ -60,7 +60,7 @@ public class GraphQlAutoConfiguration { @ConditionalOnMissingBean(GraphQlSource.Builder.class) public static class GraphQlSourceConfiguration { - private static final String SCHEMA_FILES_PATTERN = "*.graphqls"; + private static final String[] SCHEMA_FILES_EXTENSIONS = new String[] {"*.graphqls", "*.graphql", "*.gql", "*.gqls"}; @Bean @ConditionalOnMissingBean @@ -85,7 +85,9 @@ public class GraphQlAutoConfiguration { private List resolveSchemaResources(ResourcePatternResolver resolver, List schemaLocations) throws IOException { List schemaResources = new ArrayList<>(); for (String location : schemaLocations) { - schemaResources.addAll(Arrays.asList(resolver.getResources(location + SCHEMA_FILES_PATTERN))); + for (String extension : SCHEMA_FILES_EXTENSIONS) { + schemaResources.addAll(Arrays.asList(resolver.getResources(location + extension))); + } } return schemaResources; } diff --git a/graphql-spring-boot-starter/src/test/java/org/springframework/graphql/boot/GraphQlAutoConfigurationTests.java b/graphql-spring-boot-starter/src/test/java/org/springframework/graphql/boot/GraphQlAutoConfigurationTests.java index 0678485e..90ef180f 100644 --- a/graphql-spring-boot-starter/src/test/java/org/springframework/graphql/boot/GraphQlAutoConfigurationTests.java +++ b/graphql-spring-boot-starter/src/test/java/org/springframework/graphql/boot/GraphQlAutoConfigurationTests.java @@ -16,6 +16,7 @@ package org.springframework.graphql.boot; +import graphql.schema.GraphQLSchema; import org.junit.jupiter.api.Test; import org.springframework.boot.autoconfigure.AutoConfigurations; @@ -58,6 +59,19 @@ class GraphQlAutoConfigurationTests { }); } + @Test + void shouldScanLocationsForSchemaFiles() { + this.contextRunner.withPropertyValues("spring.graphql.schema.locations:classpath:schema/") + .run((context) -> { + assertThat(context).hasSingleBean(GraphQlSource.class); + GraphQlSource graphQlSource = context.getBean(GraphQlSource.class); + GraphQLSchema schema = graphQlSource.schema(); + assertThat(schema.getObjectType("Movie")).isNotNull(); + assertThat(schema.getObjectType("Book")).isNotNull(); + assertThat(schema.getObjectType("Store")).isNotNull(); + }); + } + @Configuration(proxyBeanMethods = false) static class CustomGraphQlBuilderConfiguration { diff --git a/graphql-spring-boot-starter/src/test/resources/schema/books.graphqls b/graphql-spring-boot-starter/src/test/resources/schema/books.graphqls new file mode 100644 index 00000000..dfa25bc5 --- /dev/null +++ b/graphql-spring-boot-starter/src/test/resources/schema/books.graphqls @@ -0,0 +1,11 @@ +type Book { + id: ID + name: String + pageCount: Int + author: Author +} + +type Author { + id: ID + name: String +} \ No newline at end of file diff --git a/graphql-spring-boot-starter/src/test/resources/schema/movies.gqls b/graphql-spring-boot-starter/src/test/resources/schema/movies.gqls new file mode 100644 index 00000000..5e5a2e04 --- /dev/null +++ b/graphql-spring-boot-starter/src/test/resources/schema/movies.gqls @@ -0,0 +1,10 @@ +type Movie { + id: ID + title: String + director: Director +} + +type Director { + id: ID + name: String +} \ No newline at end of file diff --git a/graphql-spring-boot-starter/src/test/resources/schema/queries.gql b/graphql-spring-boot-starter/src/test/resources/schema/queries.gql new file mode 100644 index 00000000..de032e95 --- /dev/null +++ b/graphql-spring-boot-starter/src/test/resources/schema/queries.gql @@ -0,0 +1,5 @@ +type Query { + bookById(id: ID): Book + movieById(id: ID): Movie + storeById(id: ID): Store +} \ No newline at end of file diff --git a/graphql-spring-boot-starter/src/test/resources/schema/stores.graphql b/graphql-spring-boot-starter/src/test/resources/schema/stores.graphql new file mode 100644 index 00000000..daa27964 --- /dev/null +++ b/graphql-spring-boot-starter/src/test/resources/schema/stores.graphql @@ -0,0 +1,10 @@ +type Store { + id: ID + location: Location +} + +type Location { + address: String + city: String + country: String +} \ No newline at end of file diff --git a/spring-graphql-docs/src/docs/asciidoc/index.adoc b/spring-graphql-docs/src/docs/asciidoc/index.adoc index 77588be1..7ef3a9ae 100644 --- a/spring-graphql-docs/src/docs/asciidoc/index.adoc +++ b/spring-graphql-docs/src/docs/asciidoc/index.adoc @@ -129,7 +129,8 @@ The Spring GraphQL project offers a few configuration properties to customize yo ---- # web path to the graphql endpoint spring.graphql.path=/graphql -# locations of the graphql '*.graphqls' schema files +# locations of the graphql schema files +# scanning for files with well-known extensions: '*.graphqls', '*.gqls', '*.graphql', '*.gql' spring.graphql.schema.locations=classpath:graphql/ # schema printer endpoint configuration # endpoint path is concatenated with the main path, so "/graphql/schema" by default