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

Allow client to specify metadata per call #356

Merged
merged 8 commits into from
Feb 15, 2019
Merged
Show file tree
Hide file tree
Changes from 2 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
20 changes: 20 additions & 0 deletions Sources/Examples/Echo/Generated/echo.grpc.swift
Original file line number Diff line number Diff line change
Expand Up @@ -144,11 +144,19 @@ internal final class Echo_EchoServiceClient: ServiceClientBase, Echo_EchoService
return try Echo_EchoGetCallBase(channel)
.run(request: request, metadata: metadata)
}
internal func get(_ request: Echo_EchoRequest, metadata customMetadata: Metadata?) throws -> Echo_EchoResponse {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you implement my suggestion in the review comments, it should be possible to always have this method take a non-optional Metadata argument.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please use Metadata as the argument for all of these, not Metadata? (in Generator.swift).

return try Echo_EchoGetCallBase(channel)
.run(request: request, metadata: customMetadata ?? self.metadata)
}
/// Asynchronous. Unary.
internal func get(_ request: Echo_EchoRequest, completion: @escaping (Echo_EchoResponse?, CallResult) -> Void) throws -> Echo_EchoGetCall {
return try Echo_EchoGetCallBase(channel)
.start(request: request, metadata: metadata, completion: completion)
}
internal func get(_ request: Echo_EchoRequest, metadata customMetadata: Metadata?, completion: @escaping (Echo_EchoResponse?, CallResult) -> Void) throws -> Echo_EchoGetCall {
return try Echo_EchoGetCallBase(channel)
.start(request: request, metadata: customMetadata ?? self.metadata, completion: completion)
}

/// Asynchronous. Server-streaming.
/// Send the initial message.
Expand All @@ -157,6 +165,10 @@ internal final class Echo_EchoServiceClient: ServiceClientBase, Echo_EchoService
return try Echo_EchoExpandCallBase(channel)
.start(request: request, metadata: metadata, completion: completion)
}
internal func expand(_ request: Echo_EchoRequest, metadata customMetadata: Metadata?, completion: ((CallResult) -> Void)?) throws -> Echo_EchoExpandCall {
return try Echo_EchoExpandCallBase(channel)
.start(request: request, metadata: customMetadata ?? self.metadata, completion: completion)
}

/// Asynchronous. Client-streaming.
/// Use methods on the returned object to stream messages and
Expand All @@ -165,6 +177,10 @@ internal final class Echo_EchoServiceClient: ServiceClientBase, Echo_EchoService
return try Echo_EchoCollectCallBase(channel)
.start(metadata: metadata, completion: completion)
}
internal func collect(metadata customMetadata: Metadata?, completion: ((CallResult) -> Void)?) throws -> Echo_EchoCollectCall {
return try Echo_EchoCollectCallBase(channel)
.start(metadata: customMetadata ?? self.metadata, completion: completion)
}

/// Asynchronous. Bidirectional-streaming.
/// Use methods on the returned object to stream messages,
Expand All @@ -173,6 +189,10 @@ internal final class Echo_EchoServiceClient: ServiceClientBase, Echo_EchoService
return try Echo_EchoUpdateCallBase(channel)
.start(metadata: metadata, completion: completion)
}
internal func update(metadata customMetadata: Metadata?, completion: ((CallResult) -> Void)?) throws -> Echo_EchoUpdateCall {
return try Echo_EchoUpdateCallBase(channel)
.start(metadata: customMetadata ?? self.metadata, completion: completion)
}

}

Expand Down
40 changes: 40 additions & 0 deletions Sources/protoc-gen-swiftgrpc/Generator-Client.swift
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,14 @@ extension Generator {
outdent()
outdent()
println("}")
println("\(access) func \(methodFunctionName)(_ request: \(methodInputName), metadata customMetadata: Metadata?) throws -> \(methodOutputName) {")
indent()
println("return try \(callName)Base(channel)")
indent()
println(".run(request: request, metadata: customMetadata ?? self.metadata)")
outdent()
outdent()
println("}")
}
if asynchronousCode {
println("/// Asynchronous. Unary.")
Expand All @@ -215,6 +223,14 @@ extension Generator {
outdent()
outdent()
println("}")
println("\(access) func \(methodFunctionName)(_ request: \(methodInputName), metadata customMetadata: Metadata?, completion: @escaping (\(methodOutputName)?, CallResult) -> Void) throws -> \(callName) {")
indent()
println("return try \(callName)Base(channel)")
indent()
println(".start(request: request, metadata: customMetadata ?? self.metadata, completion: completion)")
outdent()
outdent()
println("}")
}
case .serverStreaming:
println("/// Asynchronous. Server-streaming.")
Expand All @@ -228,6 +244,14 @@ extension Generator {
outdent()
outdent()
println("}")
println("\(access) func \(methodFunctionName)(_ request: \(methodInputName), metadata customMetadata: Metadata?, completion: ((CallResult) -> Void)?) throws -> \(callName) {")
indent()
println("return try \(callName)Base(channel)")
indent()
println(".start(request: request, metadata: customMetadata ?? self.metadata, completion: completion)")
outdent()
outdent()
println("}")
case .clientStreaming:
println("/// Asynchronous. Client-streaming.")
println("/// Use methods on the returned object to stream messages and")
Expand All @@ -240,6 +264,14 @@ extension Generator {
outdent()
outdent()
println("}")
println("\(access) func \(methodFunctionName)(metadata customMetadata: Metadata?, completion: ((CallResult) -> Void)?) throws -> \(callName) {")
indent()
println("return try \(callName)Base(channel)")
indent()
println(".start(metadata: customMetadata ?? self.metadata, completion: completion)")
outdent()
outdent()
println("}")
case .bidirectionalStreaming:
println("/// Asynchronous. Bidirectional-streaming.")
println("/// Use methods on the returned object to stream messages,")
Expand All @@ -252,6 +284,14 @@ extension Generator {
outdent()
outdent()
println("}")
println("\(access) func \(methodFunctionName)(metadata customMetadata: Metadata?, completion: ((CallResult) -> Void)?) throws -> \(callName) {")
indent()
println("return try \(callName)Base(channel)")
indent()
println(".start(metadata: customMetadata ?? self.metadata, completion: completion)")
outdent()
outdent()
println("}")
}
println()
}
Expand Down