Skip to content

Commit e9a4f46

Browse files
committed
Parser: use "any_nodes" util fn to parse object literal
Replicates graphql/graphql-js@d98f40c
1 parent 51a791d commit e9a4f46

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

graphql/language/parser.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
from typing import Callable, List, Optional, Union, cast, Dict
2+
from functools import partial
23

34
from .ast import (
45
ArgumentNode,
@@ -445,12 +446,11 @@ def parse_object_field(lexer: Lexer, is_const: bool) -> ObjectFieldNode:
445446
def parse_object(lexer: Lexer, is_const: bool) -> ObjectValueNode:
446447
"""ObjectValue[Const]"""
447448
start = lexer.token
448-
expect_token(lexer, TokenKind.BRACE_L)
449-
fields: List[ObjectFieldNode] = []
450-
append = fields.append
451-
while not expect_optional_token(lexer, TokenKind.BRACE_R):
452-
append(parse_object_field(lexer, is_const))
453-
return ObjectValueNode(fields=fields, loc=loc(lexer, start))
449+
item = cast(Callable[[Lexer], Node], partial(parse_object_field, is_const=is_const))
450+
return ObjectValueNode(
451+
fields=any_nodes(lexer, TokenKind.BRACE_L, item, TokenKind.BRACE_R),
452+
loc=loc(lexer, start),
453+
)
454454

455455

456456
def parse_int(lexer: Lexer, _is_const=True) -> IntValueNode:

0 commit comments

Comments
 (0)