Daniyal Awan
Daniyal Awan

Reputation: 256

Error updating GraphQL data through mutation in AWS AppSync

I have successfully created data using mutation but when I update that data I am getting this error

Variable 'input' has coerced Null value for NonNull type 'Int!

Here is my query schema

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")
}

Here is the update query

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
  }
}

Here is the code for calling API.

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

In Operation I am sending the update query where as in data I am putting

{ 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: "[email protected]"
    videoInfoReviewed: true 
}}

Upvotes: 1

Views: 1572

Answers (1)

Daniyal Awan
Daniyal Awan

Reputation: 256

I have figured out the issue, expectedVersion property was missing in the input. Just added expectedVersion: 1 and it's good to go. The number must be exact to the version entry present in the current data, you will have to increment it everytime update is called.

Upvotes: 1

Related Questions