Skip to content

Commit 66f7d38

Browse files
committed
fix issue #109
1 parent e515c21 commit 66f7d38

File tree

1 file changed

+13
-4
lines changed

1 file changed

+13
-4
lines changed

graphql-server/drivers/arangodb/driver.js

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -514,6 +514,8 @@ function stringifyImportedFields(importedFields){
514514
* @param ctxt
515515
*/
516516
function addExportedVariables(isRoot, resVar, info, ctxt){
517+
// check exports only for the root field
518+
if(!isRoot) return;
517519
// find all exported variables and the corresponding selection fields
518520
for(let fieldNode of info.fieldNodes){
519521
for(let selection of fieldNode.selectionSet.selections){
@@ -532,6 +534,9 @@ function addExportedVariables(isRoot, resVar, info, ctxt){
532534
* @param ctxt
533535
*/
534536
function exportSelection(isRoot, resVar, selection, info, ctxt){
537+
// skip inline fragments
538+
if(selection.kind === 'InlineFragment') return;
539+
535540
// skip non-root level, cannot export these fields
536541
if(selection.selectionSet !== undefined) {
537542
for(let s of selection.selectionSet.selections){
@@ -544,7 +549,7 @@ function exportSelection(isRoot, resVar, selection, info, ctxt){
544549
if(directive.name.value !== 'export') continue;
545550
let varName = directive.arguments[0].value.value;
546551
if(!isRoot){
547-
ctxt.trans.code.push(`throw "Cannot export non-root field for variable "$${varName}"`);
552+
ctxt.trans.code.push(`throw "Cannot export non-root field for variable $${varName}";`);
548553
}
549554
for(let argument of directive.arguments) {
550555
// Variable values will be injected instead of variable references. If a value is added to
@@ -581,9 +586,13 @@ function substituteExportedVariables(data, ctxt){
581586
if(typeof value === 'object' && value !== null){
582587
if(value.kind === 'VariableDefinition'){
583588
const varName = value.variable.name.value;
584-
// remove field from data object
585-
delete data[fieldName];
586-
substitutes[fieldName] = ctxt.trans.exportedVariables[varName];
589+
if(ctxt.trans.exportedVariables[varName] === undefined){
590+
ctxt.trans.code.push(`throw "Variable $${varName} has not been exported";`);
591+
} else {
592+
// remove field from data object
593+
delete data[fieldName];
594+
substitutes[fieldName] = ctxt.trans.exportedVariables[varName];
595+
}
587596
}
588597
}
589598
});

0 commit comments

Comments
 (0)