Skip to content

Commit bacdab6

Browse files
committed
Revert "Fixed nested variable replacement using recursion."
This reverts commit 6e47f4e.
1 parent 6e47f4e commit bacdab6

File tree

2 files changed

+8
-89
lines changed

2 files changed

+8
-89
lines changed

src/test/templates/JSResolverOCHTTPS.test.js

Lines changed: 0 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -798,46 +798,6 @@ test('should resolve query with nested edge filter and variables', () => {
798798
});
799799
});
800800

801-
test('should resolve query with nested edge filter and nested scalar variables', () => {
802-
const query = 'query GetNodeAirports($filter: AirportInput, $options: Options, $nestedFilter: AirportInput, $nestedOptions: Options) {\n' +
803-
' getNodeAirports(filter: {country: {eq: $country}}, options: {limit: $limit}) {\n' +
804-
' code\n' +
805-
' airportRoutesOut(filter: {country: {eq: $country}}, options: {limit: $limit}) {\n' +
806-
' code\n' +
807-
' }\n' +
808-
' }\n' +
809-
'}';
810-
const variables = {
811-
"country": "CA",
812-
"limit": 6
813-
}
814-
const result = resolveGraphDBQuery({queryObjOrStr: query, variables: variables});
815-
816-
expect(result).toMatchObject({
817-
query: 'MATCH (getNodeAirports_Airport:`airport`) ' +
818-
'WHERE getNodeAirports_Airport.country = $getNodeAirports_Airport_country ' +
819-
'WITH getNodeAirports_Airport LIMIT 6\n' +
820-
'OPTIONAL MATCH (getNodeAirports_Airport)-[getNodeAirports_Airport_airportRoutesOut_route:route]->(getNodeAirports_Airport_airportRoutesOut:`airport`) ' +
821-
'WHERE getNodeAirports_Airport_airportRoutesOut.country = $getNodeAirports_Airport_airportRoutesOut_country\n' +
822-
'WITH getNodeAirports_Airport, ' +
823-
'CASE WHEN getNodeAirports_Airport_airportRoutesOut IS NULL THEN [] ' +
824-
'ELSE COLLECT({' +
825-
'code: getNodeAirports_Airport_airportRoutesOut.`code`' +
826-
'})[..6] ' +
827-
'END AS getNodeAirports_Airport_airportRoutesOut_collect\n' +
828-
'RETURN collect({' +
829-
'code: getNodeAirports_Airport.`code`, ' +
830-
'airportRoutesOut: getNodeAirports_Airport_airportRoutesOut_collect' +
831-
'})[..6]',
832-
parameters: {
833-
getNodeAirports_Airport_country: "CA",
834-
getNodeAirports_Airport_airportRoutesOut_country: "CA"
835-
},
836-
language: 'opencypher',
837-
refactorOutput: null
838-
});
839-
});
840-
841801
test('should resolve custom mutation with @graphQuery directive and $input parameter', () => {
842802
const query = 'mutation MyMutation {\n' +
843803
' createAirport(\n' +

templates/JSResolverOCHTTPS.js

Lines changed: 8 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)