2

I'm trying to implement two microservices with gRpc, my stack is nestjs and prism.

I have a method that gets a user in the database (findOne), the Prisma does not find the user returns null, but gRpc does not accept the return to null and generates an error that the fields do not exist.

My question is how to implement this in the proto file, when it has data it returns the data, but if the user doesn't exist it returns null.

My error:

enter image description here

My Proto File

syntax = "proto3";

package users;

service UsersService {
  rpc create (UserRequest) returns (UserResponse) {}
  rpc findAll (Empty) returns (UsersResponse) {}
  rpc findOne (UserId) returns (UserResponse) {}
  rpc update (UserRequest) returns (UserResponse) {}
  rpc remove (UserId) returns (RequestResponse) {}
}

message Empty {

}

message UserId {
  string id = 1;
}

message RequestResponse {
  string msg = 1;
}

message UserRequest {
  string id = 1;
  string email = 2;
  string password = 3;
  enum Status {
    INACTIVE = 1;
    ACTIVE = 2;
    BLOCKED = 3;
    DELETED = 4;
  }
  Status status = 4;
}

message UserResponse {
  optional string id = 1;
  optional string email = 2;
  optional string password = 3;
  enum Status {
    INACTIVE = 1;
    ACTIVE = 2;
    BLOCKED = 3;
    DELETED = 4;
  }
  optional Status status = 4;
  optional string createdAt = 5;
  optional string updatedAt = 6;
}

message UsersResponse {
  repeated UserResponse users = 1;
}

message Profile {
  string id = 1;
  string userId = 2;
  string name = 3;
  string birthdate = 4;
  string tin = 5;
  string photo = 6;
  string phone = 7;
}

I try this, but don't work.

message NullableUserResponse {
  oneof kind {
    google.protobuf.NullValue null = 1;
    UserResponse data = 2;
  }
}

Does any gRpc specialist know how I can do it?

Parisa.H.R
  • 3,303
  • 3
  • 19
  • 38
Seta-san
  • 23
  • 3
  • Your error is coming from the server. Have you tried to find where exactly the error comes from in your server code? – murgatroid99 Nov 12 '21 at 18:15

0 Answers0