Skip to content

Commit c43ac68

Browse files
AnthonyMDevgh-action-runner
authored andcommitted
Fix infinite loop bug in Test Mocks (#842)
1 parent 7aae57a commit c43ac68

File tree

2 files changed

+25
-1
lines changed

2 files changed

+25
-1
lines changed

Tests/ApolloTests/TestMockTests.swift

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -517,7 +517,7 @@ class TestMockTests: XCTestCase {
517517
final class CatData: TestMockSchema.MockSelectionSet, @unchecked Sendable {
518518
override class var __parentType: any ParentType { TestMockSchema.Types.Cat }
519519
override class var __selections: [Selection] {[
520-
.field("species", String.self),
520+
.field("species", String?.self),
521521
]}
522522
}
523523
}
@@ -535,6 +535,27 @@ class TestMockTests: XCTestCase {
535535
expect(selectionSet.nestedListOfObjects.count).to(equal(1))
536536
expect(selectionSet.nestedListOfObjects[0].count).to(equal(3))
537537
}
538+
539+
func test__convertToSelectionSet__setListOfScalarsField__canAccessField() async throws {
540+
// given
541+
final class Animal: TestMockSchema.MockSelectionSet, @unchecked Sendable {
542+
override class var __parentType: any ParentType { TestMockSchema.Interfaces.Animal }
543+
override class var __selections: [Selection] {[
544+
.field("listOfStrings", [String].self),
545+
]}
546+
547+
var listOfStrings: [String] { __data["listOfStrings"] }
548+
}
549+
550+
let mock = Mock<Dog>()
551+
mock.listOfStrings = ["1", "2", "3"]
552+
553+
// when
554+
let selectionSet = await Animal.from(mock)
555+
556+
// then
557+
expect(selectionSet.listOfStrings.count).to(equal(3))
558+
}
538559
}
539560

540561
// MARK: - Generated Example

apollo-ios/Sources/ApolloTestSupport/TestMock.swift

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,9 @@ fileprivate extension Array {
198198
case let innerArray as Array<Any>:
199199
return innerArray._unsafelyConvertToSelectionSetData() as JSONValue
200200

201+
case let element as JSONValue:
202+
return element
203+
201204
case let optionalElement as Optional<any Sendable>:
202205
guard case let .some(element) = optionalElement.asNullable else {
203206
return nil

0 commit comments

Comments
 (0)