ololo
ololo

Reputation: 2076

Why is google.protobuf.Struct not working on NodeJS?

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?

Upvotes: 1

Views: 295

Answers (0)

Related Questions