【发布时间】:2017-12-12 10:20:31
【问题描述】:
我正在尝试使用 GraphQL 将 UNIX 时间戳存储在 MongoDB 中,但它发现 GraphQL 在处理整数方面存在限制。请参阅下面的突变:
const addUser = {
type: UserType,
description: 'Add an user',
args: {
data: {
name: 'data',
type: new GraphQLNonNull(CompanyInputType)
}
},
resolve(root, params) {
params.data.creationTimestamp = Date.now();
const model = new UserModel(params.data);
const saved = model.save();
if (!saved)
throw new Error('Error adding user');
return saved;
}
}
结果:
"errors": [
{
"message": "Int cannot represent non 32-bit signed integer value: 1499484833027",
"locations": [
{
"line": 14,
"column": 5
}
],
"path": [
"addUser",
"creationTimestamp"
]
}
我目前在类型定义的这个字段中使用GraphQLInteger:
creationTimestamp: {
type: GraphQLInt
}
如果GraphQL 中没有更大的GraphQLInt,我该如何解决?
【问题讨论】:
标签: javascript mongodb mongoose graphql