2017-07-08 170 views
1

我試圖使用GraphQLMongoDB中存儲UNIX時間戳,但它認爲GraphQL有處理整數的限制。請參見下面的突變:GraphQL大整數錯誤:Int不能表示非32位有符號整數值

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" 
     ] 
    } 

I'm目前使用GraphQLInteger對類型定義這個領域:

creationTimestamp: { 
    type: GraphQLInt 
} 

我怎樣才能解決這種情況,如果有沒有更大的GraphQLInt可在GraphQL

回答

4

你可能最好使用像GraphQL Date這樣的自定義標量。還有一個「長」型可用here。或者你可以推出你自己的自定義類型;阿波羅here有一個很好的例子。

如果您想知道爲什麼GraphQL不支持更大的東西,您可以查看this issue on Github

相關問題