Skip to content

Commit 4d60e3f

Browse files
committed
save the details when schema resource is invalid
1 parent 5433e42 commit 4d60e3f

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, 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+
import org.springframework.core.io.Resource;
6+
7+
8+
/**
9+
* Indicates that the Resource in {@link GraphQlSource.Builder} is invalid.
10+
*
11+
* @author GenKui Du
12+
* @since 1.0.0
13+
*/
14+
public class InvalidSchemaResourceException extends GraphQLException {
15+
16+
private final Resource schemaResource;
17+
18+
private final SchemaProblem schemaProblem;
19+
20+
public InvalidSchemaResourceException(Resource schemaResource, SchemaProblem schemaProblem) {
21+
super(
22+
String.format("invalid schema, resource = %s, errors = %s", schemaResource, schemaProblem.getErrors()),
23+
schemaProblem
24+
);
25+
this.schemaResource = schemaResource;
26+
this.schemaProblem = schemaProblem;
27+
}
28+
29+
public Resource getSchemaResource() {
30+
return schemaResource;
31+
}
32+
33+
public SchemaProblem getSchemaProblem() {
34+
return schemaProblem;
35+
}
36+
37+
@Override
38+
public String toString() {
39+
return "InvalidSchemaResourceException{" +
40+
"schemaResource=" + schemaResource +
41+
", schemaProblem=" + schemaProblem +
42+
'}';
43+
}
44+
}

0 commit comments

Comments
 (0)