-
Notifications
You must be signed in to change notification settings - Fork 17
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
Add method stream type to generated code #172
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,11 +16,6 @@ package com.connectrpc | |
|
||
import kotlin.reflect.KClass | ||
|
||
internal object Method { | ||
internal const val GET_METHOD = "GET" | ||
internal const val POST_METHOD = "POST" | ||
} | ||
|
||
/** | ||
* Represents the minimum set of information to execute an RPC method. | ||
* Primarily used in generated code. | ||
|
@@ -29,12 +24,12 @@ internal object Method { | |
* @param requestClass The Kotlin Class for the request message. | ||
* @param responseClass The Kotlin Class for the response message. | ||
* @param idempotency The declared idempotency of a method. | ||
* @param method The HTTP method of a request. | ||
* @param streamType The method's stream type. | ||
*/ | ||
class MethodSpec<Input : Any, Output : Any>( | ||
val path: String, | ||
val requestClass: KClass<Input>, | ||
val responseClass: KClass<Output>, | ||
val idempotency: Idempotency = Idempotency.UNKNOWN, | ||
val method: String = Method.POST_METHOD, | ||
val streamType: StreamType = StreamType.UNKNOWN, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This unknown value seems a little scary. How will it impact things? Is it necessary for backwards-compatibility with older generated code? What could go wrong if older code is paired with this newer runtime -- would it mean that the GET HTTP verb is never used and interceptors would see the wrong value for stream type? I think it might be safer to make this a non-optional parameter with no default and remove the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I went back and forth on this. Having UNKNOWN also matches connect-go and grpc-java. connect-swift doesn't have an unknown type. It was less about the compatibility with existing generated code as this is still pre-v1 and it should be expected that consumers keep the runtime libraries in sync with the generated code. I'll make the change to make it required. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I know connect-go has this because there's no real support for enums in Go, and it's just good practice for the default/zero value to be a sentinel of this sort. But in kotlin and java, it's much less clear why you'd include one. With grpc-java, it's likely because that supports server-side, too, and if you want to create an "unknown method handler", it's most correct for it to report to handler/interceptor code that the stream type is unknown. |
||
) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
// Copyright 2022-2023 The Connect Authors | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package com.connectrpc | ||
|
||
/** | ||
* Represents the RPC stream type. Set by the code generator on each [MethodSpec]. | ||
*/ | ||
enum class StreamType { | ||
/** Unknown stream type. */ | ||
UNKNOWN, | ||
|
||
/** Unary RPC. */ | ||
UNARY, | ||
|
||
/** Client streaming RPC. */ | ||
CLIENT, | ||
|
||
/** Server streaming RPC. */ | ||
SERVER, | ||
|
||
/** Bidirectional streaming RPC. */ | ||
BIDI, | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -216,7 +216,7 @@ class ProtocolClient( | |
isComplete = true | ||
when (streamResult.code) { | ||
Code.OK -> channel.close() | ||
else -> channel.close(streamResult.connectException() ?: ConnectException(code = streamResult.code)) | ||
else -> channel.close(streamResult.connectException() ?: ConnectException(code = streamResult.code, exception = streamResult.cause)) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There were a few places where we were missing specifying the ConnectException's underlying cause (if set). |
||
} | ||
} | ||
} | ||
|
pkwarren marked this conversation as resolved.
Show resolved
Hide resolved
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This did not make sense to live on the
MethodSpec
- it should have lived on the HTTPRequest. Now theMethodSpec
type only contains fields assigned by the code generator.