Skip to content

Commit 555289d

Browse files
committed
provide details when schema resource is invalid
1 parent 5433e42 commit 555289d

File tree

2 files changed

+48
-0
lines changed

2 files changed

+48
-0
lines changed

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@
4646
import graphql.schema.idl.TypeDefinitionRegistry;
4747
import graphql.schema.idl.WiringFactory;
4848

49+
import graphql.schema.idl.errors.SchemaProblem;
4950
import org.springframework.core.io.Resource;
5051
import org.springframework.lang.Nullable;
5152
import org.springframework.util.Assert;
@@ -193,6 +194,9 @@ private TypeDefinitionRegistry parseSchemaResource(Resource schemaResource) {
193194
catch (IOException ex) {
194195
throw new IllegalArgumentException("Failed to load schema resource: " + schemaResource);
195196
}
197+
catch (SchemaProblem ex) {
198+
throw new InvalidSchemaResourceException(schemaResource.getDescription(), ex);
199+
}
196200
}
197201

198202
private GraphQLSchema applyTypeVisitors(GraphQLSchema schema) {
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
package org.springframework.graphql.execution;
2+
3+
import graphql.GraphQLException;
4+
import graphql.schema.idl.errors.SchemaProblem;
5+
6+
7+
/**
8+
* Indicates that the Resource in {@link GraphQlSource.Builder} is invalid.
9+
*
10+
* @author GenKui Du
11+
* @since 1.0.0
12+
*/
13+
public class InvalidSchemaResourceException extends GraphQLException {
14+
15+
private final String resourceDescription;
16+
17+
private final SchemaProblem schemaProblem;
18+
19+
public InvalidSchemaResourceException(String resourceDescription, SchemaProblem schemaProblem) {
20+
super(
21+
String.format("invalid schema, resource = %s, errors = %s", resourceDescription, schemaProblem.getErrors()),
22+
schemaProblem
23+
);
24+
this.resourceDescription = resourceDescription;
25+
this.schemaProblem = schemaProblem;
26+
}
27+
28+
public String getResourceDescription() {
29+
return resourceDescription;
30+
}
31+
32+
public SchemaProblem getSchemaProblem() {
33+
return schemaProblem;
34+
}
35+
36+
@Override
37+
public String toString() {
38+
return "InvalidSchemaResourceException{" +
39+
"resourceDescription='" + resourceDescription + '\'' +
40+
", schemaProblem=" + schemaProblem +
41+
'}';
42+
}
43+
44+
}

0 commit comments

Comments
 (0)