Skip to content
Snippets Groups Projects
Unverified Commit d3bb383c authored by Thiago Bellini Ribeiro's avatar Thiago Bellini Ribeiro Committed by GitHub
Browse files

Fix wrong _get_value for variables (#52)

parent 08e6f596
Branches
Tags
No related merge requests found
......@@ -217,11 +217,11 @@ class QueryOptimizer(object):
if isinstance(value, Variable):
var_name = value.name.value
value = info.variable_values.get(var_name)
if isinstance(value, InputObjectType):
return value
elif isinstance(value, InputObjectType):
return value.__dict__
else:
return GenericScalar.parse_literal(value)
return value
def _optimize_field_by_hints(self, store, selection, field_def, parent_type):
optimization_hints = self._get_optimization_hints(field_def.resolver)
......
......@@ -149,3 +149,24 @@ def test_should_return_valid_result_with_prefetch_related_as_a_function():
''')
assert not result.errors
assert result.data['items'][0]['filteredChildren'][0]['id'] == '2'
@pytest.mark.django_db
def test_should_return_valid_result_with_prefetch_related_as_a_function_using_variable():
parent = Item.objects.create(id=1, name='foo')
Item.objects.create(id=2, name='bar', parent=parent)
Item.objects.create(id=3, name='foobar', parent=parent)
result = schema.execute('''
query Foo ($name: String!) {
items(name: "foo") {
id
foo
filteredChildren(name: $name) {
id
foo
}
}
}
''', variables={'name': 'bar'})
assert not result.errors
assert result.data['items'][0]['filteredChildren'][0]['id'] == '2'
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment