Skip to content

Commit cc76d3d

Browse files
committed
update ast_from_value/value_from_ast utils
- add None ast conversion test
1 parent 5dea9f1 commit cc76d3d

File tree

3 files changed

+8
-1
lines changed

3 files changed

+8
-1
lines changed

graphql/utils/ast_from_value.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ def ast_from_value(value, type=None):
1515
return ast_from_value(value, type.of_type)
1616

1717
if value is None:
18-
return None
18+
return ast.NullValue()
1919

2020
if isinstance(value, list):
2121
item_type = type.of_type if isinstance(type, GraphQLList) else None

graphql/utils/tests/test_ast_from_value.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,10 @@ def test_it_converts_string_values_to_asts():
3737
assert ast_from_value('123') == ast.StringValue('123')
3838

3939

40+
def test_it_converts_null_values_to_asts():
41+
assert ast_from_value(None) == ast.NullValue()
42+
43+
4044
my_enum = GraphQLEnumType(
4145
'MyEnum', {
4246
'HELLO': GraphQLEnumValue(1),

graphql/utils/value_from_ast.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@ def value_from_ast(value_ast, type, variables=None):
1414
if value_ast is None:
1515
return None
1616

17+
if isinstance(value_ast, ast.NullValue):
18+
return None
19+
1720
if isinstance(value_ast, ast.Variable):
1821
variable_name = value_ast.name.value
1922
if not variables or variable_name not in variables:

0 commit comments

Comments
 (0)