-
Notifications
You must be signed in to change notification settings - Fork 39
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Field Merging[2/x] Compute MergedSelections w/MergingStrategy
- Loading branch information
1 parent
eec8762
commit 73b01cd
Showing
11 changed files
with
329 additions
and
109 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
102 changes: 102 additions & 0 deletions
102
Tests/ApolloCodegenTests/CodeGenIR/IRMergedSelections_FieldMergingStrategy_Tests.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
import XCTest | ||
import Nimble | ||
import OrderedCollections | ||
import GraphQLCompiler | ||
@testable import IR | ||
@testable import ApolloCodegenLib | ||
import ApolloInternalTestHelpers | ||
import ApolloCodegenInternalTestHelpers | ||
import ApolloAPI | ||
|
||
class IRMergedSelections_FieldMergingStrategy_Tests: XCTestCase { | ||
|
||
var schemaSDL: String! | ||
var document: String! | ||
var ir: IRBuilderTestWrapper! | ||
var operation: CompilationResult.OperationDefinition! | ||
var rootField: IRTestWrapper<IR.Field>! | ||
|
||
var schema: IR.Schema { ir.schema } | ||
|
||
override func setUp() { | ||
super.setUp() | ||
} | ||
|
||
override func tearDown() { | ||
schemaSDL = nil | ||
document = nil | ||
operation = nil | ||
rootField = nil | ||
super.tearDown() | ||
} | ||
|
||
// MARK: - Helpers | ||
|
||
func buildRootField( | ||
mergingStrategy: IR.MergedSelections.MergingStrategy | ||
) async throws { | ||
ir = try await IRBuilderTestWrapper(.mock(schema: schemaSDL, document: document)) | ||
operation = try XCTUnwrap(ir.compilationResult.operations.first) | ||
|
||
rootField = await ir.build( | ||
operation: operation, | ||
mergingStrategy: mergingStrategy | ||
).rootField | ||
} | ||
|
||
// MARK: - Test MergingStrategy: Ancestors | ||
|
||
func test__mergingStrategy_ancestors__givenFieldInAncestor_includesField() async throws { | ||
// given | ||
schemaSDL = """ | ||
type Query { | ||
allAnimals: [Animal!] | ||
} | ||
interface Animal { | ||
species: String | ||
} | ||
interface Pet implements Animal { | ||
species: String | ||
petName: String | ||
} | ||
""" | ||
|
||
document = """ | ||
query Test { | ||
allAnimals { | ||
species | ||
... on Pet { | ||
petName | ||
} | ||
} | ||
} | ||
""" | ||
let mergingStrategy: MergedSelections.MergingStrategy = .ancestors | ||
|
||
try await buildRootField(mergingStrategy: mergingStrategy) | ||
|
||
let Scalar_String = try unwrap(self.schema[scalar: "String"]) | ||
|
||
// when | ||
let subject = rootField[field: "allAnimals"]?[as: "Pet"] | ||
|
||
let expected = SelectionSetMatcher( | ||
parentType: try unwrap(self.schema[interface: "Pet"]), | ||
directSelections: [ | ||
.field("petName", type: .scalar(Scalar_String)) | ||
], | ||
mergedSelections: [ | ||
.field("species", type: .scalar(Scalar_String)) | ||
], | ||
mergedSources: [ | ||
try .mock(rootField[field:"allAnimals"]) | ||
], | ||
mergingStrategy: mergingStrategy | ||
) | ||
|
||
// then | ||
expect(subject).to(shallowlyMatch(expected)) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.