-
Notifications
You must be signed in to change notification settings - Fork 343
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
bug: stream should force observable #59
Comments
Hi @toonvanstrijp yeah, good call out. I've not actually used streams in protobuf on node; I did awhile ago in some protobuf on JVM but kinda forgot about streaming for node so far. :-) I think your initial fix is a good first step... Since you're an NestJS user, can you extend the https://github.com/stephenh/ts-proto/tree/master/integration/nestjs-simple To have an additional And then run the If we have that, I think that's a good enough to accept. I.e. if it works for you and NestJS, I'm fine just having a known-issue that streaming is still unsupported for non-NestJS use cases. Two things:
@GrpcStreamCall()
bidiHello(requestStream: any) {
requestStream.on('data', message => {
console.log(message);
requestStream.write({
reply: 'Hello, world!'
});
});
} Makes me think that, if you use streams (maybe as input parameters?), the service interface is no longer 100% the same for client and server, b/c the server-side method accepts a
At first this test could be just for regular synchronous calls, but then it'd be great especially for these streaming methods, given the APIs can be fairly unintuitive at first. But I'm fine punting on this #2 ask if you don't want to tackle it in the 1st "return |
Great catch @toonvanstrijp , I must admit I don't use the streaming option so I kind of never investigated it - but your fix looks good. I kind of always set everything to Observable :-) Although that's a mistake on my part as others might not want this and then the stream part would fail. @stephenh I believe the client/server API interface can be the same, in-fact that's the way I would use it. Returns an observable and accepts an observable - I think these both work on client/server. The thing is that the implementation supports way more stuff :-)
So it kind of supports a call back on the client according to the nestjs docs. I must admit, I don't use it, so I am not the best person to comment. @toonvanstrijp Can you confirm. Maybe this callback is a kind of edge cases for most systems and not needed or used minimal? Not sure, but if this is the case - then maybe we can say - if you require a custom implementation that doesn't use the generated interface and create it manually - if it's only for 1 or 2 methods. Again - I am not sure the right approach here. Cheers! |
@stephenh @iangregsondev First of all, yes I'll add a test for this inside
As I said I'm quite new to this but we could add an option inside the proto file so you can tell if the
I'm not sure if this is the right way to make this possible, so if you guys have other ideas let me know ;) |
@stephenh I'm trying to run the |
Did you follow this in the readme ? I also had some initial problems but i think it was fixed following this.
|
@iangregsondev ow haha I was running it from the wrong directory. I was doing this: |
Alrighty I'm making some progress and found out that there is a difference between the client / server implementation of If we take the following proto:
And we generate the ts file:
The interface is correct for server implementation. Hover for So the server typescript could look like this:
This way it matches the Then the client typescript file should look like this:
I think when What is your opinion on this? |
@stephenh @iangregsondev As you can see right now I'm doing a ugly type casting here: debugged@7213e8b#diff-f54c909de34198d5f4758846c62e72efR41 But we can solve this by implementing the solution I provided above. |
Yes true, nestjs will convert this to standard object as its going over the wire. There is no such thing as an observable when going over the wire. The main thing it gives you is how to deal with your code inside the service methods, dealing with ASYNC and AWAIT, pure promises, observables or simple objects.
ermm, I never thought of returning union types. I kind of like it :-) Me as a developer can decide to return what I want - but this means it is slightly less typed ah ah. I mean it isn't specifically typed to one return type but to 3 (union) - but I think this works.
I must admit I have never tested it, but are you saying that the client can only receive Observables? Not sure here, the client I think can at least receive standard objects or observables - ?? Maybe I am wrong. I don't really tend to use Promises anyway, but it kind of make sense I think as the information isn't sent over the wire until the promise completes on the server.
I think it would work but implementing 2 x interfaces, 1 for client and 1 for server! I like it, what does @stephenh think? |
I think we have to do a 3 (union) type here cause that we model
Yes the way update
@stephenh @iangregsondev |
update 2
@Controller('hero')
// Generated decorator that applies all the @GrpcMethod and @GrpcStreamMethod to the right methods
@HeroServiceControllerMethods()
export class HeroController implements HeroServiceController {
...
}
|
I agree with pretty much everything in #60 :-) The |
Great work @toonvanstrijp Somebody reported an issue to me last night actually, I don't know if yours fixes this or not. Here reported this in the nestjs discord channel
I still need to confirm it but I must admit I think I overlooked that :-( If you want I can take a look after you have merged? Or you can - let me know either way. |
@iangregsondev It didn't but I've implemented a check for this and now it expects a type |
nice @toonvanstrijp , yep i knew I overlooked that. Thanks! |
Released in v1.20.0. Thanks @toonvanstrijp |
Heey there, I'm quite new to GRPC and protobuffers. Great library btw! I'm using the nestjs feature and it's working great so far!
However I think when defining a
stream
parameter or return type it should be forced to be of typeObservable
right? Cause aPromise
can't support a stream of data.The proto file I have:
As you can see the
FindMany
call takes astream
as input and returns astream
.Right now
ts-proto
outputs this function as followed:You can force the return type by providing this option
--ts_proto_opt=returnObservable=true
but this only changed the return type not the parameter type. Also if you set this option to false and therpc
call returns a stream it should be forced to theObservable
type right?I'm currently looking at the
nestjs
documentation: https://docs.nestjs.com/microservices/grpc#subject-strategyAnd as you can see they wrap the input in an
Observable
and the return type also.fix
I already implemented a fix and can create a pull request for this. But my main question is if we should do this if the
nestJs
option is true or not.debugged@dd5a808
The text was updated successfully, but these errors were encountered: