Open mpx2m opened 2 years ago
Yep, our grpc-js services already do this, they accept DeepPartial
versions of requests. We just haven't had anyone get around to porting that over to the NestJS services.
...and I assume that would work, i.e. I'm pretty sure we'd still need to invoke FooMessage.fromPartial
within the generated client method. I just haven't looked at the NestJS code in awhile.
A PR would be great.
@stephenh type-fest
package would be great to implement DeepPartial
the generated code show above:
[...]
export interface TestServiceClient {
login(request: LoginRequest, metadata?: Metadata): Observable<LoginResponse>;
}
[...]
After set the flag (new feature) for generating DeepPartial
version requests
import { PartialDeep } from 'type-fest'
[...]
export interface TestServiceClient {
login(request: PartialDeep<LoginRequest>, metadata?: Metadata): Observable<LoginResponse>;
}
[...]
@mpx2m yeah, our grpc-js (or grpc-web...or both...I forget) services already output their own version of DeepPartial
/ PartialDeep
, to avoid a dependency on type-fest
.
It really is a matter of "we have two sets of code for generating service methods, one for grpc-js, one for NestJS, and only the grpc-js uses a DeepPartial".
I don't have time to fix it myself, but if you poke around at the grpc-js/grpc-web service generation, you should be able to update NestJS to do the same.
If there is proto like this:
after
produce
In the NestJS code, if only
name
andpassword
to be used in thelogin
method, typescript code will be writed like blew to meet generated interfaces requirement, many fields have to be filled with undefined:So it would be nicer to allow request message fields to be optional:
but still keep response message as normal (not optional)
above ts code will be simplified like: