|
@@ -20,11 +20,13 @@ local visitors = {
|
|
operation = {
|
|
operation = {
|
|
enter = function(node, context)
|
|
enter = function(node, context)
|
|
table.insert(context.objects, context.schema.query)
|
|
table.insert(context.objects, context.schema.query)
|
|
|
|
+ context.currentOperation = node
|
|
context.variableReferences = {}
|
|
context.variableReferences = {}
|
|
end,
|
|
end,
|
|
|
|
|
|
exit = function(node, context)
|
|
exit = function(node, context)
|
|
table.remove(context.objects)
|
|
table.remove(context.objects)
|
|
|
|
+ context.currentOperation = nil
|
|
context.variableReferences = nil
|
|
context.variableReferences = nil
|
|
end,
|
|
end,
|
|
|
|
|
|
@@ -39,7 +41,8 @@ local visitors = {
|
|
rules.variablesHaveCorrectType,
|
|
rules.variablesHaveCorrectType,
|
|
rules.variableDefaultValuesHaveCorrectType,
|
|
rules.variableDefaultValuesHaveCorrectType,
|
|
exit = {
|
|
exit = {
|
|
- rules.variablesAreUsed
|
|
|
|
|
|
+ rules.variablesAreUsed,
|
|
|
|
+ rules.variablesAreDefined
|
|
}
|
|
}
|
|
}
|
|
}
|
|
},
|
|
},
|
|
@@ -75,6 +78,12 @@ local visitors = {
|
|
end
|
|
end
|
|
end
|
|
end
|
|
|
|
|
|
|
|
+ if node.directives then
|
|
|
|
+ for i = 1, #node.directives do
|
|
|
|
+ table.insert(children, node.directives[i])
|
|
|
|
+ end
|
|
|
|
+ end
|
|
|
|
+
|
|
if node.selectionSet then
|
|
if node.selectionSet then
|
|
table.insert(children, node.selectionSet)
|
|
table.insert(children, node.selectionSet)
|
|
end
|
|
end
|
|
@@ -131,7 +140,7 @@ local visitors = {
|
|
|
|
|
|
table.insert(context.objects, fragmentType)
|
|
table.insert(context.objects, fragmentType)
|
|
|
|
|
|
- if context.variableReferences then
|
|
|
|
|
|
+ if context.currentOperation then
|
|
local function collectTransitiveVariables(node)
|
|
local function collectTransitiveVariables(node)
|
|
if not node then return end
|
|
if not node then return end
|
|
|
|
|
|
@@ -179,7 +188,13 @@ local visitors = {
|
|
end,
|
|
end,
|
|
|
|
|
|
children = function(node)
|
|
children = function(node)
|
|
- return { node.selectionSet }
|
|
|
|
|
|
+ local children = {}
|
|
|
|
+
|
|
|
|
+ for _, selection in ipairs(node.selectionSet) do
|
|
|
|
+ table.insert(children, selection)
|
|
|
|
+ end
|
|
|
|
+
|
|
|
|
+ return children
|
|
end,
|
|
end,
|
|
|
|
|
|
rules = {
|
|
rules = {
|
|
@@ -191,19 +206,25 @@ local visitors = {
|
|
|
|
|
|
argument = {
|
|
argument = {
|
|
enter = function(node, context)
|
|
enter = function(node, context)
|
|
- if context.variableReferences then
|
|
|
|
|
|
+ if context.currentOperation then
|
|
local value = node.value
|
|
local value = node.value
|
|
while value.kind == 'listType' or value.kind == 'nonNullType' do
|
|
while value.kind == 'listType' or value.kind == 'nonNullType' do
|
|
value = value.type
|
|
value = value.type
|
|
end
|
|
end
|
|
|
|
|
|
if value.kind == 'variable' then
|
|
if value.kind == 'variable' then
|
|
- context.variablesUsed[value.name.value] = true
|
|
|
|
|
|
+ context.variableReferences[value.name.value] = true
|
|
end
|
|
end
|
|
end
|
|
end
|
|
end,
|
|
end,
|
|
|
|
|
|
rules = { rules.uniqueInputObjectFields }
|
|
rules = { rules.uniqueInputObjectFields }
|
|
|
|
+ },
|
|
|
|
+
|
|
|
|
+ directive = {
|
|
|
|
+ children = function(node, context)
|
|
|
|
+ return node.arguments
|
|
|
|
+ end
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
@@ -215,6 +236,7 @@ return function(schema, tree)
|
|
hasAnonymousOperation = false,
|
|
hasAnonymousOperation = false,
|
|
usedFragments = {},
|
|
usedFragments = {},
|
|
objects = {},
|
|
objects = {},
|
|
|
|
+ currentOperation = nil,
|
|
variableReferences = nil
|
|
variableReferences = nil
|
|
}
|
|
}
|
|
|
|
|