Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature: fetch with including specific or all keys #74

Merged
merged 8 commits into from Feb 2, 2021
Merged

Conversation

cbaker6
Copy link
Contributor

@cbaker6 cbaker6 commented Feb 1, 2021

  • Adds fetch(includeKeys: [String]? = nil) and fetchPublisher(includeKeys: [String]? = nil) to all ParseObjects.
  • Documentation
  • Testcases
  • Playgrounds

Non breaking...

@codecov
Copy link

codecov bot commented Feb 1, 2021

Codecov Report

Merging #74 (a8ce5d0) into main (fb61b78) will increase coverage by 0.06%.
The diff coverage is 90.90%.

Impacted file tree graph

@@            Coverage Diff             @@
##             main      #74      +/-   ##
==========================================
+ Coverage   78.91%   78.97%   +0.06%     
==========================================
  Files          61       61              
  Lines        4870     4903      +33     
==========================================
+ Hits         3843     3872      +29     
- Misses       1027     1031       +4     
Impacted Files Coverage Δ
Sources/ParseSwift/Protocols/Fetchable.swift 0.00% <0.00%> (ø)
Sources/ParseSwift/Objects/ParseObject.swift 75.94% <84.61%> (-0.60%) ⬇️
Sources/ParseSwift/Objects/ParseInstallation.swift 82.07% <88.23%> (-0.09%) ⬇️
Sources/ParseSwift/Objects/ParseUser.swift 75.97% <88.23%> (+0.02%) ⬆️
Sources/ParseSwift/API/API+Commands.swift 82.58% <100.00%> (+0.24%) ⬆️
...ParseSwift/Objects/ParseInstallation+combine.swift 100.00% <100.00%> (ø)
...urces/ParseSwift/Objects/ParseObject+combine.swift 100.00% <100.00%> (ø)
Sources/ParseSwift/Objects/ParseUser+combine.swift 92.30% <100.00%> (+0.30%) ⬆️
Sources/ParseSwift/Types/ParseCloud.swift 97.43% <100.00%> (ø)
Sources/ParseSwift/Types/ParseConfig.swift 94.52% <100.00%> (ø)
... and 4 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update fb61b78...3e0fdda. Read the comment docs.

@cbaker6
Copy link
Contributor Author

cbaker6 commented Feb 1, 2021

@dplewis a question for you about your PR parse-community/Parse-SDK-JS#631

Can you tell me how the URI should look? My interpretation is that they should be query parameters, so the URI's would look something like:

http://localhost:1337/1/installations/pqHEgVBo4HnreKMiC0Y1CXRCXqb40WUg?include=score

and

http://localhost:1337/1/installations/pqHEgVBo4HnreKMiC0Y1CXRCXqb40WUg?include=*

I'm sure I'm doing something wrong as I'm still getting back pointers.

You can see my test case below:

func testFetchIncludeCommand() {
var score = GameScore(score: 10)
let className = score.className
let objectId = "yarr"
score.objectId = objectId
let includeExpected = ["include": "yolo,test"]
do {
let command = try score.fetchCommand(include: ["yolo", "test"])
XCTAssertNotNil(command)
XCTAssertEqual(command.path.urlComponent, "/classes/\(className)/\(objectId)")
XCTAssertEqual(command.method, API.Method.GET)
XCTAssertEqual(command.params, includeExpected)
XCTAssertNil(command.body)
XCTAssertNil(command.data)
// swiftlint:disable:next line_length
guard let urlExpected = URL(string: "http://localhost:1337/1/classes/GameScore/yarr?include=yolo,test") else {
XCTFail("Should have unwrapped")
return
}
let request = command.prepareURLRequest(options: [])
switch request {
case .success(let url):
XCTAssertEqual(url.url, urlExpected)
case .failure(let error):
XCTFail(error.localizedDescription)
}
} catch {
XCTFail(error.localizedDescription)
}
}

@cbaker6
Copy link
Contributor Author

cbaker6 commented Feb 1, 2021

Maybe I misread, was the PR never merged on the server, only in the JS SDK?

@dplewis
Copy link
Member

dplewis commented Feb 1, 2021

FetchwithInclude is basically like a query with include so it should work on the server.

Are you setting the pointer fields in your test case?

@cbaker6
Copy link
Contributor Author

cbaker6 commented Feb 1, 2021

Are you setting the pointer fields in your test case?

Yes, my output from connecting to an actual server in playgrounds is below:

http://localhost:1337/1/installations/pqHEgVBo4HnreKMiC0Y1CXRCXqb40WUg?include=score
Successfully fetched user with score key: _Installation ({"updatedAt":{"__type":"Date","iso":"2021-02-01T19:57:01.877Z"},"customKey":"myCustomInstallationKey2","parseVersion":"0.0.1","deviceType":"osx","installationId":"de66d713-2bd7-4b59-8389-145706e037fd","localeIdentifier":"en-US","appIdentifier":"com.apple.dt.Xcode.PlaygroundStub-macosx","timeZone":"America\/New_York","appName":"com.apple.dt.Xcode.PlaygroundStub-macosx","targetScore":{"__type":"Pointer","className":"GameScore","objectId":"Wzpfpc5sXQyMdDdgb6YJHOAEAPFuvij4"},"objectId":"pqHEgVBo4HnreKMiC0Y1CXRCXqb40WUg","appVersion":"1","createdAt":{"__type":"Date","iso":"2021-02-01T19:57:01.877Z"},"score":{"__type":"Pointer","className":"GameScore","objectId":"DvyVRuPphLnBMCZAGWpU27nhAHkANayj"}})
http://localhost:1337/1/installations/pqHEgVBo4HnreKMiC0Y1CXRCXqb40WUg?include=*
Successfully fetched user with all keys: _Installation ({"updatedAt":{"__type":"Date","iso":"2021-02-01T19:57:01.877Z"},"customKey":"myCustomInstallationKey2","parseVersion":"0.0.1","deviceType":"osx","installationId":"de66d713-2bd7-4b59-8389-145706e037fd","localeIdentifier":"en-US","appIdentifier":"com.apple.dt.Xcode.PlaygroundStub-macosx","timeZone":"America\/New_York","appName":"com.apple.dt.Xcode.PlaygroundStub-macosx","targetScore":{"__type":"Pointer","className":"GameScore","objectId":"Wzpfpc5sXQyMdDdgb6YJHOAEAPFuvij4"},"objectId":"pqHEgVBo4HnreKMiC0Y1CXRCXqb40WUg","appVersion":"1","createdAt":{"__type":"Date","iso":"2021-02-01T19:57:01.877Z"},"score":{"__type":"Pointer","className":"GameScore","objectId":"DvyVRuPphLnBMCZAGWpU27nhAHkANayj"}})

@cbaker6
Copy link
Contributor Author

cbaker6 commented Feb 1, 2021

FetchwithInclude is basically like a query with include so it should work on the server.

To this point, when fetching a single object, I use .GET and the URI as stated in the REST API docs, but for fetchAll, I use query. I can easily get this working if I use a query for fetching a single object, since I know that works. Is that what it's doing in JS?

@dplewis
Copy link
Member

dplewis commented Feb 1, 2021

I've never tried it with the installation class. I can run some tests

@cbaker6
Copy link
Contributor Author

cbaker6 commented Feb 1, 2021

I tried it with User first, but got the same results. I haven't tried it with a regular parse object on the server.

It's possible I'm making the URI incorrectly.

@cbaker6
Copy link
Contributor Author

cbaker6 commented Feb 2, 2021

@dplewis looks like I had it working. The problem was my debugDescription for print was encoding ParseObjects as back to pointers.

@cbaker6 cbaker6 changed the title Feature: fetchWithInclude Feature: fetch with including specific or all keys Feb 2, 2021
@cbaker6 cbaker6 requested a review from TomWFox February 2, 2021 00:34
@cbaker6
Copy link
Contributor Author

cbaker6 commented Feb 2, 2021

@TomWFox can you review the docs? It's basically the same line added for all fetch methods

@dplewis
Copy link
Member

dplewis commented Feb 2, 2021

Nice! I should add this to the iOS SDK

@cbaker6 cbaker6 merged commit 304af69 into main Feb 2, 2021
@cbaker6 cbaker6 deleted the fetchWithInclude branch February 2, 2021 01:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants