protobuf.js icon indicating copy to clipboard operation
protobuf.js copied to clipboard

Is the example rpcImpl in the README.md correct?

Open GeorgeBills opened this issue 6 years ago • 8 comments

The example given is:

const rpcImpl = function(method, requestData, callback) {
  client.makeUnaryRequest(
    method.name,
    arg => arg,
    arg => arg,
    requestData,
    callback
  )
}

That gives a method call to the path "SayHello" which won't actually work against the helloworld example server - it needs to include the namespace and service in the path: "/helloworld.Greeter/SayHello".

The below seems to work for me:

const rpcImpl = function (method, requestData, callback) {
    const service = method.parent, namespace = service.parent;
    client.makeUnaryRequest(
        "/" + namespace.name + "." + service.name + "/" + method.name,
        arg => arg,
        arg => arg,
        requestData,
        callback
    )
}

GeorgeBills avatar May 26 '19 09:05 GeorgeBills

I spent about a day's worth of work before figuring this out on my own. I searched here to find that I'm not the only one. Is this the correct way? If so, we should update the example.

longility avatar Oct 09 '20 03:10 longility

method.parent do not exist anymore. I had to hardcode for now.

longility avatar Oct 09 '20 03:10 longility

@longility `package parentName;

syntax = "proto3";`

if you will use this in your proto file then you will get method.parent

Mohammad-Khalid23 avatar Nov 24 '20 07:11 Mohammad-Khalid23

I do have that @Mohammad-Khalid23 . I'm generating my code like this, which works, but maybe I'm missing something:

pbjs -t static-module -w commonjs -o src/junk-domain/__grpc-stubs__/profile.js ../profile/*.Api/Protos/*.proto
pbts -o src/junk-domain/__grpc-stubs__/profile.d.ts src/junk-domain/__grpc-stubs__/profile.js

I followed this: https://www.npmjs.com/package/protobufjs#pbts-for-typescript

longility avatar Nov 24 '20 10:11 longility

Yeah, I ran into this today as well. I don't have any parent value either. Assuming that there are indeed some cases where that parent value isn't present, isn't this an actual problem with the library, rather than just with the example? Or is the intended usage pattern to capture the namespace & service class in the RPC implementation? That would seem a bit odd to me, given that the name is passed in already.

morcam avatar Dec 05 '20 08:12 morcam

I have the same problem. Is it resolved?

Raylin51 avatar Mar 02 '21 09:03 Raylin51

Correct, this example is no longer accurate. Even the gRPC library is updated and now has more fields on makeUnaryRequest.

hermanbanken avatar Apr 14 '21 14:04 hermanbanken

For f’s sake, since 2021 nobody updated the docs nor solved this issue. Do we really have to manually hack our paths in the fng call, or there is another ticket hidden from the internet that explains how it’s supposed to be used in 2024?

adam-rocska avatar May 27 '24 14:05 adam-rocska