GraphQL Cookbook
Updating an object
10 min
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 https //www back4app com/docs/parse graphql/graphql mutation update object#mutation generic 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 https //www back4app com/docs/parse graphql/graphql mutation update object#mutation class 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 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 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 https //www back4app com/docs/parse graphql/graphql mutation update object#mutation class if your object’s class already has all fields that you want to update this example will only work if you use a classname classname and an objectid objectid of an existing object you can create an object using the creating an object recipe parse 3 8 0 request 1 mutation updateobject { 2 update(classname "hero", objectid "rr8jmfrnks", fields { height 5 6 }) { 3 updatedat 4 } 5 } response 1 { 2 "data" { 3 "updatehero" { 4 "updatedat" "2019 11 04t13 28 44 150z" 5 } 6 } 7 } 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 https //www back4app com/docs/parse graphql/graphql mutation create object#mutation generic recipe), parse server instantly adds to your graphql api a new update\<classname> 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 objectid or id 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 1 mutation updateobject { 2 updatehero(input { 3 id "sgvybzpvrm5tvdm1ynbp" 4 fields { 5 height 5 6 6 } 7 }){ 8 hero{ 9 updatedat 10 } 11 } 12 } response 1 { 2 "data" { 3 "updatehero" { 4 "hero" { 5 "updatedat" "2020 02 06t13 31 49 866z" 6 } 7 } 8 } 9 } older parse server versions parse 3 9 0 class mutation parse server 3 9 0 1 mutation updateobject { 2 updatehero(id "ckhurmmjzw" fields { 3 height 5 6 4 }){ 5 updatedat 6 } 7 } result parse 3 9 0 1 { 2 "data" { 3 "updatehero" { 4 "updatedat" "2019 11 04t13 30 20 457z" 5 } 6 } 7 } parse 3 8 0 class mutation request 1 mutation updateobject { 2 updatehero(objectid "rr8jmfrnks" fields { 3 height 5 6 4 }){ 5 updatedat 6 } 7 } response 1 { 2 "data" { 3 "updatehero" { 4 "updatedat" "2019 11 04t13 38 46 343z" 5 } 6 } 7 } parse 3 7 2 generic mutation parse server 3 7 2 1 mutation updateobject { 2 objects { 3 update(classname "hero", objectid "ffyobotk85", fields { height 5 6 }) { 4 updatedat 5 } 6 } 7 } result parse 3 7 2 1 { 2 "data" { 3 "objects" { 4 "update" { 5 "updatedat" "2019 07 15t05 57 14 416z" 6 } 7 } 8 } 9 } class mutation parse server 3 7 2 1 mutation updatehero { 2 objects { 3 updatehero(objectid "jjh0aqqjfs", fields { height 3 6 }) { 4 updatedat 5 } 6 } 7 } result parse 3 7 2 1 { 2 "data" { 3 "objects" { 4 "updatehero" { 5 "updatedat" "2019 07 15t05 51 25 572z" 6 } 7 } 8 } 9 }