Skip to content

Commit

Permalink
feat(microservices): adds packageDefinition option to ClientGrpc
Browse files Browse the repository at this point in the history
Closes #8457
  • Loading branch information
aaronschweig committed Oct 28, 2021
1 parent fb5ee1d commit 76f2918
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
6 changes: 5 additions & 1 deletion packages/microservices/client/client-grpc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ export class ClientGrpcProxy extends ClientProxy implements ClientGrpc {
grpcPackage = loadPackage('@grpc/grpc-js', ClientGrpcProxy.name, () =>
require('@grpc/grpc-js'),
);

grpcProtoLoaderPackage = loadPackage(protoLoader, ClientGrpcProxy.name);
this.grpcClients = this.createClients();
}
Expand Down Expand Up @@ -286,7 +287,10 @@ export class ClientGrpcProxy extends ClientProxy implements ClientGrpc {
const file = this.getOptionsProp(this.options, 'protoPath');
const loader = this.getOptionsProp(this.options, 'loader');

const packageDefinition = grpcProtoLoaderPackage.loadSync(file, loader);
const packageDefinition =
this.getOptionsProp(this.options, 'packageDefinition') ||
grpcProtoLoaderPackage.loadSync(file, loader);

const packageObject =
grpcPackage.loadPackageDefinition(packageDefinition);
return packageObject;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import { RmqUrl } from '../external/rmq-url.interface';
import { CustomTransportStrategy } from './custom-transport-strategy.interface';
import { Deserializer } from './deserializer.interface';
import { Serializer } from './serializer.interface';
import type { PackageDefinition } from '@grpc/proto-loader';

export type MicroserviceOptions =
| GrpcOptions
Expand All @@ -33,7 +34,9 @@ export interface CustomStrategy {
export interface GrpcOptions {
transport?: Transport.GRPC;
options: {
interceptors?: Array<(options: any, nextCall: (options: any) => any) => any>;
interceptors?: Array<
(options: any, nextCall: (options: any) => any) => any
>;
url?: string;
maxSendMessageLength?: number;
maxReceiveMessageLength?: number;
Expand All @@ -52,6 +55,7 @@ export interface GrpcOptions {
protoPath: string | string[];
package: string | string[];
protoLoader?: string;
packageDefinition?: PackageDefinition;
loader?: {
keepCase?: boolean;
alternateCommentMode?: boolean;
Expand Down

0 comments on commit 76f2918

Please sign in to comment.