Query Collections

Collection: Query Collections

User Intent

"I want to list all my collections or find a specific collection by name"

Operation

  • SDK Method: graphlit.queryCollections() or graphlit.getCollection()

  • GraphQL: queryCollections or getCollection query

  • Entity Type: Collection

  • Common Use Cases: List collections, find collection by name, check collection contents

TypeScript (Canonical)

import { Graphlit } from 'graphlit-client';
import { ContentTypes, EntityState } from 'graphlit-client/dist/generated/graphql-types';

const graphlit = new Graphlit();

// Query all collections
const collections = await graphlit.queryCollections();

console.log(`Total collections: ${collections.collections.results.length}`);

collections.collections.results.forEach(coll => {
  console.log(`- ${coll.name} (${coll.state})`);
});

// Search by name
const searchResults = await graphlit.queryCollections({
  search: 'Documentation'
});

console.log(`\nFound ${searchResults.collections.results.length} documentation collections`);

// Get specific collection
// Replace with ID from creating a collection or from queryCollections results above
const collectionId = 'collection-id-here';
const collection = await graphlit.getCollection(collectionId);

console.log(`\nCollection: ${collection.collection.name}`);
console.log(`Created: ${collection.collection.creationDate}`);

// Count content in collection
const contents = await graphlit.queryContents({
  collections: [{ id: collectionId }]
});

console.log(`Content items: ${contents.contents.results.length}`);

Query all collections (snake_case)

collections = await graphlit.queryCollections()

print(f"Total collections: {len(collections.collections.results)}")

for coll in collections.collections.results: print(f"- {coll.name} ({coll.state})")

Search by name

search_results = await graphlit.queryCollections( filter=input_types.CollectionFilter( search="Documentation" ) )

Get specific collection

collection = await graphlit.getCollection(collection_id) print(f"Collection: {collection.collection.name}")

Parameters

queryCollections (Optional Filter)

  • search (string): Search by collection name

  • states (EntityState[]): Filter by state

    • ENABLED, DISABLED

getCollection (Required)

  • id (string): Collection ID

Response

Developer Hints

Collections Don't Store Content Count

Important: Collections don't have a built-in content count. Query contents to count.

Find Collection by Name

Collection Inventory

Variations

1. List All Collections

Get all collections:

2. Search by Name

Find specific collections:

3. Get Collection Details

Retrieve specific collection:

4. Collection with Content Count

Show content counts:

5. Filter Active Collections

Only enabled collections:

Common Issues

Issue: Collection not found error Solution: Verify collection ID is correct. Collection may have been deleted.

Issue: Search returns no results Solution: Search is case-sensitive. Try partial matches.

Issue: Can't see content count Solution: Use queryContents() with collection filter to count items.

Production Example

Collection dashboard:

Last updated

Was this helpful?