@@ -32,24 +32,21 @@ const EXTERNAL_COMPOSITION_RESULT = z.union([
32
32
supergraph : z . string ( ) ,
33
33
sdl : z . string ( ) ,
34
34
} ) ,
35
- includesNetworkError : z . boolean ( ) . optional ( ) . default ( false ) ,
35
+ includesNetworkError : z . boolean ( ) . default ( false ) ,
36
36
} ) ,
37
37
z . object ( {
38
38
type : z . literal ( 'failure' ) ,
39
39
result : z . object ( {
40
- supergraph : z . string ( ) . optional ( ) ,
41
- sdl : z . string ( ) . optional ( ) ,
40
+ supergraph : z . string ( ) . nullish ( ) ,
41
+ sdl : z . string ( ) . nullish ( ) ,
42
42
errors : z . array (
43
43
z . object ( {
44
44
message : z . string ( ) ,
45
- source : z
46
- . union ( [ z . literal ( 'composition' ) , z . literal ( 'graphql' ) ] )
47
- . optional ( )
48
- . transform ( value => value ?? 'graphql' ) ,
45
+ source : z . union ( [ z . literal ( 'composition' ) , z . literal ( 'graphql' ) ] ) . default ( 'graphql' ) ,
49
46
} ) ,
50
47
) ,
51
48
} ) ,
52
- includesNetworkError : z . boolean ( ) . optional ( ) . default ( false ) ,
49
+ includesNetworkError : z . boolean ( ) . default ( false ) ,
53
50
} ) ,
54
51
] ) ;
55
52
@@ -198,8 +195,20 @@ export async function composeExternalFederation(args: {
198
195
199
196
if ( ! parseResult . success ) {
200
197
args . logger . error ( 'External composition failure: invalid shape of data: %o' , parseResult . error ) ;
201
-
202
- throw new Error ( `External composition failure: invalid shape of data` ) ;
198
+ return {
199
+ type : 'failure' ,
200
+ result : {
201
+ supergraph : null ,
202
+ sdl : null ,
203
+ errors : [
204
+ {
205
+ message : 'External composition failure: invalid shape of data' ,
206
+ source : 'composition' ,
207
+ } ,
208
+ ] ,
209
+ } ,
210
+ includesNetworkError : false ,
211
+ } ;
203
212
}
204
213
205
214
if ( parseResult . data . type === 'success' ) {
@@ -314,6 +323,10 @@ async function callExternalService(
314
323
} ,
315
324
timeout : {
316
325
request : timeoutMs ,
326
+ // connecting should be quick
327
+ lookup : 10_000 ,
328
+ connect : 10_000 ,
329
+ secureConnect : 10_000 ,
317
330
} ,
318
331
} ) ;
319
332
@@ -329,7 +342,7 @@ async function callExternalService(
329
342
span . setAttribute ( 'error.type' , error . name ) ;
330
343
331
344
logger . error (
332
- 'Network error without response. (errorName=%s, errorMessage=%s)' ,
345
+ 'Network error during external composition without response. (errorName=%s, errorMessage=%s)' ,
333
346
error . name ,
334
347
error . message ,
335
348
) ;
@@ -341,7 +354,7 @@ async function callExternalService(
341
354
supergraph : null ,
342
355
errors : [
343
356
{
344
- message : `External composition network failure. Is the service reachable? ` ,
357
+ message : `A network error occurred during external composition: " ${ error . message } " ` ,
345
358
source : 'graphql' ,
346
359
} ,
347
360
] ,
0 commit comments