Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 0 additions & 10 deletions Protos/Readme

This file was deleted.

70 changes: 70 additions & 0 deletions Protos/Readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
# Data Connect protos
This folder contains the Data Connect protos defining the GRPC service.

# Google Protos
The google protos are obtained from https://github.com/googleapis/googleapis/tree/master

# Instructions to Generate the Swift files for the protos

## Step 1:
(for Googlers) Copy the .proto files from

`third_party/firebase/dataconnect/emulator/server/api/connector_service.proto`

`third_party/firebase/dataconnect/emulator/server/api/graphql_error.proto`


## Step 2:
If needed, adjust package name after discussion with server team.

Make following changes if needed -
- Follow same changes as specified by the copybara lines.
- Where it says strip, take that line out and follow any replace rules with a replace
- If protos reference any internal packages, those are typically not needed by the SDKs or these are marked with copybara strip rules.

## Step 3:
Get the standard protoc compiler and ensure that it is in your system path

## Step 4:
Get the protoc Swift gen plugin from the releases section of Swift GRPC

https://github.com/grpc/grpc-swift/releases

Under the 'Assets' section of a release, download the protoc-grpc-swift-plugins file for macOS.
Example:
protoc-grpc-swift-plugins-1.23.1.zip

## Step 5:
Extract this in a location of your choice. You will need the folder path of the extracted folder.

## Step 6:
Edit the `build_protos.sh` script that is present in the same folder as this Readme file.

Adjust the variables that configure the folder paths needed by the script

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

## Step 7:
Open a Terminal at the folder where the script is and run the build_protos.sh script

`sh build_protos.sh`


## Step 8:
If this script executes successfully (i.e. no errors printed), it will place the generated files in the
`data-connect-ios-sdk/Sources/ProtoGen` folder

If any of the generated Swift files doesn't have the standard License, insert one.

## Step 9:
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

`data-connect-ios-sdk/Sources/Internal/GrpcClient.swift`

`data-connect-ios-sdk/Sources/Internal/Codec.swift`

## Step 10:
Run Integration tests to confirm that the new protos are working fine.



12 changes: 5 additions & 7 deletions Protos/build_protos.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,24 +15,22 @@
# limitations under the License.



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

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


protoc graphql_error.proto connector_service.proto \
--proto_path=$sdk_folder/$sdk_name/Protos/ \
--proto_path=$sdk_folder/Protos/ \
--plugin=$plugin_folder/protoc-gen-swift \
--swift_opt=Visibility=Public \
--swift_out=$sdk_folder/$sdk_name/Sources/ProtoGen \
--swift_out=$sdk_folder/Sources/ProtoGen \
--plugin=$plugin_folder/protoc-gen-grpc-swift \
--grpc-swift_opt=Visibility=Public \
--grpc-swift_out=$sdk_folder/$sdk_name/Sources/ProtoGen
--grpc-swift_out=$sdk_folder/Sources/ProtoGen


32 changes: 12 additions & 20 deletions Protos/connector_service.proto
Original file line number Diff line number Diff line change
Expand Up @@ -16,35 +16,27 @@
//adopted from third_party/firebase/dataconnect/emulator/server/api/connector_service.proto
syntax = "proto3";

package google.firebase.dataconnect.v1alpha;
package google.firebase.dataconnect.v1beta;

import "google/api/annotations.proto";
import "google/api/field_behavior.proto";
import "google/protobuf/struct.proto";
import "graphql_error.proto";

option java_package = "com.google.firebase.dataconnect.v1alpha";
option java_package = "com.google.firebase.dataconnect.v1beta";
option java_multiple_files = true;
option java_outer_classname = "ConnectorServiceProto";


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

Expand All @@ -54,6 +46,10 @@ service ConnectorService {
option (google.api.http) = {
post: "/v1alpha/{name=projects/*/locations/*/services/*/connectors/*}:executeMutation"
body: "*"
additional_bindings {
post: "/v1beta/{name=projects/*/locations/*/services/*/connectors/*}:executeMutation"
body: "*"
}
};
}
}
Expand All @@ -65,9 +61,7 @@ message ExecuteQueryRequest {
// ```
// projects/{project}/locations/{location}/services/{service}/connectors/{connector}
// ```
string name = 1 [
(google.api.field_behavior) = REQUIRED
];
string name = 1 [(google.api.field_behavior) = REQUIRED];

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

// The name of the GraphQL operation name.
// Required because all Connector operations must be named.
Expand Down
5 changes: 2 additions & 3 deletions Protos/graphql_error.proto
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,14 @@

syntax = "proto3";

package google.firebase.dataconnect.v1alpha;
package google.firebase.dataconnect.v1beta;

import "google/protobuf/struct.proto";

option java_package = "com.google.firebase.dataconnect.v1alpha";
option java_package = "com.google.firebase.dataconnect.v1beta";
option java_multiple_files = true;
option java_outer_classname = "GraphqlErrorProto";


// GraphqlError conforms to the GraphQL error spec.
// https://spec.graphql.org/draft/#sec-Errors
//
Expand Down
14 changes: 10 additions & 4 deletions Sources/Internal/Codec.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,12 @@ import Foundation

import SwiftProtobuf

@available(macOS 10.15, iOS 13, tvOS 13, watchOS 6, *)
public typealias FirebaseDataConnectExecuteMutationRequest =
Google_Firebase_Dataconnect_V1beta_ExecuteMutationRequest
public typealias FirebaseDataConnectExecuteQueryRequest =
Google_Firebase_Dataconnect_V1beta_ExecuteQueryRequest

@available(macOS 10.15, iOS 13, tvOS 13, watchOS 6, *)
class Codec {
// Encode Codable to Protos
Expand Down Expand Up @@ -46,14 +52,14 @@ class Codec {
request: QueryRequest<
VariableType
>) throws
-> Google_Firebase_Dataconnect_V1alpha_ExecuteQueryRequest {
-> FirebaseDataConnectExecuteQueryRequest {
do {
var varStruct: Google_Protobuf_Struct? = nil
if let variables = request.variables {
varStruct = try encode(args: variables)
}

let internalRequest = Google_Firebase_Dataconnect_V1alpha_ExecuteQueryRequest.with { ireq in
let internalRequest = FirebaseDataConnectExecuteQueryRequest.with { ireq in
ireq.operationName = request.operationName

if let varStruct {
Expand All @@ -73,14 +79,14 @@ class Codec {
request: MutationRequest<
VariableType
>) throws
-> Google_Firebase_Dataconnect_V1alpha_ExecuteMutationRequest {
-> FirebaseDataConnectExecuteMutationRequest {
do {
var varStruct: Google_Protobuf_Struct? = nil
if let variables = request.variables {
varStruct = try encode(args: variables)
}

let internalRequest = Google_Firebase_Dataconnect_V1alpha_ExecuteMutationRequest
let internalRequest = FirebaseDataConnectExecuteMutationRequest
.with { ireq in
ireq.operationName = request.operationName

Expand Down
8 changes: 6 additions & 2 deletions Sources/Internal/GrpcClient.swift
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ import NIOPosix
import OSLog
import SwiftProtobuf

@available(macOS 10.15, iOS 13, tvOS 13, watchOS 6, *)
public typealias FirebaseDataConnectAsyncClient =
Google_Firebase_Dataconnect_V1beta_ConnectorServiceAsyncClient

@available(macOS 10.15, iOS 13, tvOS 13, watchOS 6, *)
actor GrpcClient: CustomStringConvertible {
nonisolated let description: String
Expand Down Expand Up @@ -56,7 +60,7 @@ actor GrpcClient: CustomStringConvertible {

private let googRequestHeaderValue: String

private lazy var client: Google_Firebase_Dataconnect_V1alpha_ConnectorServiceAsyncClient? = {
private lazy var client: FirebaseDataConnectAsyncClient? = {
do {
FirebaseLogger.dataConnect.debug("\(self.description) initialization starts.")
let group = PlatformSupport.makeEventLoopGroup(loopCount: threadPoolSize)
Expand All @@ -68,7 +72,7 @@ actor GrpcClient: CustomStringConvertible {
eventLoopGroup: group
)
FirebaseLogger.dataConnect.debug("\(self.description) has been created.")
return Google_Firebase_Dataconnect_V1alpha_ConnectorServiceAsyncClient(channel: channel)
return FirebaseDataConnectAsyncClient(channel: channel)
} catch {
FirebaseLogger.dataConnect.error("Error:\(error) when creating \(self.description).")
return nil
Expand Down
Loading