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

Pass safe and idempotent options to the MethodDescriptor #1774

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

igor-vovk
Copy link

@igor-vovk igor-vovk commented Nov 28, 2024

Hi! I'm working on the library that provides ConnectRPC-compatible REST interface from ScalaPB service interfaces https://github.com/igor-vovk/connect-rpc-scala.

One of the nice features of the Connect protocol is being able to expose endpoints so they are reachable with GET-requests instead of POST (https://connectrpc.com/docs/protocol/#unary-get-request). It is controlled by the idempotency_level option. This PR adds passing this option to the MethodDefinition, so that https://github.com/igor-vovk/connect-rpc-scala/pull/14/files#diff-c75d247c647e264575f9907d360db7a0769a44833b041a1a540b2eb7592ca656R71 would be possible.

Sadly I did not find any tests for similar functionality, so I wonder if I should add anything.

@@ -179,12 +180,18 @@ final class GrpcServicePrinter(service: ServiceDescriptor, implicits: Descriptor

val grpcMethodDescriptor = "_root_.io.grpc.MethodDescriptor"

val idempotencyLevel = method.getOptions.getIdempotencyLevel
val safe = idempotencyLevel == IdempotencyLevel.NO_SIDE_EFFECTS
val idempotent = idempotencyLevel == IdempotencyLevel.IDEMPOTENT
Copy link
Contributor

Choose a reason for hiding this comment

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

p.add(
s"""${method.deprecatedAnnotation}val ${method.grpcDescriptor.nameSymbol}: $grpcMethodDescriptor[${method.inputType.scalaType}, ${method.outputType.scalaType}] =
| $grpcMethodDescriptor.newBuilder()
| .setType($grpcMethodDescriptor.MethodType.$methodType)
| .setFullMethodName($grpcMethodDescriptor.generateFullMethodName("${service.getFullName}", "${method.getName}"))
| .setSampledToLocalTracing(true)
| .setSafe($safe)
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we setSafe and setIdempotent only when method.getOptions.hasIdempotencyLevel ? You cal use p.when to emit code conditionally.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants