GraphQL Cookbook

Deleting an object through the Parse GraphQL API

Problem

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

Solution

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

  • Using generic mutation - this is the mutation that you can use to delete an object of any class.
  • Using class mutation - this is the recommended mutation that you should use to delete an object of a specific class.

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 delete generic mutation, you send the object’s className and objectId, and Parse Server will delete this object.

Therefore, the objects’ delete generic mutation is the one that you can use for deleting an existing object of any class. If you want to delete an existing object of a specific class, we recommend using the class mutation.

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.

1
2
3
mutation DeleteObject {
  delete(className: "Hero", objectId: "rR8jmFRnkS")
}
Result Parse 3.8.0:
1
2
3
4
5
{
  "data": {
    "delete": true
  }
}

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.

1
2
3
4
5
mutation DeleteObject {
  objects {
    delete(className: "Hero", objectId: "ffyOBOTk85")
  }
}
Result Parse 3.7.2:
1
2
3
4
5
6
7
{
  "data": {
    "objects": {
      "delete": true
    }
  }
}
Example Parse 3.9.0 and later:

Parse 3.9.0 and later does not have the generic method DELETE. You must use the specific methods below to delete 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 delete<ClassName> mutation to delete an existing object of this class.

Therefore, the object’s class mutation is the recommended method for deleting an existing object of a specific class.

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.

1
2
3
4
5
6
7
8
9
mutation DeleteObject {
  deleteHero(input:{
    id: "SGVybzpVRm5TVDM1YnBp"
  }){
    hero{
      id
    }
  }
}
Result Parse 3.10.0 and later:
1
2
3
4
5
6
7
8
9
{
  "data": {
    "deleteHero": {
      "hero": {
        "id": "SGVybzpVRm5TVDM1YnBp"
      }
    }
  }
}

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

1
2
3
4
5
mutation DeleteObject {
  deleteHero(id: "CkhurmMjZW"){
    id
  }
}
Result Parse 3.9.0:
1
2
3
4
5
6
7
{
  "data": {
    "deleteHero": {
      "id": "CkhurmMjZW"
    }
  }
}

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

1
2
3
4
5
mutation DeleteObject {
  deleteHero(objectId: "rR8jmFRnkS"){
    objectId
  }
}
Result Parse 3.8.0:
1
2
3
4
5
6
7
{
  "data": {
    "deleteHero": {
      "objectId": "rR8jmFRnkS"
    }
  }
}

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

1
2
3
4
5
mutation DeleteHero {
  objects {
    deleteHero(objectId: "jJH0aQQjfs")
  }
}
Result Parse 3.7.2:
1
2
3
4
5
6
7
{
  "data": {
    "objects": {
      "deleteHero": true
    }
  }
}