【问题标题】:AWS Amplify Appsync solving error when creating object with relationshipAWS Amplify Appsync 在创建具有关系的对象时解决错误
【发布时间】:2020-02-03 19:24:20
【问题描述】:

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

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

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

我得到的错误信息是

"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-services graphql aws-amplify


    【解决方案1】:

    解决方案是将包含关系 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"}
    

    【讨论】:

    • 提交更新的基本功能。看来aws-amplify 应该为我们处理这个问题,对吧?我必须相信有一种方法可以转换模型,因为我使用的模型与我现在正在更新的查询中的模型相同。 ?
    • 我能想到的最好的想法是编写一个函数,该函数接受一个嵌套对象,然后将其展平以符合 aws-amplify 的要求。嵌套对象的属性树将累积成一个字符串。所以在这个例子中 creditcard.customer.id => creditcardCustomerId
    猜你喜欢
    • 2020-04-28
    • 2020-11-23
    • 2018-12-21
    • 2018-10-27
    • 1970-01-01
    • 1970-01-01
    • 2020-01-07
    • 2013-02-17
    • 2020-07-08
    相关资源
    最近更新 更多