As described in this issue, we can't implement a gRPC client using the Node implementation because "RN is not pure Node".
So I started working on an Objective-C implementation using the Native Modules.
[service postWithRequest:request handler:^(RequestConfirmation * _Nullable response, NSError * _Nullable error) {
if (response) {
// This prints correctly in my JS console
RCTLogInfo(@"%@", response.message);
// This generates an error, see below
resolve(response);
// This works
NSDictionary *formattedResponse = @{
@"id": response.id_p,
@"message": response.message
};
resolve(formattedResponse);
} else {
reject(@"error", @"An error occurred while saving", error);
}
}];
Error :
RCTJSONStringify() encountered the following error: Invalid type in JSON write (RequestConfirmation)
As you can see the problem is with the resolve method. I suppose React does not find any way to convert my proto message to JSON.
How can I keep the response as is and pass it to the resolve method ? Then I can decode it in my JS code.
Thanks.
EDIT 1 :
RequestConfirmation is defined in my proto file like this :
message RequestConfirmation {
string id = 1;
string message = 2;
}
And then it is generated in Objective-C :
@interface RequestConfirmation : GPBMessage
@property(nonatomic, readwrite, copy, null_resettable) NSString *id_p;
@property(nonatomic, readwrite, copy, null_resettable) NSString *message;
@end