How can I send and receive Structs in GRPC using NodeJS on both Server and Client

152 views
Skip to first unread message

Bro Bant

unread,
Nov 3, 2022, 5:10:17 AM11/3/22
to grpc.io
I have attempted all I can to send and receive arbitrary data using `google.protobuf.Struct` from NodeJS all to no success.

I am using the official `@grpc/grpc-js` npm package for all my needs.

Below is my proto file:

    message WorkSpaceRequest{
        google.protobuf.Struct body=1;
    }

    message WorkSpaceResponse{
        google.protobuf.Struct workspace=1;
    }

Here is how I sent out the request from a NodeJS Client

       function findById(id) {
          client?.findById({ body: {id:xxxxxx} }, (err, response) => {
               if (err) {
                   console.log(err);
                   return;
               }
               let workspace=response.workspace;
              //Below is the response that keeps coming back
               {
                  "fields": {}
               }
          });
       }

Here is my rpc implementation function:
 

        function findById(call, callback) {
          let {id} = call.request.body; //Id always comes in as undefined even though it has a value to it.
          let sampleWorkspaceSpace = {
            "name": "Sample Workspace Name",
            "id": "Sample Workspace Id"
        }
        callback(null, { workspace: sampleWorkspaceSpace  });
      }

What could I be doing wrong?
Reply all
Reply to author
Forward
0 new messages