-
-
Notifications
You must be signed in to change notification settings - Fork 7.6k
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
feat(microservices): add support for grpc reflection api #12899
Conversation
Pull Request Test Coverage Report for Build ac32cf05-85fc-4042-afa2-a4bcb1a35160Details
💛 - Coveralls |
f6b7ea9
to
96638e8
Compare
👍 looking forward to seeing this functionality released! |
@kamilmysliwiec any chance this can be reviewed? |
You can declare a new custom strategy that inherits from the I see no need for lazily loading yet another library when this should be fairly simple to achieve without making any changes to the codebase. |
sure, I can take a pass at one of those options and add to the documentation as a recipe? My thinking in integrating it more deeply into the
imo there's almost no reason to run a gRPC service without reflection these days so given the utility of it and it being central to the grpc-node ecosystem, it might make sense to try and make as frictionless as possible for people to enable? |
But this means adding yet another peer dependency to the I agree that |
yep, that makes sense to me! So between the options we have, making a custom strategy feels a bit heavy-handed and isn't very composable with other changes like this in the future so I'm looking more into how we can inject the reflection service into the existing strategy. Feels like there's two paths here:
export const grpcClientOptions: GrpcOptions = {
transport: Transport.GRPC,
options: {
...
onPreLoadDefinition: (pkg, server) => {
new ReflectionService(pkg).addToServer(server);
}
},
}
const grpcServer = ServerGrpc(grpcClientOptions.options);
grpcServer.onPreLoadDefinition((pkg, server) => {
const reflection = new ReflectionService(pkg);
reflection.addToServer(server);
});
app.connectMicroservice({ strategy: grpcServer }); any preference between these directions or some other path I missed here @kamilmysliwiec? |
Let's pursue the number 1 option (easy to integrate with existing services and compatible with the regular gRPC microservice creation flow - with no need to explicitly import the server class) |
98a2f0c
to
6c8fac7
Compare
6c8fac7
to
f0baed7
Compare
great, just pushed those changes! Added a |
LGTM |
@kamilmysliwiec a little late on this but finally put a PR up to document this new field's usage in nestjs/docs.nestjs.com#3027 |
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?
Issue Number: N/A
What is the new behavior?
Automatically add support for the gRPC reflection API if the user has the
@grpc/reflection
package installedDoes this PR introduce a breaking change?
Other information
I currently maintain a Nest Module package (
nestjs-grpc-reflection
) which adds this capability to a user's app, but opening this PR as a discussion point for whether this makes sense to add to NestJS directly!The gRPC server reflection API exposes information about a gRPC package so that clients can introspect it, this is gaining in popularity in developer tooling such as Postman, grpcui, ezy and so on as it removes the need for developers to manually manage proto file definitions and can instead rely on their client to fetch the correct definition automatically