Skip to content

Commit b099fab

Browse files
committed
add NullValue ast node
- addresses graphql-python#118 - initial implementation by @yen223 in PR graphql-python#119
1 parent b3a6bd0 commit b099fab

File tree

4 files changed

+30
-4
lines changed

4 files changed

+30
-4
lines changed

graphql/language/ast.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -534,6 +534,27 @@ def __hash__(self):
534534
return id(self)
535535

536536

537+
class NullValue(Value):
538+
__slots__ = ('loc', 'value')
539+
_fields = ('value',)
540+
541+
def __init__(self, value=None, loc=None):
542+
self.value = None
543+
self.loc = loc
544+
545+
def __eq__(self, other):
546+
return isinstance(other, NullValue)
547+
548+
def __repr__(self):
549+
return 'NullValue'
550+
551+
def __copy__(self):
552+
return type(self)(self.value, self.loc)
553+
554+
def __hash__(self):
555+
return id(self)
556+
557+
537558
class EnumValue(Value):
538559
__slots__ = ('loc', 'value',)
539560
_fields = ('value',)

graphql/language/parser.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -414,13 +414,14 @@ def parse_value_literal(parser, is_const):
414414
return ast.StringValue(value=token.value, loc=loc(parser, token.start))
415415

416416
elif token.kind == TokenKind.NAME:
417+
advance(parser)
417418
if token.value in ('true', 'false'):
418-
advance(parser)
419419
return ast.BooleanValue(value=token.value == 'true', loc=loc(parser, token.start))
420420

421-
if token.value != 'null':
422-
advance(parser)
423-
return ast.EnumValue(value=token.value, loc=loc(parser, token.start))
421+
if token.value == 'null':
422+
return ast.NullValue(loc=loc(parser, token.start))
423+
424+
return ast.EnumValue(value=token.value, loc=loc(parser, token.start))
424425

425426
elif token.kind == TokenKind.DOLLAR:
426427
if not is_const:

graphql/language/printer.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,9 @@ def leave_StringValue(self, node, *args):
8181
def leave_BooleanValue(self, node, *args):
8282
return json.dumps(node.value)
8383

84+
def leave_NullValue(self, node, *args):
85+
return 'null'
86+
8487
def leave_EnumValue(self, node, *args):
8588
return node.value
8689

graphql/language/visitor_meta.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
ast.FloatValue: (),
2020
ast.StringValue: (),
2121
ast.BooleanValue: (),
22+
ast.NullValue: (),
2223
ast.EnumValue: (),
2324
ast.ListValue: ('values',),
2425
ast.ObjectValue: ('fields',),

0 commit comments

Comments
 (0)