【问题标题】:GraphQL: Integer too long? (AWS Amplify/GraphQL Transform)GraphQL:整数太长? (AWS Amplify/GraphQL 转换)
【发布时间】:2020-04-08 08:03:52
【问题描述】:

我使用 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"])
}

【问题讨论】:

    标签: graphql aws-amplify


    【解决方案1】:

    来自the spec

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

    由于 Int 必须是 32 位值,其值不能大于 2147483647。对于值可能高于该值的字段,规范建议:

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

    【讨论】:

    • 啊有趣,这解释了为什么我可以直接在 DynamoDB 中输入更长的整数,而不是通过 GraphQL 突变。谢谢丹尼尔!
    猜你喜欢
    • 2020-07-01
    • 2021-08-31
    • 2019-09-07
    • 2022-01-02
    • 2020-08-12
    • 2020-03-27
    • 2022-08-17
    • 2020-11-23
    • 2020-02-09
    相关资源
    最近更新 更多