Add and Remove Content
Collection: Add and Remove Content
User Intent
Operation
TypeScript (Canonical)
import { Graphlit } from 'graphlit-client';
import {
ContentTypes,
EntityReferenceInput,
FileTypes,
} from 'graphlit-client/dist/generated/graphql-types';
const graphlit = new Graphlit();
// Assumes you have a collection ID from creating a collection:
// const collection = await graphlit.createCollection({ name: "My Collection" });
// const collectionId = collection.createCollection.id;
const collection: EntityReferenceInput = { id: 'collection-id' };
const contents: EntityReferenceInput[] = [
{ id: 'content-id-1' },
{ id: 'content-id-2' },
{ id: 'content-id-3' },
];
// Add content to collection
await graphlit.addContentsToCollections(contents, [collection]);
console.log(`Added ${contents.length} items to collection`);
// Remove content from collection
await graphlit.removeContentsFromCollection([{ id: 'content-id-1' }], collection);
console.log('Removed 1 item from collection');
// Verify collection contents
const membership = await graphlit.queryContents({
collections: [collection]
});
console.log(`Collection now has ${membership.contents.results.length} items`);Add content to collection (snake_case)
Remove content from collection
Parameters
addContentsToCollections
removeContentsFromCollection
Response
Developer Hints
Add vs Ingestion
Batch Operations
Move Content Between Collections
Content Can Be in Multiple Collections
Variations
1. Add Single Item
2. Add Multiple Items
3. Remove Items
4. Add All Content from Query
5. Reorganize Collections
6. Clear Collection
Common Issues
Production Example
Last updated