GraphQL:整数是否太长? (AWS Amplify / GraphQL转换)

时间:2019-12-15 18:19:12

标签: graphql aws-amplify

我将GraphQL Transform用作AWS Amplify的一部分。现在,我要创建以下突变。但是,看来to整数太长。阅读文档应该可以更长一些。您知道为什么我总是收到错误消息:Validation error of type WrongType: argument 'input.to' with value 'IntValue{value=49160381234}' is not a valid 'Int' @ 'createNumber

mutation createNumber {
  createNumber(input: {
    username: "mymail@gmail.com"
    to: 49160381234
  }) {
    username
    to
  }
}

这是我的架构:

type Message
  @model
  @auth(rules: [{ allow: owner }])
  @key(fields: ["to", "from"]) # `to` as primary index and `from` as sort key.
  @key(
    name: "byToByTimestamp"
    fields: ["to", "timestamp"]
    queryField: "messagesByToByTimestamp"
  ) {
  to: Int!
  from: String!
  medium: String!
  messageBody: String!
  timestamp: Int!
}

type Number
  @model
  @key(fields: ["to"]) # Each number can only exist once.
  @key(
    name: "byUserByTo"
    fields: ["username", "to"]
    queryField: "numberByUserByTo"
  ) {
  username: String!
  to: Int!
  messages: [Message] @connection(keyName: "byToByTimestamp", fields: ["to"])
}

type User @model @key(fields: ["username"]) {
  username: String!
  numbers: [Number] @connection(keyName: "byUserByTo", fields: ["username"])
}

1 个答案:

答案 0 :(得分:0)

来自the spec

  

Int标量类型表示带符号的32位数字非分数值。支持32位整数或数字类型的响应格式应使用该类型来表示此标量...如果整数内部值表示的值小于-2 ^ 31或大于或等于2 ^ 31,则字段错误应该提出。

由于Int必须为32位值,因此其值不能大于2147483647。对于可能具有更高值的字段,规范建议:

  

大于32位的数字整数值应使用String或自定义的标量类型,因为并非所有平台和传输器都支持大于32位的编码整数。