@@ -917,59 +917,18 @@ function convertToValueNode(value) {
917917
918918/**
919919 * Replaces any variable references in the selection with the actual value from the variables object.
920- * @param { object } selection the graphQL selection to replace variable references in
921- * @param { object } variables the variables object
920+ * @param selection the graphQL selection to replace variable references in
921+ * @param variables the variables object
922922 */
923- function replaceVariableArgsWithValues ( selection , variables = { } ) {
924- if ( ! selection ?. arguments || ! variables ) {
925- return ;
926- }
927-
928- selection . arguments . forEach ( arg => {
929- if ( ! arg . value ) {
930- return ;
931- }
932- replaceVariableInValue ( arg . value , variables ) ;
923+ function replaceVariableArgsWithValues ( selection , variables ) {
924+ selection . arguments ?. filter ( arg => arg . value ?. kind === 'Variable'
925+ && arg . value ?. name ?. value && variables . hasOwnProperty ( arg . value . name . value ) )
926+ . forEach ( arg => {
927+ // replace variable reference with actual value
928+ arg . value = convertToValueNode ( variables [ arg . value . name . value ] ) ;
933929 } ) ;
934930}
935931
936- /**
937- * Recursively replaces any variable references in a value node with the variable value
938- * @param {Object } valueNode - The value node to process
939- * @param {Object } variables - The variables object containing values to substitute
940- */
941- function replaceVariableInValue ( valueNode , variables = { } ) {
942- if ( ! valueNode || ! variables ) {
943- return ;
944- }
945-
946- if ( valueNode . kind === 'Variable' &&
947- valueNode . name ?. value &&
948- variables . hasOwnProperty ( valueNode . name . value ) ) {
949- // replace the variable with actual value
950- Object . assign ( valueNode , convertToValueNode ( variables [ valueNode . name . value ] ) ) ;
951- return ;
952- }
953-
954- if ( valueNode . kind === 'ObjectValue' && valueNode . fields ) {
955- // replace any variables in the object value fields
956- valueNode . fields . forEach ( field => {
957- if ( field . value ) {
958- replaceVariableInValue ( field . value , variables ) ;
959- }
960- } ) ;
961- return ;
962- }
963-
964- if ( valueNode . kind === 'ListValue' && valueNode . values ) {
965- // replace any variables in the list values
966- valueNode . values . forEach ( value => {
967- replaceVariableInValue ( value , variables ) ;
968- } ) ;
969- return ;
970- }
971- }
972-
973932/**
974933 * Replaces any fragment references in the selection with the actual fragment selections.
975934 * @param selection the graphQL selection to replace fragment references in
0 commit comments