Update a Record

Update a single record from the API

Updating existing records is a fundamental operation when maintaining your database's accuracy and relevance. Using Noloco's dynamic GraphQL API, you can seamlessly update entries through GraphQL mutations. This guide will walk you through the process of updating a record using the API.

Update an existing record with the API

To update an existing record, you'll employ a GraphQL mutation in the format mutation update<tableName>, where <tableName> stands for the name of the table containing the record you aim to update.

Examples:

  • For updating an existing project: mutation updateProjects.

  • For modifying a user's details: mutation updateUser.

Specifying the Record ID and Field Values

The primary distinction when updating, as opposed to creating, is that you must include the id argument, which represents the integer ID of the record you wish to update. This ensures you are modifying the correct record.

Additionally, only fields provided with a value will be updated. This behavior is called a "partial update" and ensures you don't overwrite fields unintentionally.

Example:

mutation {
  updateUser(id: 17, firstName: "John", lastName: "Doe") {
    id
    firstName
    lastName
    email
    age
  }
}

In this example, only the firstName and lastName fields of the user with ID 123 is being updated to "Jane" and "Doe". All other fields remain unchanged.

Choosing Response Fields

As with creating or fetching records, after updating, you can decide which fields and values you want to be returned in the response. This aids in verifying that the update operation was successful and reflects the intended changes.

Example:

mutation {
  updateProjects(id: 456, name: "Updated Project Title") {
    id
    name
    createdAt
  }
}

Post update, the response will display the id, name, and updatedAt fields, giving instant feedback about the modified record.

Conclusion

Noloco's dynamic GraphQL API ensures that updating records in your database is both intuitive and efficient. By using mutations tailored for updates and leveraging the ability to perform partial updates, you can ensure that your data remains current, consistent, and accurate without the risk of unintended changes.

Last updated