Skip to content

Conversation

@glbrntt
Copy link
Collaborator

@glbrntt glbrntt commented Jun 30, 2020

Motivation:

The generated protocol for clients allows the caller to optionally pass
in some CallOptions. The generated client conforming to this protocol
defaults this argument to nil and falls back to default options set on
that client in that case.

It is therefore possible to call, for example,
theClient.someUnaryRPC(someRequest) but not
theProtocol.someUnaryRPC(someRequest).

Without explicitly passing the call options, the protocol offers little
value when coding to the protocol rather than to a concrete
implementation.

Modifications:

  • Generated client protocols now extend GRPCClient (previously the
    generated client implementations conformed to GRPCClient and the
    protocol)
  • Generated client protocol requires CallOptions
  • Generated client protocols now have a generated extension for each RPC
    which does not require call options whose implementation forwards the
    default call options courtesy of GRPCClient.

Result:

  • It is possible to reasonably implement code against the generated
    protocol rather than a concrete implementation
  • We lose the ability to call an RPC with callOptions: nil

@glbrntt glbrntt added nio ⚠️ semver/major Breaks existing public API. labels Jun 30, 2020
@glbrntt glbrntt requested a review from Lukasa June 30, 2020 14:14
@glbrntt
Copy link
Collaborator Author

glbrntt commented Jun 30, 2020

Note: 3c6fe84 contains the actual change and a regenerated Echo client. The other commits are just other clients regenerated.

Copy link
Collaborator

@Lukasa Lukasa left a comment

Choose a reason for hiding this comment

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

Great, I generally think this looks good. I've left a few small notes in the diff: nothing major, just some cleanups and thoughts.

@glbrntt glbrntt force-pushed the gb-generated-protocol branch from 0fa5d9d to c310e5c Compare June 30, 2020 15:27
glbrntt added 3 commits June 30, 2020 16:28
Motivation:

The generated protocol for clients allows the caller to optionally pass
in some `CallOptions`. The generated client conforming to this protocol
defaults this argument to `nil` and falls back to default options set on
that client in that case.

It is therefore possible to call, for example,
`theClient.someUnaryRPC(someRequest)` but not
`theProtocol.someUnaryRPC(someRequest)`.

Without explicitly passing the call options, the protocol offers little
value when coding to the protocol rather than to a concrete
implementation.

Modifications:

- Generated client protocols now extend `GRPCClient` (previously the
  generated client implementations conformed to `GRPCClient` and the
  protocol)
- Generated client protocol requires `CallOptions`
- Generated client protocols now have a generated extension for each RPC
  which does not require call options whose implementation forwards the
  default call options courtesy of `GRPCClient`.

Result:

- It is possible to reasonably implement code against the generated
  protocol rather than a concrete implementation
- We lose the ability to call an RPC with `callOptions: nil`
@glbrntt glbrntt force-pushed the gb-generated-protocol branch from c310e5c to aa11601 Compare June 30, 2020 15:28
@glbrntt glbrntt requested a review from Lukasa June 30, 2020 16:07
Copy link
Collaborator

@Lukasa Lukasa left a comment

Choose a reason for hiding this comment

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

Go for it.

@glbrntt glbrntt merged commit fed0094 into grpc:master Jun 30, 2020
@glbrntt glbrntt deleted the gb-generated-protocol branch June 30, 2020 16:15
glbrntt added a commit to glbrntt/grpc-swift that referenced this pull request Jul 1, 2020
Motivation:

When consuming gRPC it is often helpful to be able to write tests that
ensure the client is integrated correctly. At the moment this is only
possible by running a local gRPC server with a custom service handler to
return the responses you would like to test.

Modifications:

This builds on work in grpc#855, grpc#864, and grpc#865.

This pull request introduces code generation for the test clients. It
provides type-safe wrappers and convenience methods on top of
`FakeChannel` and a code-gen option to enable 'TestClient' generation.

It also removes an `init` requirement on the `GRPCClient` protocol.

Result:

Users can generate test clients.
glbrntt added a commit to glbrntt/grpc-swift that referenced this pull request Jul 1, 2020
Motivation:

When consuming gRPC it is often helpful to be able to write tests that
ensure the client is integrated correctly. At the moment this is only
possible by running a local gRPC server with a custom service handler to
return the responses you would like to test.

Modifications:

This builds on work in grpc#855, grpc#864, and grpc#865.

This pull request introduces code generation for the test clients. It
provides type-safe wrappers and convenience methods on top of
`FakeChannel` and a code-gen option to enable 'TestClient' generation.

It also removes an `init` requirement on the `GRPCClient` protocol.

Result:

Users can generate test clients.
glbrntt added a commit to glbrntt/grpc-swift that referenced this pull request Jul 2, 2020
Motivation:

When consuming gRPC it is often helpful to be able to write tests that
ensure the client is integrated correctly. At the moment this is only
possible by running a local gRPC server with a custom service handler to
return the responses you would like to test.

Modifications:

This builds on work in grpc#855, grpc#864, and grpc#865.

This pull request introduces code generation for the test clients. It
provides type-safe wrappers and convenience methods on top of
`FakeChannel` and a code-gen option to enable 'TestClient' generation.

It also removes an `init` requirement on the `GRPCClient` protocol.

Result:

Users can generate test clients.
MrMage pushed a commit that referenced this pull request Jul 3, 2020
* Provide the codegen with an option to generate test clients

Motivation:

When consuming gRPC it is often helpful to be able to write tests that
ensure the client is integrated correctly. At the moment this is only
possible by running a local gRPC server with a custom service handler to
return the responses you would like to test.

Modifications:

This builds on work in #855, #864, and #865.

This pull request introduces code generation for the test clients. It
provides type-safe wrappers and convenience methods on top of
`FakeChannel` and a code-gen option to enable 'TestClient' generation.

It also removes an `init` requirement on the `GRPCClient` protocol.

Result:

Users can generate test clients.

* Regenerate

* fix type, add assertion

* Add "Remaining"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

⚠️ semver/major Breaks existing public API.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants