Skip to content

Commit c14723a

Browse files
authored
feat: allow includeAll with additional includes (#367)
* refactor: includeAll property -> includeAll() * feat: allow includeAll with additional includes * fix tests and add changelog
1 parent 6fc9d2d commit c14723a

File tree

11 files changed

+42
-62
lines changed

11 files changed

+42
-62
lines changed

CHANGELOG.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,10 @@ __New features__
99
- Add toCLLocation and toCLLocationCoordinate2D computed properties to ParseGeoPoint, deprecate toCLLocation() and toCLLocationCoordinate2D() ([#366](https://github.com/parse-community/Parse-Swift/pull/366)), thanks to [Corey Baker](https://github.com/cbaker6).
1010
- Add query computed property to ParseObject ([#365](https://github.com/parse-community/Parse-Swift/pull/365)), thanks to [Corey Baker](https://github.com/cbaker6).
1111
- Add macCatalyst to SPM ([#363](https://github.com/parse-community/Parse-Swift/pull/363)), thanks to [Corey Baker](https://github.com/cbaker6).
12-
- Add includeAll computed property to Query and deprecate includeAll(). Add an order() method to Query that excepts a variadic list as input ([#362](https://github.com/parse-community/Parse-Swift/pull/362)), thanks to [Corey Baker](https://github.com/cbaker6).
12+
- Add an order() method to Query that excepts a variadic list as input ([#362](https://github.com/parse-community/Parse-Swift/pull/362)), thanks to [Corey Baker](https://github.com/cbaker6).
1313

1414
__Improvements__
15+
- Allow includeAll key to be sent with additional include keys. When fetching, if the include argument is specified, convert it to a Set to prevent duplicate keys from being sent to the server ([#367](https://github.com/parse-community/Parse-Swift/pull/367)), thanks to [Corey Baker](https://github.com/cbaker6).
1516
- Allow LiveQuery client to be set using ParseLiveQuery.defaultClient and deprecate ParseLiveQuery.setDefault(). Show usage of deprecated code as warnings during compile time and suggest changes ([#360](https://github.com/parse-community/Parse-Swift/pull/360)), thanks to [Corey Baker](https://github.com/cbaker6).
1617

1718
### 4.4.0

ParseSwift.playground/Pages/8 - Pointers.xcplaygroundpage/Contents.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ query2.first { results in
177177
objects.
178178
*/
179179
let query3 = Author.query("name" == "Bruce")
180-
.includeAll
180+
.includeAll()
181181

182182
query3.first { results in
183183
switch results {
@@ -192,7 +192,7 @@ query3.first { results in
192192
//: You can also check if a field is equal to a ParseObject.
193193
do {
194194
let query4 = try Author.query("book" == newBook)
195-
.includeAll
195+
.includeAll()
196196

197197
query4.first { results in
198198
switch results {

Sources/ParseSwift/API/API+Command.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -474,7 +474,7 @@ internal extension API.Command {
474474

475475
var params: [String: String]?
476476
if let includeParams = include {
477-
params = ["include": "\(includeParams)"]
477+
params = ["include": "\(Set(includeParams))"]
478478
}
479479

480480
return API.Command<T, T>(

Sources/ParseSwift/Objects/ParseInstallation.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -508,7 +508,7 @@ extension ParseInstallation {
508508

509509
var params: [String: String]?
510510
if let includeParams = include {
511-
params = ["include": "\(includeParams)"]
511+
params = ["include": "\(Set(includeParams))"]
512512
}
513513

514514
return API.Command(method: .GET,

Sources/ParseSwift/Objects/ParseUser.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -916,7 +916,7 @@ extension ParseUser {
916916

917917
var params: [String: String]?
918918
if let includeParams = include {
919-
params = ["include": "\(includeParams)"]
919+
params = ["include": "\(Set(includeParams))"]
920920
}
921921

922922
return API.Command(method: .GET,

Sources/ParseSwift/ParseConstants.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ enum ParseConstants {
1717
static let fileDownloadsDirectory = "Downloads"
1818
static let bundlePrefix = "com.parse.ParseSwift"
1919
static let batchLimit = 50
20+
static let includeAllKey = "*"
2021
#if os(iOS)
2122
static let deviceType = "ios"
2223
#elseif os(macOS)

Sources/ParseSwift/Types/Query.swift

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -45,16 +45,6 @@ public struct Query<T>: Encodable, Equatable where T: ParseObject {
4545
Self.className
4646
}
4747

48-
/**
49-
Includes all nested `ParseObject`s one level deep.
50-
- warning: Requires Parse Server 3.0.0+.
51-
*/
52-
public var includeAll: Query<T> {
53-
var mutableQuery = self
54-
mutableQuery.include = ["*"]
55-
return mutableQuery
56-
}
57-
5848
struct AggregateBody<T>: Encodable where T: ParseObject {
5949
let pipeline: [[String: AnyEncodable]]?
6050
let hint: AnyEncodable?
@@ -265,12 +255,16 @@ public struct Query<T>: Encodable, Equatable where T: ParseObject {
265255
/**
266256
Includes all nested `ParseObject`s one level deep.
267257
- warning: Requires Parse Server 3.0.0+.
268-
- warning: This will be removed in ParseSwift 5.0.0 in favor of the `includeAll` computed property.
269258
- returns: The mutated instance of query for easy chaining.
270259
*/
271-
@available(*, deprecated, message: "Use the computed property instead by removing \"()\"")
272-
public func includeAll(_ keys: [String]? = nil) -> Query<T> {
273-
self.includeAll
260+
public func includeAll() -> Query<T> {
261+
var mutableQuery = self
262+
if mutableQuery.include != nil {
263+
mutableQuery.include?.insert(ParseConstants.includeAllKey)
264+
} else {
265+
mutableQuery.include = [ParseConstants.includeAllKey]
266+
}
267+
return mutableQuery
274268
}
275269

276270
/**

Tests/ParseSwiftTests/ParseInstallationTests.swift

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -777,21 +777,14 @@ class ParseInstallationTests: XCTestCase { // swiftlint:disable:this type_body_l
777777
XCTAssertNotNil(command)
778778
XCTAssertEqual(command.path.urlComponent, "/installations/\(objectId)")
779779
XCTAssertEqual(command.method, API.Method.GET)
780-
XCTAssertEqual(command.params, includeExpected)
781-
XCTAssertNil(command.body)
782-
783-
// swiftlint:disable:next line_length
784-
guard let urlExpected = URL(string: "http://localhost:1337/1/installations/yarr?include=%5B%22yolo%22,%20%22test%22%5D") else {
785-
XCTFail("Should have unwrapped")
786-
return
787-
}
788-
let request = command.prepareURLRequest(options: [])
789-
switch request {
790-
case .success(let url):
791-
XCTAssertEqual(url.url, urlExpected)
792-
case .failure(let error):
793-
XCTFail(error.localizedDescription)
780+
XCTAssertEqual(command.params?.keys.first, includeExpected.keys.first)
781+
if let value = command.params?.values.first,
782+
let includeValue = value {
783+
XCTAssertTrue(includeValue.contains("\"yolo\""))
784+
} else {
785+
XCTFail("Should have unwrapped value")
794786
}
787+
XCTAssertNil(command.body)
795788
} catch {
796789
XCTFail(error.localizedDescription)
797790
}

Tests/ParseSwiftTests/ParseObjectTests.swift

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -456,21 +456,14 @@ class ParseObjectTests: XCTestCase { // swiftlint:disable:this type_body_length
456456
XCTAssertNotNil(command)
457457
XCTAssertEqual(command.path.urlComponent, "/classes/\(className)/\(objectId)")
458458
XCTAssertEqual(command.method, API.Method.GET)
459-
XCTAssertEqual(command.params, includeExpected)
460-
XCTAssertNil(command.body)
461-
462-
// swiftlint:disable:next line_length
463-
guard let urlExpected = URL(string: "http://localhost:1337/1/classes/GameScore/yarr?include=%5B%22yolo%22,%20%22test%22%5D") else {
464-
XCTFail("Should have unwrapped")
465-
return
466-
}
467-
let request = command.prepareURLRequest(options: [])
468-
switch request {
469-
case .success(let url):
470-
XCTAssertEqual(url.url, urlExpected)
471-
case .failure(let error):
472-
XCTFail(error.localizedDescription)
459+
XCTAssertEqual(command.params?.keys.first, includeExpected.keys.first)
460+
if let value = command.params?.values.first,
461+
let includeValue = value {
462+
XCTAssertTrue(includeValue.contains("\"yolo\""))
463+
} else {
464+
XCTFail("Should have unwrapped value")
473465
}
466+
XCTAssertNil(command.body)
474467
} catch {
475468
XCTFail(error.localizedDescription)
476469
}

Tests/ParseSwiftTests/ParseQueryTests.swift

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,11 @@ class ParseQueryTests: XCTestCase { // swiftlint:disable:this type_body_length
205205
let query2 = GameScore.query.includeAll()
206206
XCTAssertEqual(query2.include?.count, 1)
207207
XCTAssertEqual(query2.include, ["*"])
208+
let query3 = GameScore.query
209+
.include("hello")
210+
.includeAll()
211+
XCTAssertEqual(query3.include?.count, 2)
212+
XCTAssertEqual(query3.include, Set(["hello", "*"]))
208213
}
209214

210215
func testExcludeKeys() throws {

Tests/ParseSwiftTests/ParseUserTests.swift

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -213,21 +213,14 @@ class ParseUserTests: XCTestCase { // swiftlint:disable:this type_body_length
213213
XCTAssertNotNil(command)
214214
XCTAssertEqual(command.path.urlComponent, "/users/\(objectId)")
215215
XCTAssertEqual(command.method, API.Method.GET)
216-
XCTAssertEqual(command.params, includeExpected)
217-
XCTAssertNil(command.body)
218-
219-
// swiftlint:disable:next line_length
220-
guard let urlExpected = URL(string: "http://localhost:1337/1/users/yarr?include=%5B%22yolo%22,%20%22test%22%5D") else {
221-
XCTFail("Should have unwrapped")
222-
return
223-
}
224-
let request = command.prepareURLRequest(options: [])
225-
switch request {
226-
case .success(let url):
227-
XCTAssertEqual(url.url, urlExpected)
228-
case .failure(let error):
229-
XCTFail(error.localizedDescription)
216+
XCTAssertEqual(command.params?.keys.first, includeExpected.keys.first)
217+
if let value = command.params?.values.first,
218+
let includeValue = value {
219+
XCTAssertTrue(includeValue.contains("\"yolo\""))
220+
} else {
221+
XCTFail("Should have unwrapped value")
230222
}
223+
XCTAssertNil(command.body)
231224
} catch {
232225
XCTFail(error.localizedDescription)
233226
}

0 commit comments

Comments
 (0)