Men*_*des 9 javascript mongoose mongodb graphql
我试图在MongoDB使用中存储UNIX时间戳GraphQL,但它认为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;
}
}
Run Code Online (Sandbox Code Playgroud)
结果:
"errors": [
{
"message": "Int cannot represent non 32-bit signed integer value: 1499484833027",
"locations": [
{
"line": 14,
"column": 5
}
],
"path": [
"addUser",
"creationTimestamp"
]
}
Run Code Online (Sandbox Code Playgroud)
我目前GraphQLInteger在类型定义上使用此字段:
creationTimestamp: {
type: GraphQLInt
}
Run Code Online (Sandbox Code Playgroud)
如果没有更大的GraphQLInt可用空间,我该如何解决这种情况GraphQL?
\xe2\x9a\xa0\xef\xb8\x8f 不推荐,因为可能会损失精度...
\n...但是如果您想要快速修复(也许您没有时间实现自定义标量),您可以使用类型Float而不是Int.
| 归档时间: |
|
| 查看次数: |
6702 次 |
| 最近记录: |