Repository navigation
Give iOS a typed network client and one read helper (RND-2355) - #3417
Draft
StylianosGakis wants to merge 14 commits into
Draft
StylianosGakis wants to merge 14 commits into
StylianosGakis wants to merge 14 commits into
Conversation
Flavor, DeviceIdFetcher, AccessTokenFetcher and NetworkLogPolicy come from modules the framework links but does not export, so Swift would see them with a module prefix such as Network_clientsNetworkLogPolicy. ObjCName pins the Objective-C name and a plain Swift name. The annotation has no effect on Android or desktop. The two fetchers now say on which threads Kotlin calls them and that an iOS implementation must complete exactly once. (cherry picked from commit dcb65db4a075b2fd2c7494445a3784e86edd21e8, only these declarations; the rest of that commit is the reads experiment)
On iOS the language came in as a free-form tag through LanguageStorage, which Kotlin then guessed from with Language.from, logging a warning on every request for a tag it did not know, and which offered setters Kotlin has no business calling. IosLanguageSource gives Kotlin the Language enum the app shows, asked for each request from any thread. The iOS app owns the setting, so setLanguage on iOS only changes what Kotlin reports. Language gets a plain Swift name; nothing changes on Android or desktop.
The Hedvig-TimeZone header read the zone through kotlinx-datetime, which on iOS links its own time zone database parsing and formatting into the framework. Foundation already knows the device's zone identifier, the same IANA name. Android and desktop send no such header.
Every iOS read goes to the network and the iOS app keeps its own state, so a cache on the Kotlin side only adds risk: a read of the previous member that already had its answer could write it after a session change cleared the store, and the next member's cache-first read would get it. The native client now has no cache at all, so a fetch policy that asks for one is answered from the network. Android and desktop keep theirs; buildHedvigApolloClient takes the cache factory as optional.
(cherry picked from commit 9c58a80 with edits: the umbrella graph and test hunks are dropped, since the native graph here is written later in this series and wires the client itself)
(cherry picked from commit 6f91654 with edits: the umbrella test hunk is dropped)
Building the base HTTP client starts the device id's first DataStore write on the application scope. The test's teardown deleted the data directory under that write, and the uncaught IOException then failed the next runTest in the class. Teardown now waits for the application scope's work before deleting the directory. (cherry picked from commit 90874ec)
(cherry picked from commit 1f6ac94)
Android and desktop keep the public client exactly as added before: on the token-free base HTTP client, with a small cache of its own. The native graph gets the same client without a cache, as its member client, so no logged-out answer is stored on iOS either.
Every read the iOS app makes through Kotlin gets the same contract: one callback, the caller's cancel delivered at once, equal reads joined, and every failure a ReadFailure with a typed kind and reason and the read and operation names, no exception text, so the iOS app can log all of it. Kotlin cannot cancel a suspend function implemented in Swift, so the wait is bounded where Kotlin waits: a caller fails as TIMEOUT after 60 s, and while that read is still stuck in the iOS app's input the same read fails at once as STUCK. A member read belongs to its session and a login or logout ends it as SESSION_ENDED; a logged-out read belongs to none. The client is handed to the read, not chosen by it: a member read's block receives only the member client and a logged-out read's only the token-free one, so a logged-out read cannot send the member's token. The contract lives in commonMain (ReadSessions, SingleFlight, ReadFailure) and its tests run on the JVM too. Only the Objective-C adapter is native: SessionReads returns NativeSuspend from kmp-nativecoroutines-core, whose catalog entry this adds, ReadFailures reads a failure out of the NSError, and IosGraphHolder is the holder Swift keeps, which a feature extends with its own reads without a change here. (adapted from the reads experiment's ios-data-bridge at dcb65db4a0: typed kind and reason instead of strings and a visitor, the logged-out read, the client scopes, the common core and the holder; without SharedDay, SharedMoney, BackendValues, runWithin and the test factories. The catalog entry is cherry-picked from 5191266 without its ScreenModel)
A call's invokeOnCompletion handler can run after its waiter already saw the result, so the next call of that key could join the finished entry and get its old value or failure instead of running again. That made SingleFlightTest flaky on CI. Drop a completed entry when a call starts.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
🤖 AI description
Sits on #3416. What an iOS read needs: the token-free Apollo client from PR 3409 (its commits, authorship kept), iOS Apollo clients without a normalized cache so every read goes to the network and nothing crosses members, plain Swift names for the inputs iOS passes in, a typed Language, and ios-data-bridge with one helper for every read. The block of a read receives its client from the helper: read gives the member client, publicRead only the token-free one. That covers the block's receiver, so a logged-out read must not call code that injects the plain ApolloClient. The read contract (one callback, a bounded wait when a Swift input never answers, equal reads joined, every failure a ReadFailure, login and logout ending member reads) is common code tested on the JVM. Nothing is exported to iOS yet.