【发布时间】:2018-10-19 14:46:53
【问题描述】:
我正在构建一个与 protobuf 集成的 graphql。我有一个 gql 架构,例如:
type User {
userId: ID!,
createTime: DateTime
}
问题是如何仅通过构造函数创建User 消息对象?指定,我想做:
message = new User(['my_user_id', '2018-10-01']).toObject() 以便它将转换为正确的 protobuf 消息对象给我。喜欢:
{
"userId": "my_user_id",
"createTime": {
"seconds": 15000000,
"nanos": 0
}
}
但是,createTime 始终是undefined
试了很多方法,还是不行(顺便说一下nodejs protobuf时间戳的网上资源少之又少)
我试过message = new User(['my_user_id', '2018-10-01T20:23:32.000Z']).toObject() 不工作
我试过message = new User(['my_user_id', new Date()]).toObject(),没用
我试过了
let timestamp = new proto.google.protobuf.Timestamp()
timestamp.setSeconds(1)
timestamp.setNanos(1)
message = new User(['my_user_id',timestamp]).toObject()
也不行
有谁知道正确的方法来做到这一点?非常感谢
【问题讨论】:
标签: node.js protobuf.js