Skip to content

Commit 90e5b9a

Browse files
committed
Implement concat_ast utility
Closes #32.
1 parent dede9a1 commit 90e5b9a

File tree

2 files changed

+37
-0
lines changed

2 files changed

+37
-0
lines changed

graphql/core/utils/concat_ast.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import itertools
2+
3+
from ..language.ast import Document
4+
5+
6+
def concat_ast(asts):
7+
return Document(definitions=list(itertools.chain.from_iterable(
8+
document.definitions for document in asts
9+
)))

tests/core_utils/test_concat_ast.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
from graphql.core import Source, parse
2+
3+
from graphql.core.language.printer import print_ast
4+
from graphql.core.utils.concat_ast import concat_ast
5+
6+
7+
def test_it_concatenates_two_acts_together():
8+
source_a = Source('{ a, b, ... Frag }')
9+
source_b = Source('''
10+
fragment Frag on T {
11+
c
12+
}
13+
''')
14+
15+
ast_a = parse(source_a)
16+
ast_b = parse(source_b)
17+
ast_c = concat_ast([ast_a, ast_b])
18+
19+
assert print_ast(ast_c) == '''{
20+
a
21+
b
22+
...Frag
23+
}
24+
25+
fragment Frag on T {
26+
c
27+
}
28+
'''

0 commit comments

Comments
 (0)