Scan nested locations for GraphQL schema files

This commit changes the default value for the `spring.graphql.locations`
configuration property to `classpath:/graphql/**/`. By default, this
will scan nested locations for GraphQL schema files.

Fixes gh-210
This commit is contained in:
Brian Clozel
2021-12-06 10:47:22 +01:00
parent 6b1d5ebf64
commit b78808d54d
5 changed files with 20 additions and 6 deletions

View File

@@ -66,7 +66,7 @@ public class GraphQlProperties {
/**
* Locations of GraphQL schema files.
*/
private String[] locations = new String[] { "classpath:graphql/"};
private String[] locations = new String[] { "classpath:graphql/**/"};
/**
* File extensions for GraphQL schema files.

View File

@@ -2,7 +2,7 @@
"properties": [
{
"name": "spring.graphql.schema.locations",
"defaultValue": "classpath:graphql/"
"defaultValue": "classpath:graphql/**/"
},
{
"name": "spring.graphql.schema.file-extensions",

View File

@@ -40,10 +40,11 @@ class GraphQlAutoConfigurationTests {
@Test
void shouldFailWhenSchemaFileIsMissing() {
this.contextRunner.run((context) -> {
assertThat(context).hasFailed();
assertThat(context).getFailure().getRootCause().isInstanceOf(MissingSchemaException.class);
});
this.contextRunner.withPropertyValues("spring.graphql.schema.locations:classpath:missing/")
.run((context) -> {
assertThat(context).hasFailed();
assertThat(context).getFailure().getRootCause().isInstanceOf(MissingSchemaException.class);
});
}
@Test
@@ -52,6 +53,11 @@ class GraphQlAutoConfigurationTests {
.run((context) -> assertThat(context).hasSingleBean(GraphQlSource.class));
}
@Test
void shouldScanNestedLocations() {
this.contextRunner.run((context) -> assertThat(context).hasSingleBean(GraphQlSource.class));
}
@Test
void shouldUseProgrammaticallyDefinedBuilder() {
this.contextRunner.withPropertyValues("spring.graphql.schema.locations:classpath:books/")

View File

@@ -0,0 +1,3 @@
type Query {
bookById(id: ID): Book
}

View File

@@ -0,0 +1,5 @@
type Book {
id: ID
name: String
pageCount: Int
}