Skip to content

Commit d69a78f

Browse files
Update Readme, Changelog, SPM docs (#28)
1 parent 509402b commit d69a78f

File tree

7 files changed

+74
-215
lines changed

7 files changed

+74
-215
lines changed

Changelog.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
1-
1+
# 11.3.0-beta
2+
[added] Initial public beta release of the SDK. For more information visit [Firebase Data Connect](https://firebase.google.com/products/data-connect)
23

README.md

Lines changed: 1 addition & 153 deletions
Original file line numberDiff line numberDiff line change
@@ -16,160 +16,8 @@ Instructions for [Swift Package Manager](https://swift.org/package-manager/) sup
1616
found in the [SwiftPackageManager.md](SwiftPackageManager.md) Markdown file.
1717

1818
## Getting Started
19-
Firebase Data Connect is in Private Preview at no cost for a limited time. Sign up the program at https://firebase.google.com/products/data-connect.
2019

21-
Once you are selected as an allowlist member, you should be able to create a Cloud SQL instance through Firebase Data Connect console.
22-
23-
Here's a quick rundown of steps to get you started. Learn more about details at the official [Getting Started documentation](https://firebase.google.com/docs/data-connect/quickstart).
24-
25-
### 1. Create a new Data Connect service and Cloud SQL instance.
26-
* Go to Firebase Console and select Firebase Data Connect from the Left Navigation bar to create a new Data Connect service and a Cloud SQL instance. You have to be in Blaze plan and you can view the details of pricing at https://firebase.google.com/pricing.
27-
* Select us-central1 region if you want to try out vector search with Data Connect later.
28-
* Your Cloud SQL instance is now to be provisioned, you can view and manage the instance at the Google Cloud console.
29-
30-
### 2. Setup your iOS app and [initialize Firebase](https://firebase.google.com/docs/ios/setup)
31-
32-
#### The following steps will guide you to setup your schema and create query operation that you need for your app. The toolings below will help you to test out your query with dummy data and once you are happy with your query, the tools will help generate client code for that query so you can call directly from your app.
33-
34-
35-
### 3. Set up [Firebase CLI](https://firebase.google.com/docs/cli)
36-
37-
* If you already have CLI, make sure you always update to the latest version
38-
```
39-
npm install -g firebase-tools
40-
```
41-
42-
### 4. Set up VSCode
43-
You will need VS Code and its Firebase extension (VS Code extension) to automatically generate Swift code for your queries.
44-
* Install VS Code
45-
* Download the [extension](https://firebasestorage.googleapis.com/v0/b/firemat-preview-drop/o/vsix%2Ffirebase-vscode-latest.vsix?alt=media) and drag it into the "Extensions" in the Left Navigation bar for installation. Keep in mind double clicking the file won't install.
46-
* Create a fdc folder where you like to have firebase data connect configuration.
47-
```
48-
mkdir fdc
49-
```
50-
* Open VS Code from folder you just created
51-
* Select the Firebase icon on the left and login
52-
* Click on "Run firebase init" button
53-
54-
* Select the first option of Data Connect
55-
* Enter/Select the project, service and database ID you setup on the console
56-
* Enter to select the default connector ID and complete the rest of the process
57-
58-
### 5. Set up generated SDK location
59-
In the connector.yaml file, add the following code to enable swift code to be generated.
60-
61-
```
62-
swiftSdk:
63-
outputDir: "../swift-generated/"
64-
package: "User"
65-
```
66-
* You should see swift code is generated inside the ../swift-generated/User/ folder
67-
68-
### 6. Create a schema and generate some dummy data
69-
* In the schema.gql file, uncomment the schema
70-
```
71-
type User @table(key: "uid") {
72-
uid: String!
73-
name: String!
74-
address: String!
75-
}
76-
```
77-
* On top of the schema User, an "Add data" button start showing up, click on it to generate a User_insert.gql file
78-
* Fill out the fields and click on Run button to run the query to add a user dummy data for testing
79-
80-
### 7. Deploy your schema
81-
* To deploy your schema, you will need your Cloud SQL instance to be ready. You can view the instance at the Cloud Cloud console.
82-
* Select the Firebase icon on the left and Click on the "Deploy all" button to deploy all the schema and operations to backend.
83-
* You can now see your schemas on the Firebase Console.
84-
85-
### 8. Set up a mutation
86-
In the mutations.gql file, uncomment the "CreateUser" query.
87-
* In the CONFIGURATION -> VARIABLES, enter
88-
```
89-
{
90-
"name" : "dummy_name",
91-
"address" : "dummy_address"
92-
}
93-
```
94-
* In the CONFIGURATION -> AUTHENTICATION, select Run as "Authenticated".
95-
* Click on the "Run" button above the query.
96-
* You should see your dummy data is added.
97-
* Select the Firebase icon on the left and Click on the "Deploy all" button to deploy all the schema and operations to backend.
98-
* As you see this operation needs authentication, so you will need to be authenticated with Firebase Authentication in your client app when you call this operation in iOS app.
99-
100-
#### At this point, you have the code generated for the queries you need for your app. Now let's see how you can use the generated query code in your iOS app:
101-
102-
### 9. Adding the generated package to your app project
103-
* Go to File -> Add Package Dependencies -> Add Local
104-
* Navigate to the generated folder and select the "swift-generated/User" folder (You should see a Package.swift file in it).
105-
106-
### 10. Calling the generated code from your app
107-
```
108-
import FirebaseDataConnect
109-
import Users //change this to the name of your generated package
110-
111-
func executeFDCCreateUserQuery() {
112-
Task {
113-
do {
114-
let result = try await DataConnect.defaultConnectorClient.createUserMutationRef(name: "dummyUserName", address: "dummyUserAddress").execute()
115-
} catch {
116-
}
117-
}
118-
}
119-
120-
```
121-
122-
123-
124-
125-
## Development
126-
127-
To develop Firebase software in this repository, ensure that you have at least
128-
the following software:
129-
130-
* Xcode 15.2 (or later)
131-
132-
### Swift Package Manager
133-
* To enable test schemes: `./scripts/setup_spm_tests.sh`
134-
* `open Package.swift` or double click `Package.swift` in Finder.
135-
* Xcode will open the project
136-
* Choose a scheme for a library to build or test suite to run
137-
* Choose a target platform by selecting the run destination along with the scheme
138-
139-
### Code Formatting
140-
141-
To ensure that the code is formatted consistently, run the script
142-
[./scripts/check.sh](https://github.com/firebase/firebase-ios-sdk/blob/main/scripts/check.sh)
143-
before creating a pull request (PR).
144-
145-
GitHub Actions will verify that any code changes are done in a style-compliant
146-
way. Install `clang-format` and `mint`:
147-
148-
```console
149-
brew install clang-format@19
150-
brew install mint
151-
```
152-
153-
### Running Unit Tests
154-
155-
Select a scheme and press Command-u to build a component and run its unit tests.
156-
157-
### Running Sample Apps
158-
To run the sample apps and integration tests, you'll need a valid
159-
`GoogleService-Info.plist
160-
` file. The Firebase Xcode project contains dummy plist
161-
files without real values, but they can be replaced with real plist files. To get your own
162-
`GoogleService-Info.plist` files:
163-
164-
1. Go to the [Firebase Console](https://console.firebase.google.com/)
165-
2. Create a new Firebase project, if you don't already have one
166-
3. For each sample app you want to test, create a new Firebase app with the sample app's bundle
167-
identifier (e.g., `com.google.Database-Example`)
168-
4. Download the resulting `GoogleService-Info.plist` and add it to the Xcode project.
169-
170-
### Coverage Report Generation
171-
172-
For coverage report generation instructions, see [scripts/code_coverage_report/README](scripts/code_coverage_report/README.md) Markdown file.
20+
Learn how to develop on Data Connect - [Quick Start](https://firebase.google.com/docs/data-connect/quickstart).
17321

17422
## Contributing
17523

Sources/DataConnect.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@ public class DataConnect {
3838

3939
// MARK: Static Creation
4040

41+
/// Returns an instance of DataConnect matching the parameters.
42+
/// If a matching instance is found that is returned, otherwise a new instance is created.
4143
public class func dataConnect(app: FirebaseApp? = FirebaseApp.app(),
4244
connectorConfig: ConnectorConfig,
4345
settings: DataConnectSettings = DataConnectSettings(),
@@ -108,6 +110,7 @@ public class DataConnect {
108110

109111
// MARK: Operations
110112

113+
/// Returns a query ref matching the name and variables.
111114
public func query<ResultData: Decodable,
112115
Variable: OperationVariable>(name: String,
113116
variables: Variable,
@@ -119,6 +122,7 @@ public class DataConnect {
119122
return operationsManager.queryRef(for: request, with: resultsDataType, publisher: publisher)
120123
}
121124

125+
/// Returns a Mutation Ref matching the name and specified variables.
122126
public func mutation<ResultData: Decodable,
123127
Variable: OperationVariable>(name: String,
124128
variables: Variable,

Sources/DataConnectError.swift

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,22 +14,24 @@
1414

1515
import Foundation
1616

17+
/// Represents an error returned by the DataConnect service
1718
@available(iOS 15.0, macOS 12.0, tvOS 15.0, watchOS 8.0, *)
1819
public enum DataConnectError: Error {
19-
// no firebase app specified. configure not complete
20+
/// no firebase app specified. configure not complete
2021
case appNotConfigured
2122

23+
/// failed to configure gRPC
2224
case grpcNotConfigured
2325

24-
// failed to decode results from server
26+
/// failed to decode results from server
2527
case decodeFailed
2628

27-
// uuid string length is not correct.
29+
/// Invalid uuid format during encoding / decoding of data
2830
case invalidUUID
2931

30-
// date components specified to initialize LocalDate are invalid
32+
/// date components specified to initialize LocalDate are invalid
3133
case invalidLocalDateFormat
3234

33-
// timestamp components specified to initialize Timestamp are invalid
35+
/// timestamp components specified to initialize Timestamp are invalid
3436
case invalidTimestampFormat
3537
}

Sources/MutationRef.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ struct MutationRequest<Variable: OperationVariable>: OperationRequest {
2525
}
2626
}
2727

28+
/// Represents a predefined graphql mutation identified by name and variables.
2829
@available(iOS 15.0, macOS 12.0, tvOS 15.0, watchOS 8.0, *)
2930
public class MutationRef<ResultData: Decodable, Variable: OperationVariable>: OperationRef {
3031
private var request: any OperationRequest

Sources/QueryRef.swift

Lines changed: 50 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,18 @@ import Foundation
1717
import Combine
1818
import Observation
1919

20+
/// The type of publisher to use for the Query Ref
2021
@available(iOS 15.0, macOS 12.0, tvOS 15.0, watchOS 8.0, *)
2122
public enum ResultsPublisherType {
22-
case auto // automatically determine ObservableQueryRef
23-
case observableObject // pre-iOS 17 ObservableObject
24-
case observableMacro // iOS 17+ Observation framework
23+
/// automatically determine ObservableQueryRef.
24+
/// Tries to pick the iOS 17+ Observation but falls back to ObservableObject
25+
case auto
26+
27+
/// pre-iOS 17 ObservableObject
28+
case observableObject
29+
30+
/// iOS 17+ Observation framework
31+
case observableMacro
2532
}
2633

2734
@available(iOS 15.0, macOS 12.0, tvOS 15.0, watchOS 8.0, *)
@@ -122,10 +129,18 @@ public protocol ObservableQueryRef: QueryRef {
122129
var lastError: DataConnectError? { get }
123130
}
124131

125-
// QueryRef class used with ObservableObject protocol
126-
// data: Published variable that contains bindable results of the query.
127-
// lastError: Published variable that contains DataConnectError if last fetch had error.
128-
// If last fetch was successful, this variable is cleared
132+
/// QueryRef class compatible with ObservableObject protocol
133+
///
134+
/// When the requested publisher is an ObservableObject, the returned query refs will be instances
135+
/// of this class
136+
///
137+
/// This class cannot be instantiated directly. To get an instance, call the
138+
/// ``DataConnect/dataConnect(...)`` function
139+
///
140+
/// This class publishes two vars
141+
/// - ``data``: Published variable that contains bindable results of the query.
142+
/// - ``lastError``: Published variable that contains ``DataConnectError`` if last fetch had error.
143+
/// If last fetch was successful, this variable is cleared
129144
@available(iOS 15.0, macOS 12.0, tvOS 15.0, watchOS 8.0, *)
130145
public class QueryRefObservableObject<
131146
ResultData: Decodable,
@@ -161,27 +176,43 @@ public class QueryRefObservableObject<
161176

162177
// ObservableQueryRef implementation
163178

179+
/// data published by query of type `ResultData`
164180
@Published public private(set) var data: ResultData?
165181

182+
/// Error thrown if error occurs during execution of query. If the last fetch was successful the
183+
/// error is cleared
166184
@Published public private(set) var lastError: DataConnectError?
167185

168186
// QueryRef implementation
169187

188+
/// Executes the query and returns `ResultData`. This will also update the published `data`
189+
/// variable
170190
public func execute() async throws -> OperationResult<ResultData> {
171191
let result = try await baseRef.execute()
172192
return result
173193
}
174194

195+
/// Returns the underlying results publisher.
196+
/// Use this function ONLY if you plan to use the Query Ref outside of SwiftUI context - (UIKit,
197+
/// background updates,...)
175198
public func subscribe() async throws
176199
-> AnyPublisher<Result<ResultData, DataConnectError>, Never> {
177200
return await baseRef.subscribe()
178201
}
179202
}
180203

181-
// QueryRef class compatible with the Observation framework introduced in iOS 17
182-
// data: Published variable that contains bindable results of the query.
183-
// lastError: Published variable that contains DataConnectError if last fetch had error.
184-
// If last fetch was successful, this variable is cleared
204+
/// QueryRef class compatible with the Observation framework introduced in iOS 17
205+
///
206+
/// When the requested publisher is an ObservableMacri, the returned query refs will be instances
207+
/// of this class
208+
///
209+
/// This class cannot be instantiated directly. To get an instance, call the
210+
/// ``DataConnect/dataConnect(...)`` function
211+
///
212+
/// This class publishes two vars
213+
/// - ``data``: Published variable that contains bindable results of the query.
214+
/// - ``lastError``: Published variable that contains ``DataConnectError`` if last fetch had error.
215+
/// If last fetch was successful, this variable is cleared
185216
@available(macOS 14, iOS 17, tvOS 17, watchOS 10, *)
186217
@Observable
187218
public class QueryRefObservation<
@@ -221,17 +252,25 @@ public class QueryRefObservation<
221252

222253
// ObservableQueryRef implementation
223254

255+
/// data published by query of type `ResultData`
224256
public private(set) var data: ResultData?
225257

258+
/// Error thrown if error occurs during execution of query. If the last fetch was successful the
259+
/// error is cleared
226260
public private(set) var lastError: DataConnectError?
227261

228262
// QueryRef implementation
229263

264+
/// Executes the query and returns `ResultData`. This will also update the published `data`
265+
/// variable
230266
public func execute() async throws -> OperationResult<ResultData> {
231267
let result = try await baseRef.execute()
232268
return result
233269
}
234270

271+
/// Returns the underlying results publisher.
272+
/// Use this function ONLY if you plan to use the Query Ref outside of SwiftUI context - (UIKit,
273+
/// background updates,...)
235274
public func subscribe() async throws
236275
-> AnyPublisher<Result<ResultData, DataConnectError>, Never> {
237276
return await baseRef.subscribe()

0 commit comments

Comments
 (0)