This repository was archived by the owner on Dec 19, 2023. It is now read-only.
File tree Expand file tree Collapse file tree 2 files changed +49
-3
lines changed
graphql-kickstart-spring-support/src/main/java/graphql/kickstart/spring/error Expand file tree Collapse file tree 2 files changed +49
-3
lines changed Original file line number Diff line number Diff line change 1+ package graphql .kickstart .spring .error ;
2+
3+ import graphql .ErrorClassification ;
4+ import graphql .language .SourceLocation ;
5+
6+ import java .util .List ;
7+ import java .util .Map ;
8+
9+ public class ErrorContext {
10+ private final List <SourceLocation > locations ;
11+ private final List <Object > path ;
12+ private final Map <String , Object > extensions ;
13+ private final ErrorClassification errorType ;
14+
15+ public ErrorContext (List <SourceLocation > locations ,
16+ List <Object > path ,
17+ Map <String , Object > extensions ,
18+ ErrorClassification errorType ) {
19+ this .locations = locations ;
20+ this .path = path ;
21+ this .extensions = extensions ;
22+ this .errorType = errorType ;
23+ }
24+
25+ public List <SourceLocation > getLocations () {
26+ return locations ;
27+ }
28+
29+ public List <Object > getPath () {
30+ return path ;
31+ }
32+
33+ public Map <String , Object > getExtensions () {
34+ return extensions ;
35+ }
36+
37+ public ErrorClassification getErrorType () {
38+ return errorType ;
39+ }
40+ }
Original file line number Diff line number Diff line change @@ -32,7 +32,13 @@ protected List<GraphQLError> filterGraphQLErrors(List<GraphQLError> errors) {
3232 }
3333
3434 private Collection <GraphQLError > transform (GraphQLError error ) {
35- return extractException (error ).map (this ::transform )
35+ ErrorContext errorContext = new ErrorContext (
36+ error .getLocations (),
37+ error .getPath (),
38+ error .getExtensions (),
39+ error .getErrorType ()
40+ );
41+ return extractException (error ).map (throwable -> transform (throwable , errorContext ))
3642 .orElse (singletonList (new GenericGraphQLError (error .getMessage ())));
3743 }
3844
@@ -47,13 +53,13 @@ private Optional<Throwable> extractException(GraphQLError error) {
4753 return Optional .empty ();
4854 }
4955
50- private Collection <GraphQLError > transform (Throwable throwable ) {
56+ private Collection <GraphQLError > transform (Throwable throwable , ErrorContext errorContext ) {
5157 Map <Class <? extends Throwable >, GraphQLErrorFactory > applicables = new HashMap <>();
5258 factories .forEach (factory -> factory .mostConcrete (throwable ).ifPresent (t -> applicables .put (t , factory )));
5359 return applicables .keySet ().stream ()
5460 .min (new ThrowableComparator ())
5561 .map (applicables ::get )
56- .map (factory -> factory .create (throwable ))
62+ .map (factory -> factory .create (throwable , errorContext ))
5763 .orElse (singletonList (new ThrowableGraphQLError (throwable )));
5864 }
5965
You can’t perform that action at this time.
0 commit comments