通过AWS AppSync中的突变错误更新GraphQL数据

时间:2019-03-31 10:08:20

标签: react-native graphql aws-appsync aws-amplify

我已经成功使用突变创建了数据,但是当我更新该数据时却出现此错误

  

变量“输入”已将NonNull类型的“ Int!”强制为Null值。

这是我的查询模式

type SmoothstarRegisteration @model @versioned {
  id: ID!

  active: Boolean!

  type: String!
  registerationSubmitDate: String
  registerationApprovedDate: String
  userId: String!
  videoInfoReviewed: Boolean!

  registerationAttempts: Int!
  registerationStatus: String

  orderNum: String
  orderInfo: OrderInfo @connection(name: "SmoothstarRegisterationOrder")

  address: String
  postCode: String
  region: String
  dateOfBirth: String
  smoothstarModel: String
  purchaseDate: String
  shopName: String
  ocrInfo: OCRInfo @connection(name: "SmoothstarRegisterationOCR")

  privacyPolicyReviewed: Boolean!
  extendedPolicyReviewed: Boolean!
  termsOfUseReviewed: Boolean!

  files: [RegisterationMedia!] @connection(name: "SmoothstarRegisterationMedia")
}

这是更新查询

mutation UpdateSmoothstarRegisteration(
  $input: UpdateSmoothstarRegisterationInput!
) {
  updateSmoothstarRegisteration(input: $input) {
    id
    active
    type
    registerationSubmitDate
    registerationApprovedDate
    userId
    videoInfoReviewed
    registerationAttempts
    registerationStatus
    orderNum
    orderInfo {
      id
      active
      type
      orderNum
    }
    address
    postCode
    region
    dateOfBirth
    smoothstarModel
    purchaseDate
    shopName
    ocrInfo {
      id
      active
      type
      customerId
      customerEmail
      customerPhone
      orderNum
      address
    }
    privacyPolicyReviewed
    extendedPolicyReviewed
    termsOfUseReviewed
    files {
      items {
        id
        version
      }
      nextToken
    }
    version
  }
}

这是调用API的代码。

return API.graphql(graphqlOperation(operation, data))
    .then(response => {
      console.log(`API (${name}) Response => `, response);
      return response;
    })
    .catch(error => {
      throw error;
    });

Operation中,我会将更新查询发送到我要放置的数据中的位置

{ input: {
    active: true
    extendedPolicyReviewed: true
    id: "9dfc480f-7bed-42ed-a585-820f5e8c1485"
    orderNum: "ABCD1234xyz"
    privacyPolicyReviewed: true
    registerationAttempts: 2
    registerationStatus: "registered"
    registerationSubmitDate: "2019-03-31"
    smoothstarRegisterationOrderInfoId: "03b6967d-4b86-4c2d-9115-fb7a40a9c474"
    termsOfUseReviewed: true
    type: "W"
    userId: "m.daniyal.awan@gmail.com"
    videoInfoReviewed: true 
}}

1 个答案:

答案 0 :(得分:1)

我发现了问题,输入中缺少expectedVersion属性。 刚添加了expectedVersion: 1,就很好了。该数字必须与当前数据中存在的版本条目完全相同,您每次调用更新时都必须递增该数字。