0

I would like to be able to read gRPC metadata when making a unary call with the gRPC client. Currently this is already possible with StreamCalls' which is also properly documented, but I can't figure it out with Unary Call's

Consider the following code:

Simplified Provider:

{
    provide: 'SERVICE_GRPC',
    useFactory: () => {
        return ClientProxyFactory.create({
            transport: Transport.GRPC,
            options: {
                package: 'myPackage',
                protoPath: 'my.proto
                url: '127.0.0.1',
            },
        });
    }
},

Simplified Class

interface SomeService {
  someGrpcMethod: (argument: Request) => Observable<Response>;
}

class SomeClass {
  constructor(@Inject('SERVICE_GRPC') private readonly _client: ClientGrpc) {}
  
  onModuleInit(): void {
    this._someService = this._client.getService<SomeService>('SomeService');
  }
  
  someMethod(): void {
    const observer = this._someService.someGrpcMethod({param1:true})
    // Need the metadata send by server here
    observer.subscribe(...);
  }
}

Does anyone know how to do this?

Mazzy
  • 1,901
  • 2
  • 16
  • 36
  • did you ever work this out? – Fred Johnson Jan 31 '22 at 19:44
  • Hi @FredJohnson, I did. It's not supported in NestJS, and NestJS confirmed they don't plan on supporting it(see issue #7847). We ditched the whole gRPC client from NestJS, and ran the offical gRPC package from nodejs. Then used that to pull out the metadata. Same story with their Kafka client we had to ditch. Most stuff they have wrapped is quite limiting.... – Mazzy Jan 31 '22 at 19:48
  • Ah f###! Ok thank you for getting back to me! – Fred Johnson Feb 01 '22 at 08:04

0 Answers0