GraphQL Cookbook

Updating an object

10min

Updating an object through the Parse GraphQL API

Problem

You want to update an existing object in your database through the Parse GraphQL API.

Solution

Using the parse GraphQL, there are two different ways to update an existing object in your database:

  • Using generic mutation - this is the mutation that you must use if you want to set fields that do not belong to your object’s class yet.
  • Using class mutation - this is the recommended mutation if your object’s class already has all fields that you want to update.

Version Information

Depending on the version of Parse you choose to run, the GraphQL queries, mutations and results will be slightly different. Please choose the correct example along with the Parse version you are running.

Using generic mutation

When you use the update generic mutation, Parse Server behaves like a schemaless database. It means that you do not need to define all fields of your object beforehand. You just need to send the fields that you want to update, and Parse Server will not only store it, but also learn from it, and automatically create any new field in this object’s class.

Therefore, the objects’ update generic mutation is the method that you must use for updating an existing object if you want to set fields that do not belong to your object’s class yet. You can actually use this mutation for updating any existing object, but we recommend using the class mutation if your object’s class already has all fields that you want to update.

This example will only work if you use a className and an objectId of an existing object. You can create an object using the creating an object recipe.

Parse 3.8.0

Request
Response


Example Parse 3.9.0 and later:

Parse 3.9.0 and later does not have the generic method UPDATE. You must use the specific methods below to update objects.

Using class mutation

Once you have already created your object’s class in your application’s schema (for instance, using the creating an object recipe), Parse Server instantly adds to your GraphQL API a new update<ClassName> mutation to update an existing object of this class.

Therefore, the object’s class mutation is the recommended method for updating an existing object if your object’s class already has all fields that you want to update. Since this mutation knows your class’ data, it will automatically make available for you additional features like code auto-complete and validation. You also don’t need to specify the data types when sending dates, pointers, relations, files, geo points, polygons, or bytes through the class update mutation.

This example will only work if you use a class’ mutation and objectId or id of an existing object. You can create an object using the creating an object recipe. The object’s class must have all fields that you are trying to update. You can create new fields using the generic mutation.

Parse 3.10.0 and later

Request
Response


Older Parse Server Versions