Updating an object
You want to update an existing object in your database through the Parse GraphQL API.
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.
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.
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.9.0 and later does not have the generic method UPDATE. You must use the specific methods below to update objects.
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.