diff --git a/graphql/language/ast.py b/graphql/language/ast.py index 6fffae84..db2a0321 100644 --- a/graphql/language/ast.py +++ b/graphql/language/ast.py @@ -534,6 +534,27 @@ def __hash__(self): return id(self) +class NullValue(Value): + __slots__ = ('loc', 'value') + _fields = ('value',) + + def __init__(self, value=None, loc=None): + self.value = None + self.loc = loc + + def __eq__(self, other): + return isinstance(other, NullValue) + + def __repr__(self): + return 'NullValue' + + def __copy__(self): + return type(self)(self.value, self.loc) + + def __hash__(self): + return id(self) + + class EnumValue(Value): __slots__ = ('loc', 'value',) _fields = ('value',) diff --git a/graphql/language/parser.py b/graphql/language/parser.py index 21adac91..3a8a3f26 100644 --- a/graphql/language/parser.py +++ b/graphql/language/parser.py @@ -414,13 +414,14 @@ def parse_value_literal(parser, is_const): return ast.StringValue(value=token.value, loc=loc(parser, token.start)) elif token.kind == TokenKind.NAME: + advance(parser) if token.value in ('true', 'false'): - advance(parser) return ast.BooleanValue(value=token.value == 'true', loc=loc(parser, token.start)) - if token.value != 'null': - advance(parser) - return ast.EnumValue(value=token.value, loc=loc(parser, token.start)) + if token.value == 'null': + return ast.NullValue(loc=loc(parser, token.start)) + + return ast.EnumValue(value=token.value, loc=loc(parser, token.start)) elif token.kind == TokenKind.DOLLAR: if not is_const: diff --git a/graphql/language/printer.py b/graphql/language/printer.py index 638d9b3a..d8f9c2c9 100644 --- a/graphql/language/printer.py +++ b/graphql/language/printer.py @@ -81,6 +81,9 @@ def leave_StringValue(self, node, *args): def leave_BooleanValue(self, node, *args): return json.dumps(node.value) + def leave_NullValue(self, node, *args): + return 'null' + def leave_EnumValue(self, node, *args): return node.value diff --git a/graphql/language/visitor_meta.py b/graphql/language/visitor_meta.py index db2e6409..a3631de7 100644 --- a/graphql/language/visitor_meta.py +++ b/graphql/language/visitor_meta.py @@ -19,6 +19,7 @@ ast.FloatValue: (), ast.StringValue: (), ast.BooleanValue: (), + ast.NullValue: (), ast.EnumValue: (), ast.ListValue: ('values',), ast.ObjectValue: ('fields',),