Deleting Data

The easiest way to clean up data is by deleting it through the API. There are three ways to delete objects through the Faros revisions API:

  1. Delete by key: This will delete only the entry that matches the provided key for a given model type.
  2. Delete node by id: This will delete only the entity that matches the node ID for a given model type.
  3. Delete by origin: This will delete ⚠️ALL records⚠️ of a given type that were written by the provided origin. Origin is the ID for the source, UI page, or API command that created the objects.

You’ll first need to construct a GraphQL query to determine the origin or specific key(s) you wish to delete. You’ll then create your delete entries and post them to the revisions api. Specific examples can be found below.

Example: Deleting Phantoms

Delete Team Membership Phantoms by key

  1. Query all the Team Membership entries and filter to those that refer to either a phantom team or a phantom employee.

Query:

query {  
  org {  
    teamMemberships {  
      nodes {  
        team {  
          uid  
          metadata { isPhantom }  
        }  
        member {  
          uid  
          metadata { isPhantom }  
        }  
      }  
    }  
  }  
}

JSONata:
data.org.teamMemberships.nodes[team.metadata.isPhantom or member.metadata.isPhantom]

  1. Note their keys
    Team membership keys are in the form
    {"team":{"uid": <team_uid>}, "member":{"uid":<employee_uid>}}

  2. Construct a deletion entry per key

"org_TeamMembership____Deletion": { "where": {"team":{"uid": "my_team"}, "member":{"uid":"employee1"}} } }

  1. Send a Post request to the /revisions endpoint with your deletion entries
curl -X 'POST'  
  'https://prod.api.faros.ai/graphs/<YOUR_GRAPH>/revisions'  
  -H 'accept: application/json'  
  -H 'authorization: <YOUR_AUTH>'  
  -H 'Content-Type: application/json'  
  -d '{  
  "origin": "manual-deletion",  
  "entries": [  
    { 
      "org_TeamMembership__Deletion":  
      {  
        "where": {  
          "team": { "uid": "my_deleted_team" },  
          "Member": { "uid":"employee1" }  
        }  
      }  
    },  
    { 
      "org_TeamMembership__Deletion":  
      {  
        "where": {  
          "team": { "uid": "my_deleted_team" },  
          "Member": { "uid": "employee2" }  
        }  
      }  
    },  
    { 
      "org_TeamMembership__Deletion":  
      {  
        "where": {  
          "team": { "uid": "team1" },  
          "Member": { "uid": "deleted_employee" }  
        }  
      }  
    }  
  ]  
}'

Delete by node id

  1. Query the node you are looking for in GraphQL. All entities in the Faros graphs are called nodes in GraphQL and all have an ID field (note: this is different from the uid field)
    The query below contains other fields so we can tell which node ID is the one we wish to delete.
{  
  org {  
    boardOwnerships {  
      nodes {  
        id  
        board { uid }  
        team { uid }  
      }  
    }  
  }  
}
  1. Construct a deletion entry for the node ID and model type you wish to delete
    { "<modelName>__Deletion": { "where": { "id": <node_id> } } }
  2. Send a Post request to the revisions endpoint with your deletion entry.
    Note: Make sure you have the schema type set to v2
curl -X 'POST'  
  'https://prod.api.faros.ai/graphs/<YOUR_GRAPH>/revisions'  
  -H 'accept: application/json'  
  -H 'x-faros-revision-entries-version: v2'  
  -H 'authorization: <YOUR_AUTH>'  
  -H 'Content-Type: application/json'  
  -d '{  
  "origin": "manual-deletion",  
  "entries": [  
    {  
      "org_RepositoryOwnership__Deletion": {  
        "where": { "id": <node_id> }  
      }  
    }  
  ]  
}'

Delete by Origin

  1. Query the models you are looking at in GraphQL to understand their origins. Origins are metadata explaining where that entry came from. In general this is the name of the source that wrote the entry, or, if the entry did not come from a source, the name of the page or process responsible.
    {  
      org {  
        boardOwnerships {  
          nodes {  
            metadata { origin } 
            board { uid }  
            team { uid }  
          }  
        }  
      }  
    }
    
  2. Construct a deletion entry for the node ID and model type you wish to delete
    { "<modelName>__Deletion": { "where": <origin> } }
  3. Send a Post request to the revisions endpoint with your deletion entry.

⚠️Warning: deletes ALL of the Repository Ownerships written by the origin⚠️

curl -X 'POST'  
  'https://prod.api.faros.ai/graphs/<YOUR_GRAPH>/revisions'  
  -H 'accept: application/json'  
  -H 'x-faros-revision-entries-version: v2'  
  -H 'authorization: <YOUR_AUTH>'  
  -H 'Content-Type: application/json'  
  -d '{  
  "origin": "manual-deletion",  
  "entries": [  
    {  
      "org_RepositoryOwnership__Deletion": {  
        "where": <origin>  
      }  
    }  
  ]  
}'