Skip to content

Commit 29ddbf2

Browse files
Update protos with v1Beta endpoint and regenerate proto code. (#15)
1 parent e18a148 commit 29ddbf2

File tree

10 files changed

+382
-353
lines changed

10 files changed

+382
-353
lines changed

Protos/Readme

Lines changed: 0 additions & 10 deletions
This file was deleted.

Protos/Readme.md

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
# Data Connect protos
2+
This folder contains the Data Connect protos defining the GRPC service.
3+
4+
# Google Protos
5+
The google protos are obtained from https://github.com/googleapis/googleapis/tree/master
6+
7+
# Instructions to Generate the Swift files for the protos
8+
9+
## Step 1:
10+
(for Googlers) Copy the .proto files from
11+
12+
`third_party/firebase/dataconnect/emulator/server/api/connector_service.proto`
13+
14+
`third_party/firebase/dataconnect/emulator/server/api/graphql_error.proto`
15+
16+
17+
## Step 2:
18+
If needed, adjust package name after discussion with server team.
19+
20+
Make following changes if needed -
21+
- Follow same changes as specified by the copybara lines.
22+
- Where it says strip, take that line out and follow any replace rules with a replace
23+
- If protos reference any internal packages, those are typically not needed by the SDKs or these are marked with copybara strip rules.
24+
25+
## Step 3:
26+
Get the standard protoc compiler and ensure that it is in your system path
27+
28+
## Step 4:
29+
Get the protoc Swift gen plugin from the releases section of Swift GRPC
30+
31+
https://github.com/grpc/grpc-swift/releases
32+
33+
Under the 'Assets' section of a release, download the protoc-grpc-swift-plugins file for macOS.
34+
Example:
35+
protoc-grpc-swift-plugins-1.23.1.zip
36+
37+
## Step 5:
38+
Extract this in a location of your choice. You will need the folder path of the extracted folder.
39+
40+
## Step 6:
41+
Edit the `build_protos.sh` script that is present in the same folder as this Readme file.
42+
43+
Adjust the variables that configure the folder paths needed by the script
44+
45+
Note: If you don't have the protoc compiler in your PATH, you will need specify the full path of the protoc binary in the script above
46+
47+
## Step 7:
48+
Open a Terminal at the folder where the script is and run the build_protos.sh script
49+
50+
`sh build_protos.sh`
51+
52+
53+
## Step 8:
54+
If this script executes successfully (i.e. no errors printed), it will place the generated files in the
55+
`data-connect-ios-sdk/Sources/ProtoGen` folder
56+
57+
If any of the generated Swift files doesn't have the standard License, insert one.
58+
59+
## Step 9:
60+
If the proto package or endpoint names have changed you may get build errors. You will need to adjust the new name in two files
61+
62+
`data-connect-ios-sdk/Sources/Internal/GrpcClient.swift`
63+
64+
`data-connect-ios-sdk/Sources/Internal/Codec.swift`
65+
66+
## Step 10:
67+
Run Integration tests to confirm that the new protos are working fine.
68+
69+
70+

Protos/build_protos.sh

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,24 +15,22 @@
1515
# limitations under the License.
1616

1717

18-
1918
#This is a convenience script to build protos and generate Swift files
2019
#It requires the Swift grpc and proto plugins which are part of swift-grpc project
2120
#Script should be run from the folder containing this script
2221

2322
protoc_path="protoc"
24-
sdk_folder="/Users/aashishp/Code/firebase-private/firebase-ios-sdk"
25-
sdk_name="FirebaseDataConnect"
26-
plugin_folder="/Users/aashishp/Code/grpc-swift/.build/release"
23+
sdk_folder="/Users/aashishp/Code/data-connect-ios-sdk"
24+
plugin_folder="/Users/aashishp/dev/protoc-grpc-swift-plugins-1.23.0/bin"
2725

2826

2927
protoc graphql_error.proto connector_service.proto \
30-
--proto_path=$sdk_folder/$sdk_name/Protos/ \
28+
--proto_path=$sdk_folder/Protos/ \
3129
--plugin=$plugin_folder/protoc-gen-swift \
3230
--swift_opt=Visibility=Public \
33-
--swift_out=$sdk_folder/$sdk_name/Sources/ProtoGen \
31+
--swift_out=$sdk_folder/Sources/ProtoGen \
3432
--plugin=$plugin_folder/protoc-gen-grpc-swift \
3533
--grpc-swift_opt=Visibility=Public \
36-
--grpc-swift_out=$sdk_folder/$sdk_name/Sources/ProtoGen
34+
--grpc-swift_out=$sdk_folder/Sources/ProtoGen
3735

3836

Protos/connector_service.proto

Lines changed: 12 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -16,35 +16,27 @@
1616
//adopted from third_party/firebase/dataconnect/emulator/server/api/connector_service.proto
1717
syntax = "proto3";
1818

19-
package google.firebase.dataconnect.v1alpha;
19+
package google.firebase.dataconnect.v1beta;
2020

2121
import "google/api/annotations.proto";
2222
import "google/api/field_behavior.proto";
2323
import "google/protobuf/struct.proto";
2424
import "graphql_error.proto";
2525

26-
option java_package = "com.google.firebase.dataconnect.v1alpha";
26+
option java_package = "com.google.firebase.dataconnect.v1beta";
2727
option java_multiple_files = true;
2828
option java_outer_classname = "ConnectorServiceProto";
2929

30-
31-
// Firebase Data Connect provides means to deploy a set of predefined GraphQL
32-
// operations (queries and mutations) as a Connector.
33-
//
34-
// Firebase developers can build mobile and web apps that uses Connectors
35-
// to access Data Sources directly. Connectors allow operations without
36-
// admin credentials and help Firebase customers control the API exposure.
37-
//
38-
// Note: `ConnectorService` doesn't check IAM permissions and instead developers
39-
// must define auth policies on each pre-defined operation to secure this
40-
// connector. The auth policies typically define rules on the Firebase Auth
41-
// token.
4230
service ConnectorService {
4331
// Execute a predefined query in a Connector.
4432
rpc ExecuteQuery(ExecuteQueryRequest) returns (ExecuteQueryResponse) {
4533
option (google.api.http) = {
4634
post: "/v1alpha/{name=projects/*/locations/*/services/*/connectors/*}:executeQuery"
4735
body: "*"
36+
additional_bindings {
37+
post: "/v1beta/{name=projects/*/locations/*/services/*/connectors/*}:executeQuery"
38+
body: "*"
39+
}
4840
};
4941
}
5042

@@ -54,6 +46,10 @@ service ConnectorService {
5446
option (google.api.http) = {
5547
post: "/v1alpha/{name=projects/*/locations/*/services/*/connectors/*}:executeMutation"
5648
body: "*"
49+
additional_bindings {
50+
post: "/v1beta/{name=projects/*/locations/*/services/*/connectors/*}:executeMutation"
51+
body: "*"
52+
}
5753
};
5854
}
5955
}
@@ -65,9 +61,7 @@ message ExecuteQueryRequest {
6561
// ```
6662
// projects/{project}/locations/{location}/services/{service}/connectors/{connector}
6763
// ```
68-
string name = 1 [
69-
(google.api.field_behavior) = REQUIRED
70-
];
64+
string name = 1 [(google.api.field_behavior) = REQUIRED];
7165

7266
// The name of the GraphQL operation name.
7367
// Required because all Connector operations must be named.
@@ -87,9 +81,7 @@ message ExecuteMutationRequest {
8781
// ```
8882
// projects/{project}/locations/{location}/services/{service}/connectors/{connector}
8983
// ```
90-
string name = 1 [
91-
(google.api.field_behavior) = REQUIRED
92-
];
84+
string name = 1 [(google.api.field_behavior) = REQUIRED];
9385

9486
// The name of the GraphQL operation name.
9587
// Required because all Connector operations must be named.

Protos/graphql_error.proto

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,14 @@
1616

1717
syntax = "proto3";
1818

19-
package google.firebase.dataconnect.v1alpha;
19+
package google.firebase.dataconnect.v1beta;
2020

2121
import "google/protobuf/struct.proto";
2222

23-
option java_package = "com.google.firebase.dataconnect.v1alpha";
23+
option java_package = "com.google.firebase.dataconnect.v1beta";
2424
option java_multiple_files = true;
2525
option java_outer_classname = "GraphqlErrorProto";
2626

27-
2827
// GraphqlError conforms to the GraphQL error spec.
2928
// https://spec.graphql.org/draft/#sec-Errors
3029
//

Sources/Internal/Codec.swift

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,12 @@ import Foundation
1616

1717
import SwiftProtobuf
1818

19+
@available(macOS 10.15, iOS 13, tvOS 13, watchOS 6, *)
20+
public typealias FirebaseDataConnectExecuteMutationRequest =
21+
Google_Firebase_Dataconnect_V1beta_ExecuteMutationRequest
22+
public typealias FirebaseDataConnectExecuteQueryRequest =
23+
Google_Firebase_Dataconnect_V1beta_ExecuteQueryRequest
24+
1925
@available(macOS 10.15, iOS 13, tvOS 13, watchOS 6, *)
2026
class Codec {
2127
// Encode Codable to Protos
@@ -46,14 +52,14 @@ class Codec {
4652
request: QueryRequest<
4753
VariableType
4854
>) throws
49-
-> Google_Firebase_Dataconnect_V1alpha_ExecuteQueryRequest {
55+
-> FirebaseDataConnectExecuteQueryRequest {
5056
do {
5157
var varStruct: Google_Protobuf_Struct? = nil
5258
if let variables = request.variables {
5359
varStruct = try encode(args: variables)
5460
}
5561

56-
let internalRequest = Google_Firebase_Dataconnect_V1alpha_ExecuteQueryRequest.with { ireq in
62+
let internalRequest = FirebaseDataConnectExecuteQueryRequest.with { ireq in
5763
ireq.operationName = request.operationName
5864

5965
if let varStruct {
@@ -73,14 +79,14 @@ class Codec {
7379
request: MutationRequest<
7480
VariableType
7581
>) throws
76-
-> Google_Firebase_Dataconnect_V1alpha_ExecuteMutationRequest {
82+
-> FirebaseDataConnectExecuteMutationRequest {
7783
do {
7884
var varStruct: Google_Protobuf_Struct? = nil
7985
if let variables = request.variables {
8086
varStruct = try encode(args: variables)
8187
}
8288

83-
let internalRequest = Google_Firebase_Dataconnect_V1alpha_ExecuteMutationRequest
89+
let internalRequest = FirebaseDataConnectExecuteMutationRequest
8490
.with { ireq in
8591
ireq.operationName = request.operationName
8692

Sources/Internal/GrpcClient.swift

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,10 @@ import NIOPosix
2424
import OSLog
2525
import SwiftProtobuf
2626

27+
@available(macOS 10.15, iOS 13, tvOS 13, watchOS 6, *)
28+
public typealias FirebaseDataConnectAsyncClient =
29+
Google_Firebase_Dataconnect_V1beta_ConnectorServiceAsyncClient
30+
2731
@available(macOS 10.15, iOS 13, tvOS 13, watchOS 6, *)
2832
actor GrpcClient: CustomStringConvertible {
2933
nonisolated let description: String
@@ -56,7 +60,7 @@ actor GrpcClient: CustomStringConvertible {
5660

5761
private let googRequestHeaderValue: String
5862

59-
private lazy var client: Google_Firebase_Dataconnect_V1alpha_ConnectorServiceAsyncClient? = {
63+
private lazy var client: FirebaseDataConnectAsyncClient? = {
6064
do {
6165
FirebaseLogger.dataConnect.debug("\(self.description) initialization starts.")
6266
let group = PlatformSupport.makeEventLoopGroup(loopCount: threadPoolSize)
@@ -68,7 +72,7 @@ actor GrpcClient: CustomStringConvertible {
6872
eventLoopGroup: group
6973
)
7074
FirebaseLogger.dataConnect.debug("\(self.description) has been created.")
71-
return Google_Firebase_Dataconnect_V1alpha_ConnectorServiceAsyncClient(channel: channel)
75+
return FirebaseDataConnectAsyncClient(channel: channel)
7276
} catch {
7377
FirebaseLogger.dataConnect.error("Error:\(error) when creating \(self.description).")
7478
return nil

0 commit comments

Comments
 (0)