File tree 1 file changed +24
-2
lines changed
1 file changed +24
-2
lines changed Original file line number Diff line number Diff line change @@ -107,6 +107,28 @@ export function validateSDL(
107
107
return errors ;
108
108
}
109
109
110
+ /**
111
+ * Combine multiple errors into a single error, whose message
112
+ * contains the error messages and their line:column on separate lines.
113
+ */
114
+ function combineErrorsWithLocation ( errors : ReadonlyArray < GraphQLError > ) : Error {
115
+ const errorMessageWithLocations = errors
116
+ . map ( ( error ) => {
117
+ if ( ! error . locations ?. length ) {
118
+ return error . message ;
119
+ }
120
+
121
+ const locations =
122
+ error . locations
123
+ . map ( ( { line, column } ) => `${ line } :${ column } ` )
124
+ . join ( ', ' ) ?? '' ;
125
+ return `${ error . message } (${ locations } )` ;
126
+ } )
127
+ . join ( '\n\n' ) ;
128
+
129
+ return new Error ( errorMessageWithLocations ) ;
130
+ }
131
+
110
132
/**
111
133
* Utility function which asserts a SDL document is valid by throwing an error
112
134
* if it is invalid.
@@ -116,7 +138,7 @@ export function validateSDL(
116
138
export function assertValidSDL ( documentAST : DocumentNode ) : void {
117
139
const errors = validateSDL ( documentAST ) ;
118
140
if ( errors . length !== 0 ) {
119
- throw new Error ( errors . map ( ( error ) => error . message ) . join ( '\n\n' ) ) ;
141
+ throw combineErrorsWithLocation ( errors ) ;
120
142
}
121
143
}
122
144
@@ -132,6 +154,6 @@ export function assertValidSDLExtension(
132
154
) : void {
133
155
const errors = validateSDL ( documentAST , schema ) ;
134
156
if ( errors . length !== 0 ) {
135
- throw new Error ( errors . map ( ( error ) => error . message ) . join ( '\n\n' ) ) ;
157
+ throw combineErrorsWithLocation ( errors ) ;
136
158
}
137
159
}
You can’t perform that action at this time.
0 commit comments