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

Allow client to specify metadata per call #356

merged 8 commits into from
Feb 15, 2019

Conversation

xissy
Copy link
Contributor

@xissy xissy commented Jan 13, 2019

To address #355 (comment). It also closes #190.

@xissy xissy closed this Jan 13, 2019
@xissy xissy reopened this Jan 13, 2019
Copy link
Collaborator

@MrMage MrMage left a comment

Choose a reason for hiding this comment

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

Thank you for this change!

Please remove the existing methods that do not take a metadata argument from the protocol and add them in an extension instead. That extension can then call through to the new methods, so that we don't need to have separate implementations for the metadata and non-metadata case (because the non-metadata version simply calls through the other one with self.metadata as the metadata argument).

Also, I think the tests (and possibly some auxiliary code as well and/or the test stubs) will need to be updated to make CI pass.

@@ -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).

@xissy
Copy link
Contributor Author

xissy commented Jan 14, 2019

@MrMage Let me know if I missed or did something wrong. As a swift noob, I would follow all your suggestions to learn. Thank you. :)

Copy link
Collaborator

@MrMage MrMage left a comment

Choose a reason for hiding this comment

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

Sorry for the delay, I'm on vacation right now.

Good work! Just two more changes :-)

@@ -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.

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

@@ -33,20 +33,42 @@ fileprivate struct _GeneratedWithProtocGenSwiftVersion: SwiftProtobuf.ProtobufAP
typealias Version = _2
}

struct Echo_EchoRequest: SwiftProtobuf.Message {
static let protoMessageName: String = _protobuf_package + ".EchoRequest"
struct Echo_EchoRequest {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Where do the changes in this file come from?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Possibly using a different version of SwiftProtobuf? I think this file's changes should probably be dropped

@MrMage
Copy link
Collaborator

MrMage commented Jan 22, 2019

Sorry, I thought I had seen changes where you made metadata non-optional, but now I can’t find them. Please make that change.

Also, why did the .pb.swift file change?

@MrMage
Copy link
Collaborator

MrMage commented Jan 22, 2019 via email

@rebello95
Copy link
Collaborator

Any updates on this @xissy? Would be great to get this feature in!

@xissy
Copy link
Contributor Author

xissy commented Jan 31, 2019

Sorry, I've been busy, will update soon.

Copy link
Collaborator

@rebello95 rebello95 left a comment

Choose a reason for hiding this comment

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

Thinking about this a bit more, I wonder if we can remove the extra extension altogether to reduce boilerplate - thoughts? // @MrMage


}

internal extension Echo_EchoService {
Copy link
Collaborator

Choose a reason for hiding this comment

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

@MrMage I know you had suggested putting these functions in a separate extension, but it seems like this adds a bit of boilerplate. Would it make sense to update any generated callers of these functions instead of generating more functions as an extension?

Copy link
Collaborator

Choose a reason for hiding this comment

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

@rebello95 I think these methods are actually called by gRPC users, not by generated code. I'm not super happy about this boilerplate, either, but I don't know how to avoid it if we don't want to force our library's consumers to include this argument with each gRPC call they are going to call. I might be missing something, though; let me know.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Yea that makes sense 👍

Copy link
Collaborator

@MrMage MrMage left a comment

Choose a reason for hiding this comment

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

Looks good to me, but I'd like to finish the discussion with @rebello95 about the generated-code boilerplate (which I don't think could be avoided) this adds before merging.

@rebello95 rebello95 merged commit 3cd505a into grpc:master Feb 15, 2019
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.

Allow client to specify metadata per call
3 participants