Delete
Content: Delete
User Intent
"I want to delete specific content or bulk delete multiple content items"
Operation
SDK Method:
graphlit.deleteContent(),graphlit.deleteContents(),graphlit.deleteAllContents()GraphQL:
deleteContent,deleteContents,deleteAllContentsmutationsEntity Type: Content
Common Use Cases: Remove outdated content, cleanup test data, bulk deletion by filter
TypeScript (Canonical)
import { Graphlit } from 'graphlit-client';
import { ContentTypes, EntityState, SearchTypes } from 'graphlit-client/dist/generated/graphql-types';
const graphlit = new Graphlit();
// Delete single content by ID
const response = await graphlit.deleteContent('content-id-here');
if (response.deleteContent?.id) {
console.log(`Deleted content: ${response.deleteContent.id}`);
}
// Delete multiple specific content items (by IDs)
const contentIds = ['id-1', 'id-2', 'id-3'];
const bulkResponse = await graphlit.deleteContents(
contentIds,
true // isSynchronous - wait for deletion to complete
);
console.log(`Deleted ${contentIds.length} content items`);
// Delete ALL content (use with caution!)
const deleteAllResponse = await graphlit.deleteAllContents(
true // isSynchronous
);
console.log('All content deleted');Delete single content (snake_case method)
response = await graphlit.deleteContent(id="content-id-here")
Delete multiple content items
content_ids = ["id-1", "id-2", "id-3"] bulk_response = await graphlit.deleteContents( ids=content_ids, is_synchronous=True )
Delete all content
delete_all_response = await graphlit.deleteAllContents( is_synchronous=True )
**C#**:
```csharp
using Graphlit;
var client = new Graphlit();
// Delete single content (PascalCase method)
var response = await graphlit.DeleteContent("content-id-here");
// Delete multiple content items
var contentIds = new[] { "id-1", "id-2", "id-3" };
var bulkResponse = await graphlit.DeleteContents(
contentIds,
isSynchronous: true
);
// Delete all content
var deleteAllResponse = await graphlit.DeleteAllContents(
isSynchronous: true
);Parameters
deleteContent
id(string): Content ID to delete
deleteContents
ids(string[]): Array of content IDs to deleteisSynchronous(boolean): Wait for deletion to completeDefault:
falseRecommended:
truefor immediate confirmation
deleteAllContents
filter(ContentFilter): Optional filter to delete subset of contentIf omitted, deletes ALL content in project
isSynchronous(boolean): Wait for deletion to completeDefault:
falseRecommended:
true
Response
// deleteContent
{
deleteContent: {
id: string; // ID of deleted content
state: EntityState; // DELETED
}
}
// deleteContents
{
deleteContents: {
ids: string[]; // Array of deleted content IDs
}
}
// deleteAllContents
{
deleteAllContents: {
count: number; // Number of content items deleted
}
}Developer Hints
Deletion is Permanent
There is NO undo for delete operations:
// Once deleted, content cannot be recovered
await graphlit.deleteContent(contentId);
// Content is gone forever - no trash bin, no restoreBest Practice: Query first, confirm IDs, then delete:
// 1. Query to see what will be deleted
const toDelete = await graphlit.queryContents({
types: [ContentTypes.Text],
states: [EntityState.Error]
});
console.log(`Will delete ${toDelete.contents.results.length} error content items`);
// 2. Confirm with user (in production apps)
// if (userConfirmed) { ... }
// 3. Delete
const ids = toDelete.contents.results.map(c => c.id);
await graphlit.deleteContents(ids, true);Synchronous vs Asynchronous Deletion
// Asynchronous (default) - returns immediately
await graphlit.deleteContent(id);
// Deletion happens in background
// Synchronous - waits for deletion to complete
await graphlit.deleteContent(id);
// Only returns when deletion is confirmedFor bulk operations, asynchronous can be faster, but you won't know if/when deletion completes.
🚨 deleteAllContents with Filters
// WITHOUT filter - deletes EVERYTHING (dangerous!)
await graphlit.deleteAllContents(true);
// WITH filter - deletes only matching content (safer)
await graphlit.deleteAllContents(
{
types: [ContentTypes.Text],
states: [EntityState.Error]
},
true
);
// Only deletes text content in error state⚡ Performance Considerations
For large deletions (>100 items):
Use
deleteAllContentswith filter (faster than individual deletes)Use
deleteContentswith batches (more control than deleteAll)
// Slow: Individual deletes
for (const id of contentIds) {
await graphlit.deleteContent(id); // 1 API call per item
}
// Fast: Bulk delete
await graphlit.deleteContents(contentIds, true); // 1 API call totalVariations
1. Delete Content by Filter (Conditional Deletion)
Delete content matching specific criteria:
// Find error content first
const errorContent = await graphlit.queryContents({
states: [EntityState.Error],
limit: 100
});
console.log(`Found ${errorContent.contents.results.length} error content items`);
// Delete using filter (more efficient than individual deletes)
await graphlit.deleteAllContents(
{
states: [EntityState.Error]
},
true
);
console.log('Deleted all error content');2. Delete Old Content (Cleanup)
Remove content older than a certain date:
// Define cutoff date (e.g., 1 year ago)
const oneYearAgo = new Date();
oneYearAgo.setFullYear(oneYearAgo.getFullYear() - 1);
// Query old content
const oldContent = await graphlit.queryContents({
creationDateRange: {
from: new Date('2000-01-01'), // Very old date
to: oneYearAgo
}
});
console.log(`Found ${oldContent.contents.results.length} old content items`);
// Delete old content
const ids = oldContent.contents.results.map(c => c.id);
if (ids.length > 0) {
await graphlit.deleteContents(ids, true);
console.log(`Deleted ${ids.length} old content items`);
}3. Delete Content from Specific Feed
Remove all content from a feed before deleting the feed:
// Get feed
const feeds = await graphlit.queryFeeds();
const feedToDelete = feeds.feeds.results.find(f => f.name === 'Old Feed');
if (feedToDelete) {
// Delete all content from feed
await graphlit.deleteAllContents(
{
feeds: [{ id: feedToDelete.id }]
},
true
);
console.log(`Deleted all content from feed: ${feedToDelete.name}`);
// Now safe to delete the feed itself
await graphlit.deleteFeed(feedToDelete.id);
}4. Batch Delete with Progress Tracking
Delete large number of items with progress updates:
async function batchDeleteWithProgress(contentIds: string[], batchSize: number = 50) {
const batches = [];
for (let i = 0; i < contentIds.length; i += batchSize) {
batches.push(contentIds.slice(i, i + batchSize));
}
console.log(`Deleting ${contentIds.length} items in ${batches.length} batches...`);
for (let i = 0; i < batches.length; i++) {
await graphlit.deleteContents(batches[i], true);
console.log(`Progress: ${((i + 1) / batches.length * 100).toFixed(0)}% (${(i + 1) * batchSize}/${contentIds.length})`);
}
console.log('Deletion complete');
}
// Usage
const allContent = await graphlit.queryContents({ limit: 1000 });
const ids = allContent.contents.results.map(c => c.id);
await batchDeleteWithProgress(ids);5. Safe Delete with Confirmation
Implement confirmation in production:
async function safeDeleteContent(contentId: string) {
// Get content details
const content = await graphlit.getContent(contentId);
console.log('About to delete:');
console.log(` Name: ${content.content.name}`);
console.log(` Type: ${content.content.type}`);
console.log(` Created: ${content.content.creationDate}`);
// In real app, prompt user for confirmation
const confirmed = true; // Replace with actual user confirmation
if (confirmed) {
await graphlit.deleteContent(contentId);
console.log('✓ Content deleted');
} else {
console.log('✗ Deletion cancelled');
}
}6. Delete Test Data
Clean up after testing:
// Delete all content with 'test' in the name
const testContent = await graphlit.queryContents({
search: 'test',
searchType: SearchTypes.Keyword
});
const testIds = testContent.contents.results
.filter(c => c.name.toLowerCase().includes('test'))
.map(c => c.id);
if (testIds.length > 0) {
console.log(`Deleting ${testIds.length} test content items...`);
await graphlit.deleteContents(testIds, true);
console.log('Test data cleaned up');
}7. Delete by Collection
Remove all content in a specific collection:
// Get collection
const collections = await graphlit.queryCollections({ name: 'Temporary Files' });
const collectionId = collections.collections.results[0]?.id;
if (collectionId) {
// Delete all content in collection
await graphlit.deleteAllContents(
{
collections: [{ id: collectionId }]
},
true
);
console.log('Deleted all content in Temporary Files collection');
// Optionally delete the collection itself
await graphlit.deleteCollection(collectionId);
}Common Issues
Issue: Content not found when deleting
Solution: Content may have already been deleted or ID is incorrect. Check with getContent() first.
Issue: Deletion returns success but content still appears in queries
Solution: If using isSynchronous: false, deletion happens in background. Wait a few seconds or use synchronous mode.
Issue: Cannot delete content with "Content is locked" error Solution: Content may be part of an active feed or workflow. Disable/delete the feed first.
Issue: deleteAllContents deletes too much
Solution: Always use a filter when calling deleteAllContents:
// Dangerous - deletes everything
await graphlit.deleteAllContents();
// Safe - deletes only filtered content
await graphlit.deleteAllContents({ states: [EntityState.Error] });Issue: Bulk delete times out
Solution: Delete in smaller batches (50-100 items per batch) or use isSynchronous: false.
Production Example
Single deletion:
await graphlit.deleteContent(contentId);
console.log(`Successfully deleted content ${contentId}`);Bulk deletion:
await graphlit.deleteContents(contentIds, true);
console.log(`Deleted ${contentIds.length} content items`);Filtered deletion with count:
const response = await graphlit.deleteAllContents(
{ states: [EntityState.Error] },
true
);
console.log(`Deleted ${response.deleteAllContents.count} error content items`);Last updated
Was this helpful?