File tree Expand file tree Collapse file tree 2 files changed +49
-0
lines changed
Sources/GraphQL/Utilities
Tests/GraphQLTests/UtilitiesTests Expand file tree Collapse file tree 2 files changed +49
-0
lines changed Original file line number Diff line number Diff line change 1+ /**
2+ * Provided a collection of ASTs, presumably each from different files,
3+ * concatenate the ASTs together into batched AST, useful for validating many
4+ * GraphQL source files which together represent one conceptual application.
5+ */
6+ func concatAST(
7+ documents: [ Document ]
8+ ) -> Document {
9+ var definitions : [ Definition ] = [ ]
10+ for doc in documents {
11+ definitions. append ( contentsOf: doc. definitions)
12+ }
13+ return Document ( definitions: definitions)
14+ }
Original file line number Diff line number Diff line change 1+ @testable import GraphQL
2+ import XCTest
3+
4+ class ConcatASTTests : XCTestCase {
5+ func testConcatenatesTwoASTsTogether( ) throws {
6+ let sourceA = Source ( body: """
7+ { a, b, ...Frag }
8+ """ )
9+
10+ let sourceB = Source ( body: """
11+ fragment Frag on T {
12+ c
13+ }
14+ """ )
15+
16+ let astA = try parse ( source: sourceA)
17+ let astB = try parse ( source: sourceB)
18+ let astC = concatAST ( documents: [ astA, astB] )
19+
20+ XCTAssertEqual (
21+ print ( ast: astC) ,
22+ """
23+ {
24+ a
25+ b
26+ ...Frag
27+ }
28+
29+ fragment Frag on T {
30+ c
31+ }
32+ """
33+ )
34+ }
35+ }
You can’t perform that action at this time.
0 commit comments