feat(microservices): add package definition option to server-grpc #10530
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
PR #8465 added support for packageDefinition for
ClientGrpc
, this PR adds it toServerGrpc
.packageDefinition
logic togetGrpcPackageDefinition
and used it in both gRPC Server & Client, for consistencyGrpcOptions['options']['protoPath']
is now optional -getGrpcPackageDefinition
verifies that eitherprotoPath
orPackageDefinition
existServerGrpc.loadProto
: it was Error, nowInvalidProtoDefinitionException
, as it is inClientGrpc
loadProto
test forServerGrpc
, similar to the one that exists forClientGrpc
PR Checklist
Please check if your PR fulfills the following requirements:
PR Type
What kind of change does this PR introduce?
What is the current behavior?
Currently, it's impossible to create a gRPC microservice by providing a
packageDefinition
, which means statically generated code can't be used — users must provide*.proto
files. This situation isn't suitable for all (e.g. if your organization holds a dedicated repo for Protobufs, rather than storing them in the nestjs-based API repo they're developing, which is quite common).Issue Number: N/A
What is the new behavior?
It's possible to create a gRPC microservice by providing
packageDefinition
.This change is inspired by #8465, which allowed
packageDefinition
to be provided when creating a gRPC client. I think that the fact that the author keptGrpcOptions['options']['protoPath']
as a required field is confusing and inconsistent - even when providingpackageDefinition
, one still needs to provideprotoPath
which will simply be ignored. In this PR I suggest thatprotoPath
will be optional, and when initiating the gRPC server we'll make sure that eitherprotoPath
orpackageDefinition
are supplied. I'd like to hear your thoughts on that.Does this PR introduce a breaking change?
I'm not sure if changing
protoPath
to optional is considered a breaking change... either way, the documentation should be updated as well, so users will know it's notprotoPath
that's required, but eitherprotoPath
orpackageDefinition
. The docs are in a separate repo, right?Other information
I'm open for discussion and willing to move around code (for example, I'm not sure that the
getGrpcPackageDefinition
validation should happen inloadProto
, maybe in the constructor?).Thanks!