Automatically Choose Create/Update Query on AWS AppSync in Swift

159 views Asked by At

The user can create and edit his profile with TextFields:

  • Username
  • Nickname
  • Biography

When the user presses the "Save" button, the app saves this data on AWS AppSync. If this is the first time the user enters this data the app should call createData(), otherwise it should call updateData().

Currently I choose between the two methods manually while testing the app. Is there a way to do this automatically? and let the app know if this row of the dynamoDB table has been already created or not?

    @IBAction func saveBtnTapped(_ sender: Any) {

        //How to choose automatically between these two methods?

        createData()
        // updateData()
    }

    func createData() {

        appSyncClient?.perform(mutation: CreateUserMutation(input: createQuery)) {

    }

    func updateData() {

        appSyncClient?.perform(mutation: UpdateUserMutation(input: updateQuery))

    }

This data is optional so I don't force the user to fill it when the account is being created. For authentication I am using Amazon Cognito Hosted UI. .

0

There are 0 answers