Skip to content

Commit 5dea9f1

Browse files
committed
update null tests
- add tests from the ref implementation https://github.com/graphql/graphql-js/pull/544/files
1 parent 5b4ee87 commit 5dea9f1

File tree

1 file changed

+63
-0
lines changed

1 file changed

+63
-0
lines changed

graphql/language/tests/test_parser.py

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,69 @@ def test_allows_null_value():
9494
parse('{ fieldWithNullableStringInput(input: null) }')
9595

9696

97+
def test_parses_null_value_to_null():
98+
result = parse('{ fieldWithObjectInput(input: {a: null, b: null, c: "C", d: null}) }')
99+
values = result.definitions[0].selection_set.selections[0].arguments[0].value.fields
100+
expected = (
101+
(u'a', ast.NullValue()),
102+
(u'b', ast.NullValue()),
103+
(u'c', ast.StringValue(value=u'C')),
104+
(u'd', ast.NullValue()),
105+
)
106+
for name_value, actual in zip(expected, values):
107+
assert name_value == (actual.name.value, actual.value)
108+
109+
110+
def test_parses_null_value_in_list():
111+
result = parse('{ fieldWithObjectInput(input: {b: ["A", null, "C"], c: "C"}) }')
112+
assert result == ast.Document(
113+
definitions=[
114+
ast.OperationDefinition(
115+
operation='query', name=None, variable_definitions=None, directives=[],
116+
selection_set=ast.SelectionSet(
117+
selections=[
118+
ast.Field(
119+
alias=None,
120+
name=ast.Name(value=u'fieldWithObjectInput'),
121+
directives=[],
122+
selection_set=None,
123+
arguments=[
124+
ast.Argument(
125+
name=ast.Name(value=u'input'),
126+
value=ast.ObjectValue(
127+
fields=[
128+
ast.ObjectField(
129+
name=ast.Name(value=u'b'),
130+
value=ast.ListValue(
131+
values=[
132+
ast.StringValue(value=u'A'),
133+
ast.NullValue(),
134+
ast.StringValue(value=u'C'),
135+
],
136+
),
137+
),
138+
ast.ObjectField(
139+
name=ast.Name(value=u'c'),
140+
value=ast.StringValue(value=u'C'),
141+
),
142+
]
143+
),
144+
),
145+
],
146+
),
147+
],
148+
),
149+
),
150+
],
151+
)
152+
153+
154+
def test_null_as_name():
155+
result = parse('{ thingy(null: "stringcheese") }')
156+
assert result.definitions[0].selection_set.selections[0].name.value == 'thingy'
157+
assert result.definitions[0].selection_set.selections[0].arguments[0].name.value == 'null'
158+
159+
97160
def test_parses_multi_byte_characters():
98161
result = parse(u'''
99162
# This comment has a \u0A0A multi-byte character.

0 commit comments

Comments
 (0)