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
This commit is contained in:
dugenkui03
2022-02-24 01:58:45 +08:00
committed by Brian Clozel
parent c10aed82a3
commit bc7500f33a

View File

@@ -184,7 +184,7 @@ class DefaultGraphQlSourceBuilder implements GraphQlSource.Builder {
private TypeDefinitionRegistry parseSchemaResource(Resource schemaResource) {
Assert.notNull(schemaResource, "'schemaResource' not provided");
Assert.isTrue(schemaResource.exists(), "'schemaResource' does not exist");
Assert.isTrue(schemaResource.exists(), "'schemaResource' must exist: " + schemaResource);
try {
try (InputStream inputStream = schemaResource.getInputStream()) {
return new SchemaParser().parse(inputStream);
@@ -193,6 +193,9 @@ class DefaultGraphQlSourceBuilder implements GraphQlSource.Builder {
catch (IOException ex) {
throw new IllegalArgumentException("Failed to load schema resource: " + schemaResource);
}
catch (Exception ex) {
throw new IllegalStateException("Failed to parse schema resource: " + schemaResource, ex);
}
}
private GraphQLSchema applyTypeVisitors(GraphQLSchema schema) {