首页 > 解决方案 > AWS Amplify Appsync 在创建具有关系的对象时解决错误

问题描述

我正在尝试创建一个具有关系的对象。

我正在使用自动生成的放大突变

当我创建一个没有关系的对象时,操作成功。当我创建具有关系的对象时,操作失败。

我得到的错误信息是

"The variables input contains a field name 'customer' that is not defined for input object type 'CreateCreditcardInput' "

自动生成的突变如下。

export const createCreditcard = `mutation CreateCreditcard($input: CreateCreditcardInput!) {
  createCreditcard(input: $input) {
    id
    number
    expiration
    customer {
      id
      firstName
      lastName
      phone
      address1
      address2
      city
      state
      postcode
      email
      creditcards {
        nextToken
      }
    }
    payment {
      id
      paymentType
      creditcard {
        id
        number
        expiration
      }
      orderAmount
      order {
        id
        date
        orderStatus
      }
    }
  }
}
`;

标签: amazon-web-servicesgraphqlaws-amplify

解决方案


解决方案是将包含关系 ID 的属性从嵌套对象更改为字符串。

产生错误的原件是

{id: "", number: 1212112, expiration: "12/20", customer: {id:"81d86584-e031-41db-9c20-e6d3c5b005a6"}}

现在有效的修正是

{id: "", number: 1212112, expiration: "12/20", creditcardCustomerId: "81d86584-e031-41db-9c20-e6d3c5b005a6"}

推荐阅读