Skip to content

Commit ecd3b98

Browse files
committed
fix issues with nested variables and visitors
bump 0.0.15
1 parent 260701b commit ecd3b98

File tree

4 files changed

+27
-5
lines changed

4 files changed

+27
-5
lines changed

Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "graphql-tools"
3-
version = "0.0.14"
3+
version = "0.0.15"
44
edition = "2021"
55
description = "Tools for working with GraphQL in Rust, based on graphql-parser Document."
66
license = "MIT/Apache-2.0"

src/ast/query_visitor.rs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ pub trait QueryVisitor<T = DefaultVisitorContext> {
132132

133133
for (name, argument) in &field.arguments {
134134
self.enter_field_argument(name, argument, field, visitor_context);
135-
self.__visit_value(argument, visitor_context);
135+
self.__visit_value(name, argument, visitor_context);
136136

137137
match argument {
138138
Value::Variable(variable) => {
@@ -175,13 +175,18 @@ pub trait QueryVisitor<T = DefaultVisitorContext> {
175175
self.leave_selection_set(_node, visitor_context);
176176
}
177177

178-
fn __visit_value(&self, node: &Value, visitor_context: &mut T) {
178+
fn __visit_value(&self, arg_name: &String, node: &Value, visitor_context: &mut T) {
179179
self.enter_value(node, visitor_context);
180180

181181
if let Value::Object(tree_map) = node {
182182
tree_map
183183
.iter()
184-
.for_each(|(_key, sub_value)| self.__visit_value(sub_value, visitor_context))
184+
.for_each(|(key, sub_value)| self.__visit_value(key, sub_value, visitor_context))
185+
}
186+
187+
if let Value::Variable(var_name) = node {
188+
self.enter_variable(var_name, (arg_name, node), visitor_context);
189+
self.leave_variable(var_name, (arg_name, node), visitor_context);
185190
}
186191

187192
self.leave_value(node, visitor_context);

src/validation/rules/no_unused_variables.rs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -364,3 +364,20 @@ fn should_also_check_directives_usage() {
364364
let messages = get_messages(&errors);
365365
assert_eq!(messages.len(), 0);
366366
}
367+
368+
#[test]
369+
fn nested_variable_should_work_as_well() {
370+
use crate::validation::test_utils::*;
371+
372+
let mut plan = create_plan_from_rule(Box::new(NoUnusedVariables {}));
373+
let errors = test_operation_without_schema(
374+
"query foo($t: Boolean!) {
375+
field(boop: { test: $t})
376+
}
377+
",
378+
&mut plan,
379+
);
380+
381+
let messages = get_messages(&errors);
382+
assert_eq!(messages.len(), 0);
383+
}

0 commit comments

Comments
 (0)