Skip to content

Commit

Permalink
fix child selection set computation for field merging and add more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
AnthonyMDev committed May 1, 2024
1 parent 29e5f1f commit 288253c
Show file tree
Hide file tree
Showing 5 changed files with 846 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,22 @@ class SelectionSetTemplate_ErrorHandling_Tests: XCTestCase {

// MARK: - Helpers

func buildSubjectAndOperation(named operationName: String = "ConflictingQuery") async throws {
func buildSubjectAndOperation(
named operationName: String = "ConflictingQuery",
fieldMerging: ApolloCodegenConfiguration.FieldMerging = .all
) async throws {
ir = try await IRBuilderTestWrapper(.mock(schema: schemaSDL, document: document))
let operationDefinition = try XCTUnwrap(ir.compilationResult[operation: operationName])
operation = await ir.build(operation: operationDefinition)
operation = await ir.build(
operation: operationDefinition,
mergingStrategy: fieldMerging.options
)
let config = ApolloCodegenConfiguration.mock(
schemaNamespace: "TestSchema",
output: .mock(moduleType: .swiftPackageManager, operations: .inSchemaModule),
options: .init()
options: .init(
fieldMerging: fieldMerging
)
)
let mockTemplateRenderer = MockTemplateRenderer(
target: .operationFile(),
Expand Down Expand Up @@ -251,6 +259,61 @@ class SelectionSetTemplate_ErrorHandling_Tests: XCTestCase {
expect(self.errorRecorder.recordedErrors.first).to(equal(expectedError))
}

func
test__validation__selectionSet_typeConflicts_withDirectInlineFragment_withFieldMerging_notIncludingAncestors_shouldNotReturnError()
async throws
{
schemaSDL = """
type Query {
user: User
}
type User {
containers: [ContainerInterface]
}
interface ContainerInterface {
value: Value
}
type Container implements ContainerInterface{
value: Value
values: [Value]
}
type Value {
propertyA: String!
propertyB: String!
propertyC: String!
propertyD: String!
}
"""

document = """
query ConflictingQuery {
user {
containers {
value {
propertyA
propertyB
propertyC
propertyD
}
... on Container {
values {
propertyA
propertyC
}
}
}
}
}
"""

// when
try await buildSubjectAndOperation(fieldMerging: .siblings)
_ = subject.renderBody()

// then
expect(self.errorRecorder.recordedErrors).to(beEmpty())
}

func
test__validation__selectionSet_typeConflicts_withMergedInlineFragment_shouldReturnNonFatalError()
async throws
Expand Down Expand Up @@ -382,6 +445,61 @@ class SelectionSetTemplate_ErrorHandling_Tests: XCTestCase {
expect(self.errorRecorder.recordedErrors.first).to(equal(expectedError))
}

func
test__validation__selectionSet_typeConflicts_withDirectNamedFragment_givenFieldMerging_notIncludingNamedFragments_shouldNotReturnError()
async throws
{
schemaSDL = """
type Query {
user: User
}
type User {
containers: [Container]
}
type Container {
value: Value
values: [Value]
}
type Value {
propertyA: String!
propertyB: String!
propertyC: String!
propertyD: String!
}
"""

document = """
query ConflictingQuery {
user {
containers {
value {
propertyA
propertyB
propertyC
propertyD
}
...ContainerFields
}
}
}
fragment ContainerFields on Container {
values {
propertyA
propertyC
}
}
"""

// when
try await buildSubjectAndOperation(fieldMerging: [.ancestors, .siblings])
_ = subject.renderBody()

// then
expect(self.errorRecorder.recordedErrors).to(beEmpty())
}

func test__validation__selectionSet_typeConflicts_withNamedFragment_shouldReturnNonFatalError()
async throws
{
Expand Down

0 comments on commit 288253c

Please sign in to comment.