Skip to content

Commit ab8f785

Browse files
committed
Refactor equality logic
1 parent 62f5c2b commit ab8f785

File tree

1 file changed

+13
-5
lines changed

1 file changed

+13
-5
lines changed

apollo-ios/Sources/ApolloAPI/SelectionSet+Equatable.swift

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,9 @@ public extension SelectionSet {
2222
}
2323

2424
@inlinable
25-
internal static func equatableCheck<T: Hashable>(
26-
_ lhs: [T: any Hashable],
27-
_ rhs: [T: any Hashable]
25+
internal static func equatableCheck(
26+
_ lhs: [String: any Hashable],
27+
_ rhs: [String: any Hashable]
2828
) -> Bool {
2929
guard lhs.keys == rhs.keys else { return false }
3030

@@ -37,12 +37,21 @@ public extension SelectionSet {
3737
}
3838
}
3939

40+
@_disfavoredOverload
4041
@inlinable
4142
internal static func equatableCheck<T: Hashable>(
4243
_ lhs: T,
4344
_ rhs: any Hashable
4445
) -> Bool {
45-
lhs == rhs as? T
46+
if let lhs = lhs as? [any Hashable],
47+
let rhs = rhs as? [any Hashable] {
48+
49+
return lhs.elementsEqual(rhs) { l, r in
50+
equatableCheck(l, r)
51+
}
52+
}
53+
54+
return lhs == rhs as? T
4655
}
4756

4857
private func fieldsForEquality() -> [String: FieldValue] {
@@ -52,7 +61,6 @@ public extension SelectionSet {
5261

5362
} else {
5463
self.addFulfilledSelections(of: type(of: self), to: &fields)
55-
5664
}
5765

5866
return fields

0 commit comments

Comments
 (0)