Skip to content

Commit bc7500f

Browse files
dugenkui03bclozel
authored andcommitted
Provide location information for missing/invalid schema resources
This commit ensures that the `Resource` description is provided when a schema resource is missing, cannot be read, or is invalid. This is useful when the application holds multiple schema files and an error is thrown because of a particular file. Close gh-307
1 parent c10aed8 commit bc7500f

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

spring-graphql/src/main/java/org/springframework/graphql/execution/DefaultGraphQlSourceBuilder.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ private void registerDefaultTypeResolver(TypeDefinitionRegistry registry, Runtim
184184

185185
private TypeDefinitionRegistry parseSchemaResource(Resource schemaResource) {
186186
Assert.notNull(schemaResource, "'schemaResource' not provided");
187-
Assert.isTrue(schemaResource.exists(), "'schemaResource' does not exist");
187+
Assert.isTrue(schemaResource.exists(), "'schemaResource' must exist: " + schemaResource);
188188
try {
189189
try (InputStream inputStream = schemaResource.getInputStream()) {
190190
return new SchemaParser().parse(inputStream);
@@ -193,6 +193,9 @@ private TypeDefinitionRegistry parseSchemaResource(Resource schemaResource) {
193193
catch (IOException ex) {
194194
throw new IllegalArgumentException("Failed to load schema resource: " + schemaResource);
195195
}
196+
catch (Exception ex) {
197+
throw new IllegalStateException("Failed to parse schema resource: " + schemaResource, ex);
198+
}
196199
}
197200

198201
private GraphQLSchema applyTypeVisitors(GraphQLSchema schema) {

0 commit comments

Comments
 (0)