File tree 3 files changed +43
-3
lines changed
3 files changed +43
-3
lines changed Original file line number Diff line number Diff line change
1
+ ---
2
+ " @apollo/client " : patch
3
+ ---
4
+
5
+ Fix graphQLErrors in Error Link if networkError.result is an empty string
Original file line number Diff line number Diff line change @@ -145,6 +145,40 @@ describe("error handling", () => {
145
145
} ) ;
146
146
}
147
147
) ;
148
+ itAsync (
149
+ "sets graphQLErrors to undefined if networkError.result is an empty string" ,
150
+ ( resolve , reject ) => {
151
+ const query = gql `
152
+ query Foo {
153
+ foo {
154
+ bar
155
+ }
156
+ }
157
+ ` ;
158
+
159
+ let called : boolean ;
160
+ const errorLink = onError ( ( { graphQLErrors } ) => {
161
+ expect ( graphQLErrors ) . toBeUndefined ( ) ;
162
+ called = true ;
163
+ } ) ;
164
+
165
+ const mockLink = new ApolloLink ( ( operation ) => {
166
+ return new Observable ( ( obs ) => {
167
+ const response = { status : 500 , ok : false } as Response ;
168
+ throwServerError ( response , "" , "app is crashing" ) ;
169
+ } ) ;
170
+ } ) ;
171
+
172
+ const link = errorLink . concat ( mockLink ) ;
173
+
174
+ execute ( link , { query } ) . subscribe ( {
175
+ error : ( e ) => {
176
+ expect ( called ) . toBe ( true ) ;
177
+ resolve ( ) ;
178
+ } ,
179
+ } ) ;
180
+ }
181
+ ) ;
148
182
itAsync ( "completes if no errors" , ( resolve , reject ) => {
149
183
const query = gql `
150
184
{
Original file line number Diff line number Diff line change @@ -60,9 +60,10 @@ export function onError(errorHandler: ErrorHandler): ApolloLink {
60
60
networkError,
61
61
//Network errors can return GraphQL errors on for example a 403
62
62
graphQLErrors :
63
- networkError &&
64
- networkError . result &&
65
- networkError . result . errors ,
63
+ ( networkError &&
64
+ networkError . result &&
65
+ networkError . result . errors ) ||
66
+ void 0 ,
66
67
forward,
67
68
} ) ;
68
69
if ( retriedResult ) {
You can’t perform that action at this time.
0 commit comments