Skip to content

Commit 63bf5af

Browse files
fix availability gate for JSON sorting
1 parent ecca574 commit 63bf5af

3 files changed

Lines changed: 13 additions & 4 deletions

File tree

Sources/Apollo/JSONSerialziation+Sorting.swift

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,19 @@ extension JSONSerialization {
2020
// presently support, but we should use it where we can in
2121
// order to get stable JSON representations, especially if being
2222
// used in queries.
23-
if #available(iOS 11, macOS 13, watchOS 4, tvOS 11, *) {
23+
if #available(iOS 11, macOS 10.13, watchOS 4, tvOS 11, *) {
2424
return try self.data(withJSONObject: object, options: [.sortedKeys])
2525
} else {
2626
return try self.data(withJSONObject: object)
2727
}
2828
}
29+
30+
/// Wrapper function so we don't have to scatter `if #available` all over the codebase to see if data can be sorted.
31+
static func dataCanBeSorted() -> Bool {
32+
if #available(iOS 11, macOS 10.13, watchOS 4, tvOS 11, *) {
33+
return true
34+
} else {
35+
return false
36+
}
37+
}
2938
}

Tests/ApolloTests/GETTransformerTests.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ class GETTransformerTests: XCTestCase {
3333

3434
let url = transformer.createGetURL()
3535

36-
if #available(iOS 11, macOS 13, tvOS 11, watchOS 4, *) {
36+
if JSONSerialization.dataCanBeSorted() {
3737
// Here, we know that everything should be encoded in a stable order,
3838
// and we can check the encoded URL string directly.
3939
XCTAssertEqual(url?.absoluteString, "http://localhost:8080/graphql?operationName=HeroNameTypeSpecificConditionalInclusion&query=query%20HeroNameTypeSpecificConditionalInclusion($episode:%20Episode,%20$includeName:%20Boolean!)%20%7B%20hero(episode:%20$episode)%20%7B%20__typename%20name%20@include(if:%20$includeName)%20...%20on%20Droid%20%7B%20name%20%7D%20%7D%20%7D&variables=%7B%22episode%22:%22JEDI%22,%22includeName%22:true%7D")

Tests/ApolloTests/RequestCreatorTests.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ Charlie file content.
177177

178178
let stringToCompare = try self.string(from: data)
179179

180-
if #available(iOS 11, macOS 13, tvOS 11, watchOS 4, *) {
180+
if JSONSerialization.dataCanBeSorted() {
181181
let expectedString = """
182182
--TEST.BOUNDARY
183183
Content-Disposition: form-data; name="operations"
@@ -239,7 +239,7 @@ Alpha file content.
239239

240240
let stringToCompare = try self.string(from: data)
241241

242-
if #available(iOS 11, macOS 13, tvOS 11, watchOS 4, *) {
242+
if JSONSerialization.dataCanBeSorted() {
243243
let expectedString = """
244244
--TEST.BOUNDARY
245245
Content-Disposition: form-data; name="operations"

0 commit comments

Comments
 (0)