@@ -324,6 +324,38 @@ export function getPublishResolver<TSource, TContext, TArgs>({
324
324
}
325
325
}
326
326
327
+ /**
328
+ * Returns values for link arguments, also covers the cases for
329
+ * if the link parameter contains constants that are appended to the link parameter
330
+ *
331
+ * e.g. instead of:
332
+ * $response.body#/employerId
333
+ *
334
+ * it could be:
335
+ * abc_{$response.body#/employerId}
336
+ */
337
+ function inferLinkArguments ( paramName , value , resolveData , source , args ) {
338
+ if ( Object . prototype . toString . call ( value ) === '[object Object]' ) {
339
+ return Object . entries ( value ) . reduce ( ( acc , [ key , value ] ) => {
340
+ acc [ key ] = inferLinkArguments ( paramName , value , resolveData , source , args )
341
+ return acc
342
+ } , { } )
343
+ }
344
+
345
+ if ( value . search ( / { | } / ) === - 1 ) {
346
+ return isRuntimeExpression ( value )
347
+ ? resolveRuntimeExpression ( paramName , value , resolveData , source , args )
348
+ : value
349
+ } else {
350
+ // Replace link parameters with appropriate values
351
+ const linkParams = value . match ( / { ( [ ^ } ] * ) } / g)
352
+ linkParams . forEach ( ( linkParam ) => {
353
+ value = value . replace ( linkParam , resolveRuntimeExpression ( paramName , linkParam . substring ( 1 , linkParam . length - 1 ) , resolveData , source , args ) )
354
+ } )
355
+ return value
356
+ }
357
+ }
358
+
327
359
/**
328
360
* If the operation type is Query or Mutation, create and return a resolver
329
361
* function that performs API requests for the given GraphQL query
@@ -444,43 +476,7 @@ export function getResolver<TSource, TContext, TArgs>({
444
476
445
477
let value = argsFromLink [ paramName ]
446
478
447
- /**
448
- * see if the link parameter contains constants that are appended to the link parameter
449
- *
450
- * e.g. instead of:
451
- * $response.body#/employerId
452
- *
453
- * it could be:
454
- * abc_{$response.body#/employerId}
455
- */
456
- if ( value . search ( / { | } / ) === - 1 ) {
457
- args [ saneParamName ] = isRuntimeExpression ( value )
458
- ? resolveRuntimeExpression (
459
- paramName ,
460
- value ,
461
- resolveData ,
462
- source ,
463
- args
464
- )
465
- : value
466
- } else {
467
- // Replace link parameters with appropriate values
468
- const linkParams = value . match ( / { ( [ ^ } ] * ) } / g)
469
- linkParams . forEach ( ( linkParam ) => {
470
- value = value . replace (
471
- linkParam ,
472
- resolveRuntimeExpression (
473
- paramName ,
474
- linkParam . substring ( 1 , linkParam . length - 1 ) ,
475
- resolveData ,
476
- source ,
477
- args
478
- )
479
- )
480
- } )
481
-
482
- args [ saneParamName ] = value
483
- }
479
+ args [ saneParamName ] = inferLinkArguments ( paramName , value , resolveData , source , args )
484
480
}
485
481
486
482
// Stored used parameters to future requests:
0 commit comments