Skip to content

Commit 92a2f09

Browse files
committed
feat: add includeAll computed property to Query
1 parent c57fc2e commit 92a2f09

File tree

13 files changed

+86
-66
lines changed

13 files changed

+86
-66
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@
55
[Full Changelog](https://github.com/parse-community/Parse-Swift/compare/4.4.0...main)
66
* _Contributing to this repo? Add info about your change here to be included in the next release_
77

8+
__New features__
9+
- Add includeAll computed property to Query and deprecate includeAll() ([#361](https://github.com/parse-community/Parse-Swift/pull/361)), thanks to [Corey Baker](https://github.com/cbaker6).
10+
811
### 4.4.0
912
[Full Changelog](https://github.com/parse-community/Parse-Swift/compare/4.3.1...4.4.0)
1013

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/Objects/ParseInstallation+async.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ public extension ParseInstallation {
1616
Fetches the `ParseInstallation` *aynchronously* with the current data from the server
1717
and sets an error if one occurs.
1818
- parameter includeKeys: The name(s) of the key(s) to include that are
19-
`ParseObject`s. Use `["*"]` to include all keys. This is similar to `include` and
19+
`ParseObject`s. Use `["*"]` to include all keys one level deep. This is similar to `include` and
2020
`includeAll` for `Query`.
2121
- parameter options: A set of header options sent to the server. Defaults to an empty set.
2222
- returns: Returns saved `ParseInstallation`.
@@ -128,7 +128,7 @@ public extension Sequence where Element: ParseInstallation {
128128
Fetches a collection of installations *aynchronously* with the current data from the server and sets
129129
an error if one occurs.
130130
- parameter includeKeys: The name(s) of the key(s) to include that are
131-
`ParseObject`s. Use `["*"]` to include all keys. This is similar to `include` and
131+
`ParseObject`s. Use `["*"]` to include all keys one level deep. This is similar to `include` and
132132
`includeAll` for `Query`.
133133
- parameter options: A set of header options sent to the server. Defaults to an empty set.
134134
- returns: Returns an array of Result enums with the object if a save was successful or a

Sources/ParseSwift/Objects/ParseInstallation+combine.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ public extension ParseInstallation {
1717
Fetches the `ParseInstallation` *aynchronously* with the current data from the server
1818
and sets an error if one occurs. Publishes when complete.
1919
- parameter includeKeys: The name(s) of the key(s) to include that are
20-
`ParseObject`s. Use `["*"]` to include all keys. This is similar to `include` and
20+
`ParseObject`s. Use `["*"]` to include all keys one level deep. This is similar to `include` and
2121
`includeAll` for `Query`.
2222
- parameter options: A set of header options sent to the server. Defaults to an empty set.
2323
- returns: A publisher that eventually produces a single value and then finishes or fails.
@@ -124,7 +124,7 @@ public extension Sequence where Element: ParseInstallation {
124124
Fetches a collection of installations *aynchronously* with the current data from the server and sets
125125
an error if one occurs. Publishes when complete.
126126
- parameter includeKeys: The name(s) of the key(s) to include that are
127-
`ParseObject`s. Use `["*"]` to include all keys. This is similar to `include` and
127+
`ParseObject`s. Use `["*"]` to include all keys one level deep. This is similar to `include` and
128128
`includeAll` for `Query`.
129129
- parameter options: A set of header options sent to the server. Defaults to an empty set.
130130
- returns: A publisher that eventually produces an an array of Result enums with the object if a fetch was

Sources/ParseSwift/Objects/ParseInstallation.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -427,7 +427,7 @@ extension ParseInstallation {
427427
Fetches the `ParseInstallation` *synchronously* with the current data from the server
428428
and sets an error if one occurs.
429429
- parameter includeKeys: The name(s) of the key(s) to include that are
430-
`ParseObject`s. Use `["*"]` to include all keys. This is similar to `include` and
430+
`ParseObject`s. Use `["*"]` to include all keys one level deep. This is similar to `include` and
431431
`includeAll` for `Query`.
432432
- parameter options: A set of header options sent to the server. Defaults to an empty set.
433433
- throws: An error of `ParseError` type.
@@ -448,7 +448,7 @@ extension ParseInstallation {
448448
/**
449449
Fetches the `ParseInstallation` *asynchronously* and executes the given callback block.
450450
- parameter includeKeys: The name(s) of the key(s) to include that are
451-
`ParseObject`s. Use `["*"]` to include all keys. This is similar to `include` and
451+
`ParseObject`s. Use `["*"]` to include all keys one level deep. This is similar to `include` and
452452
`includeAll` for `Query`.
453453
- parameter options: A set of header options sent to the server. Defaults to an empty set.
454454
- parameter callbackQueue: The queue to return to after completion. Default
@@ -1274,7 +1274,7 @@ public extension Sequence where Element: ParseInstallation {
12741274
/**
12751275
Fetches a collection of installations *synchronously* all at once and throws an error if necessary.
12761276
- parameter includeKeys: The name(s) of the key(s) to include that are
1277-
`ParseObject`s. Use `["*"]` to include all keys. This is similar to `include` and
1277+
`ParseObject`s. Use `["*"]` to include all keys one level deep. This is similar to `include` and
12781278
`includeAll` for `Query`.
12791279
- parameter options: A set of header options sent to the server. Defaults to an empty set.
12801280

@@ -1319,7 +1319,7 @@ public extension Sequence where Element: ParseInstallation {
13191319
/**
13201320
Fetches a collection of installations all at once *asynchronously* and executes the completion block when done.
13211321
- parameter includeKeys: The name(s) of the key(s) to include that are
1322-
`ParseObject`s. Use `["*"]` to include all keys. This is similar to `include` and
1322+
`ParseObject`s. Use `["*"]` to include all keys one level deep. This is similar to `include` and
13231323
`includeAll` for `Query`.
13241324
- parameter options: A set of header options sent to the server. Defaults to an empty set.
13251325
- parameter callbackQueue: The queue to return to after completion. Default value of .main.

Sources/ParseSwift/Objects/ParseObject+async.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ public extension ParseObject {
1515
/**
1616
Fetches the `ParseObject` *aynchronously* with the current data from the server and sets an error if one occurs.
1717
- parameter includeKeys: The name(s) of the key(s) to include that are
18-
`ParseObject`s. Use `["*"]` to include all keys. This is similar to `include` and
18+
`ParseObject`s. Use `["*"]` to include all keys one level deep. This is similar to `include` and
1919
`includeAll` for `Query`.
2020
- parameter options: A set of header options sent to the server. Defaults to an empty set.
2121
- returns: Returns the fetched `ParseObject`.
@@ -111,7 +111,7 @@ public extension Sequence where Element: ParseObject {
111111
Fetches a collection of objects *aynchronously* with the current data from the server and sets
112112
an error if one occurs.
113113
- parameter includeKeys: The name(s) of the key(s) to include that are
114-
`ParseObject`s. Use `["*"]` to include all keys. This is similar to `include` and
114+
`ParseObject`s. Use `["*"]` to include all keys one level deep. This is similar to `include` and
115115
`includeAll` for `Query`.
116116
- parameter options: A set of header options sent to the server. Defaults to an empty set.
117117
- returns: Returns an array of Result enums with the object if a fetch was successful or a

Sources/ParseSwift/Objects/ParseObject+combine.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ public extension ParseObject {
1717
Fetches the `ParseObject` *aynchronously* with the current data from the server and sets an error if one occurs.
1818
Publishes when complete.
1919
- parameter includeKeys: The name(s) of the key(s) to include that are
20-
`ParseObject`s. Use `["*"]` to include all keys. This is similar to `include` and
20+
`ParseObject`s. Use `["*"]` to include all keys one level deep. This is similar to `include` and
2121
`includeAll` for `Query`.
2222
- parameter options: A set of header options sent to the server. Defaults to an empty set.
2323
- returns: A publisher that eventually produces a single value and then finishes or fails.
@@ -118,7 +118,7 @@ public extension Sequence where Element: ParseObject {
118118
Fetches a collection of objects *aynchronously* with the current data from the server and sets
119119
an error if one occurs. Publishes when complete.
120120
- parameter includeKeys: The name(s) of the key(s) to include that are
121-
`ParseObject`s. Use `["*"]` to include all keys. This is similar to `include` and
121+
`ParseObject`s. Use `["*"]` to include all keys one level deep. This is similar to `include` and
122122
`includeAll` for `Query`.
123123
- parameter options: A set of header options sent to the server. Defaults to an empty set.
124124
- returns: A publisher that eventually produces an an array of Result enums with the object if a fetch was

Sources/ParseSwift/Objects/ParseObject.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -584,7 +584,7 @@ transactions for this call.
584584
/**
585585
Fetches a collection of objects *synchronously* all at once and throws an error if necessary.
586586
- parameter includeKeys: The name(s) of the key(s) to include that are
587-
`ParseObject`s. Use `["*"]` to include all keys. This is similar to `include` and
587+
`ParseObject`s. Use `["*"]` to include all keys one level deep. This is similar to `include` and
588588
`includeAll` for `Query`.
589589
- parameter options: A set of header options sent to the server. Defaults to an empty set.
590590
- returns: Returns an array of Result enums with the object if a fetch was successful or a
@@ -625,7 +625,7 @@ transactions for this call.
625625
/**
626626
Fetches a collection of objects all at once *asynchronously* and executes the completion block when done.
627627
- parameter includeKeys: The name(s) of the key(s) to include that are
628-
`ParseObject`s. Use `["*"]` to include all keys. This is similar to `include` and
628+
`ParseObject`s. Use `["*"]` to include all keys one level deep. This is similar to `include` and
629629
`includeAll` for `Query`.
630630
- parameter options: A set of header options sent to the server. Defaults to an empty set.
631631
- parameter callbackQueue: The queue to return to after completion. Default value of .main.
@@ -819,7 +819,7 @@ extension ParseObject {
819819
/**
820820
Fetches the `ParseObject` *synchronously* with the current data from the server and sets an error if one occurs.
821821
- parameter includeKeys: The name(s) of the key(s) to include that are
822-
`ParseObject`s. Use `["*"]` to include all keys. This is similar to `include` and
822+
`ParseObject`s. Use `["*"]` to include all keys one level deep. This is similar to `include` and
823823
`includeAll` for `Query`.
824824
- parameter options: A set of header options sent to the server. Defaults to an empty set.
825825
- throws: An error of `ParseError` type.
@@ -837,7 +837,7 @@ extension ParseObject {
837837
/**
838838
Fetches the `ParseObject` *asynchronously* and executes the given callback block.
839839
- parameter includeKeys: The name(s) of the key(s) to include. Use `["*"]` to include
840-
all keys.
840+
all keys one level deep.
841841
- parameter options: A set of header options sent to the server. Defaults to an empty set.
842842
- parameter callbackQueue: The queue to return to after completion. Default
843843
value of .main.

Sources/ParseSwift/Objects/ParseUser+async.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ public extension ParseUser {
184184
/**
185185
Fetches the `ParseUser` *aynchronously* with the current data from the server and sets an error if one occurs.
186186
- parameter includeKeys: The name(s) of the key(s) to include that are
187-
`ParseObject`s. Use `["*"]` to include all keys. This is similar to `include` and
187+
`ParseObject`s. Use `["*"]` to include all keys one level deep. This is similar to `include` and
188188
`includeAll` for `Query`.
189189
- parameter options: A set of header options sent to the server. Defaults to an empty set.
190190
- returns: Returns the fetched `ParseUser`.
@@ -303,7 +303,7 @@ public extension Sequence where Element: ParseUser {
303303
Fetches a collection of users *aynchronously* with the current data from the server and sets
304304
an error if one occurs.
305305
- parameter includeKeys: The name(s) of the key(s) to include that are
306-
`ParseObject`s. Use `["*"]` to include all keys. This is similar to `include` and
306+
`ParseObject`s. Use `["*"]` to include all keys one level deep. This is similar to `include` and
307307
`includeAll` for `Query`.
308308
- parameter options: A set of header options sent to the server. Defaults to an empty set.
309309
- returns: Returns an array of Result enums with the object if a fetch was successful or a

Sources/ParseSwift/Objects/ParseUser+combine.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ public extension ParseUser {
174174
Fetches the `ParseUser` *aynchronously* with the current data from the server and sets an error if one occurs.
175175
Publishes when complete.
176176
- parameter includeKeys: The name(s) of the key(s) to include that are
177-
`ParseObject`s. Use `["*"]` to include all keys. This is similar to `include` and
177+
`ParseObject`s. Use `["*"]` to include all keys one level deep. This is similar to `include` and
178178
`includeAll` for `Query`.
179179
- parameter options: A set of header options sent to the server. Defaults to an empty set.
180180
- returns: A publisher that eventually produces a single value and then finishes or fails.
@@ -289,7 +289,7 @@ public extension Sequence where Element: ParseUser {
289289
Fetches a collection of users *aynchronously* with the current data from the server and sets
290290
an error if one occurs. Publishes when complete.
291291
- parameter includeKeys: The name(s) of the key(s) to include that are
292-
`ParseObject`s. Use `["*"]` to include all keys. This is similar to `include` and
292+
`ParseObject`s. Use `["*"]` to include all keys one level deep. This is similar to `include` and
293293
`includeAll` for `Query`.
294294
- parameter options: A set of header options sent to the server. Defaults to an empty set.
295295
- returns: A publisher that eventually produces an an array of Result enums with the object if a fetch was

Sources/ParseSwift/Objects/ParseUser.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -835,7 +835,7 @@ extension ParseUser {
835835
/**
836836
Fetches the `ParseUser` *synchronously* with the current data from the server and sets an error if one occurs.
837837
- parameter includeKeys: The name(s) of the key(s) to include that are
838-
`ParseObject`s. Use `["*"]` to include all keys. This is similar to `include` and
838+
`ParseObject`s. Use `["*"]` to include all keys one level deep. This is similar to `include` and
839839
`includeAll` for `Query`.
840840
- parameter options: A set of header options sent to the server. Defaults to an empty set.
841841
- throws: An error of `ParseError` type.
@@ -856,7 +856,7 @@ extension ParseUser {
856856
/**
857857
Fetches the `ParseUser` *asynchronously* and executes the given callback block.
858858
- parameter includeKeys: The name(s) of the key(s) to include that are
859-
`ParseObject`s. Use `["*"]` to include all keys. This is similar to `include` and
859+
`ParseObject`s. Use `["*"]` to include all keys one level deep. This is similar to `include` and
860860
`includeAll` for `Query`.
861861
- parameter options: A set of header options sent to the server. Defaults to an empty set.
862862
- parameter callbackQueue: The queue to return to after completion. Default
@@ -1692,7 +1692,7 @@ public extension Sequence where Element: ParseUser {
16921692
/**
16931693
Fetches a collection of users *synchronously* all at once and throws an error if necessary.
16941694
- parameter includeKeys: The name(s) of the key(s) to include that are
1695-
`ParseObject`s. Use `["*"]` to include all keys. This is similar to `include` and
1695+
`ParseObject`s. Use `["*"]` to include all keys one level deep. This is similar to `include` and
16961696
`includeAll` for `Query`.
16971697
- parameter options: A set of header options sent to the server. Defaults to an empty set.
16981698

@@ -1735,7 +1735,7 @@ public extension Sequence where Element: ParseUser {
17351735
/**
17361736
Fetches a collection of users all at once *asynchronously* and executes the completion block when done.
17371737
- parameter includeKeys: The name(s) of the key(s) to include that are
1738-
`ParseObject`s. Use `["*"]` to include all keys. This is similar to `include` and
1738+
`ParseObject`s. Use `["*"]` to include all keys one level deep. This is similar to `include` and
17391739
`includeAll` for `Query`.
17401740
- parameter options: A set of header options sent to the server. Defaults to an empty set.
17411741
- parameter callbackQueue: The queue to return to after completion. Default value of .main.

Sources/ParseSwift/Types/Query.swift

Lines changed: 54 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,29 @@ public struct Query<T>: Encodable, Equatable where T: ParseObject {
3131
internal var distinct: String?
3232
internal var pipeline: [[String: AnyEncodable]]?
3333
internal var fields: Set<String>?
34+
var endpoint: API.Endpoint {
35+
.objects(className: T.className)
36+
}
37+
38+
/// The className of the `ParseObject` to query.
39+
public static var className: String {
40+
T.className
41+
}
42+
43+
/// The className of the `ParseObject` to query.
44+
public var className: String {
45+
Self.className
46+
}
47+
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+
}
3457

3558
struct AggregateBody<T>: Encodable where T: ParseObject {
3659
let pipeline: [[String: AnyEncodable]]?
@@ -60,6 +83,25 @@ public struct Query<T>: Encodable, Equatable where T: ParseObject {
6083
}
6184
}
6285

86+
enum CodingKeys: String, CodingKey {
87+
case `where`
88+
case method = "_method"
89+
case limit
90+
case skip
91+
case include
92+
case isCount = "count"
93+
case keys
94+
case order
95+
case explain
96+
case hint
97+
case excludeKeys
98+
case readPreference
99+
case includeReadPreference
100+
case subqueryReadPreference
101+
case distinct
102+
case pipeline
103+
}
104+
63105
/**
64106
An enum that determines the order to sort the results based on a given key.
65107

@@ -215,11 +257,11 @@ public struct Query<T>: Encodable, Equatable where T: ParseObject {
215257
/**
216258
Includes all nested `ParseObject`s one level deep.
217259
- warning: Requires Parse Server 3.0.0+.
260+
- warning: This will be removed in ParseSwift 5.0.0 in favor of the `includeAll` computed property.
218261
*/
219-
public func includeAll() -> Query<T> {
220-
var mutableQuery = self
221-
mutableQuery.include = ["*"]
222-
return mutableQuery
262+
@available(*, deprecated, renamed: "includeAll")
263+
public func includeAll(_ keys: [String]? = nil) -> Query<T> {
264+
self.includeAll
223265
}
224266

225267
/**
@@ -274,6 +316,14 @@ public struct Query<T>: Encodable, Equatable where T: ParseObject {
274316
return mutableQuery
275317
}
276318

319+
/**
320+
An enum that determines the order to sort the results based on a given key.
321+
- parameter keys: A variadic list of keys to order by.
322+
*/
323+
public func order(_ keys: Order...) -> Query<T> {
324+
self.order(keys)
325+
}
326+
277327
/**
278328
An enum that determines the order to sort the results based on a given key.
279329
- parameter keys: An array of keys to order by.
@@ -319,39 +369,6 @@ public struct Query<T>: Encodable, Equatable where T: ParseObject {
319369
}
320370
return mutableQuery
321371
}
322-
323-
/// The className of the `ParseObject` to query.
324-
public var className: String {
325-
return Self.className
326-
}
327-
328-
/// The className of the `ParseObject` to query.
329-
public static var className: String {
330-
return T.className
331-
}
332-
333-
var endpoint: API.Endpoint {
334-
return .objects(className: T.className)
335-
}
336-
337-
enum CodingKeys: String, CodingKey {
338-
case `where`
339-
case method = "_method"
340-
case limit
341-
case skip
342-
case include
343-
case isCount = "count"
344-
case keys
345-
case order
346-
case explain
347-
case hint
348-
case excludeKeys
349-
case readPreference
350-
case includeReadPreference
351-
case subqueryReadPreference
352-
case distinct
353-
case pipeline
354-
}
355372
}
356373

357374
// MARK: Queryable

0 commit comments

Comments
 (0)