# Query and List Feeds

## Feed: Query and List Feeds

### User Intent

"I want to list all my feeds or find a specific feed by name"

### Operation

* **SDK Method**: `graphlit.queryFeeds()` or `graphlit.getFeed()`
* **GraphQL**: `queryFeeds` or `getFeed` query
* **Entity Type**: Feed
* **Common Use Cases**: List active feeds, find feed by name, check feed status, manage feeds

### TypeScript (Canonical)

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

const graphlit = new Graphlit();

// Query all feeds
const allFeeds = await graphlit.queryFeeds();

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

allFeeds.feeds.results.forEach((feed) => {
  console.log(`- ${feed.name} (${feed.type}): ${feed.state}`);
});

// Query specific feed types
const slackFeeds = await graphlit.queryFeeds({
  types: [FeedTypes.Slack],
});

console.log(`\nSlack feeds: ${slackFeeds.feeds.results.length}`);

// Search by name
const docFeeds = await graphlit.queryFeeds({
  search: 'Documentation',
});

console.log(`\nDocumentation feeds: ${docFeeds.feeds.results.length}`);

// Get specific feed by ID
const feedId = 'feed-id-here';
const feed = await graphlit.getFeed(feedId);

console.log(`\nFeed: ${feed.feed.name}`);
console.log(`Type: ${feed.feed.type}`);
console.log(`State: ${feed.feed.state}`);
```

## Query all feeds (snake\_case)

all\_feeds = await graphlit.queryFeeds()

print(f"Total feeds: {len(all\_feeds.feeds.results)}")

for feed in all\_feeds.feeds.results: print(f"- {feed.name} ({feed.type}): {feed.state}")

## Query by type

slack\_feeds = await graphlit.queryFeeds( filter=FeedFilterInput( types=\[FeedTypes.Slack] ) )

## Get specific feed

feed = await graphlit.getFeed(feed\_id) print(f"Feed: {feed.feed.name}")

````

**C#**:
```csharp
using Graphlit;

var client = new Graphlit();

// Query all feeds (PascalCase)
var allFeeds = await graphlit.QueryFeeds();

Console.WriteLine($"Total feeds: {allFeeds.Feeds.Results.Count}");

foreach (var feed in allFeeds.Feeds.Results)
{
    Console.WriteLine($"- {feed.Name} ({feed.Type}): {feed.State}");
}

// Query by type
var slackFeeds = await graphlit.QueryFeeds(new FeedFilter {
    Types = new[] { FeedSlack }
});

// Get specific feed
var feed = await graphlit.GetFeed(feedId);
Console.WriteLine($"Feed: {feed.Feed.Name}");
````

### Parameters

#### queryFeeds (Optional Filter)

* **`types`** (FeedTypes\[]): Filter by feed type
  * `SLACK`, `GOOGLE`, `RSS`, `WEB`, etc.
* **`search`** (string): Search by feed name
* **`states`** (EntityState\[]): Filter by state
  * `ENABLED`, `DISABLED`

#### getFeed (Required)

* **`id`** (string): Feed ID

### Response

#### queryFeeds

```typescript
{
  feeds: {
    results: Feed[];  // Array of feeds
  }
}

interface Feed {
  id: string;
  name: string;
  type: FeedTypes;
  state: EntityState;
  creationDate: Date;
  // Type-specific config (slack, google, rss, web)
}
```

#### getFeed

```typescript
{
  feed: {
    id: string;
    name: string;
    type: FeedTypes;
    state: EntityState;
    slack?: SlackFeedProperties;
    google?: GoogleFeedProperties;
    rss?: RSSFeedProperties;
    web?: WebFeedProperties;
  }
}
```

### Developer Hints

#### Feed States

```typescript
// Check if feed is active
const feeds = await graphlit.queryFeeds();

feeds.feeds.results.forEach(feed => {
  if (feed.state === EntityState.Enabled) {
    console.log(` ${feed.name} is active`);
  } else {
    console.log(` ${feed.name} is disabled`);
  }
});
```

**Important**: Disabled feeds don't sync new content. Re-enable with `updateFeed()`.

#### Find Feed by Name

```typescript
// Search for feed
const results = await graphlit.queryFeeds({
  search: 'Engineering Slack'
});

if (results.feeds.results.length > 0) {
  const feed = results.feeds.results[0];
  console.log(`Found feed: ${feed.id}`);
} else {
  console.log('Feed not found');
}
```

#### Filter by Type

```typescript
// Get all Slack feeds
const slackFeeds = await graphlit.queryFeeds({
  types: [FeedTypes.Slack]
});

// Get all web crawls
const webFeeds = await graphlit.queryFeeds({
  types: [FeedTypes.Web]
});

// Multiple types
const cloudFeeds = await graphlit.queryFeeds({
  types: [FeedTypes.Site, FeedTypes.Email]
});
```

#### Check Feed Details

```typescript
// Get full feed configuration
const feed = await graphlit.getFeed(feedId);

// Check type-specific config
if (feed.feed.type === FeedTypes.Slack && feed.feed.slack) {
  console.log('Slack channel:', feed.feed.slack.channel);
}

if (feed.feed.type === FeedTypes.Web && feed.feed.web) {
  console.log('Starting URL:', feed.feed.web.uri);
  console.log('Read limit:', feed.feed.web.readLimit);
}
```

### Variations

#### 1. List All Feeds

Get all feeds:

```typescript
const feeds = await graphlit.queryFeeds();

console.log(`You have ${feeds.feeds.results.length} feeds`);
```

#### 2. Filter by Type

Only specific feed types:

```typescript
const slackFeeds = await graphlit.queryFeeds({
  types: [FeedTypes.Slack]
});

console.log('Slack feeds:');
slackFeeds.feeds.results.forEach(feed => {
  console.log(`- ${feed.name}`);
});
```

#### 3. Search by Name

Find feeds matching search:

```typescript
const docFeeds = await graphlit.queryFeeds({
  search: 'docs'
});

console.log(`Found ${docFeeds.feeds.results.length} documentation feeds`);
```

#### 4. Get Feed Details

Retrieve specific feed:

```typescript
const feed = await graphlit.getFeed(feedId);

console.log(`Feed: ${feed.feed.name}`);
console.log(`Type: ${feed.feed.type}`);
console.log(`Created: ${feed.feed.creationDate}`);
console.log(`State: ${feed.feed.state}`);
```

#### 5. List Active Feeds Only

Filter by state:

```typescript
const activeFeeds = await graphlit.queryFeeds({
  states: [EntityState.Enabled]
});

console.log(`Active feeds: ${activeFeeds.feeds.results.length}`);
```

#### 6. Feed Inventory Report

Generate feed summary:

```typescript
const feeds = await graphlit.queryFeeds();

const byType = feeds.feeds.results.reduce((acc, feed) => {
  acc[feed.type] = (acc[feed.type] || 0) + 1;
  return acc;
}, {} as Record<string, number>);

console.log('Feed Inventory:');
Object.entries(byType).forEach(([type, count]) => {
  console.log(`  ${type}: ${count}`);
});

const activeCount = feeds.feeds.results.filter(
  f => f.state === EntityState.Enabled
).length;

console.log(`\nActive: ${activeCount} / ${feeds.feeds.results.length}`);
```

### Common Issues

**Issue**: `Feed not found` error\
**Solution**: Verify feed ID is correct. Feed may have been deleted. Use `queryFeeds()` to list all feeds.

**Issue**: Search returns no results\
**Solution**: Search is case-sensitive. Try partial matches. Use `queryFeeds()` without filter to see all feeds.

**Issue**: Wrong feed type returned\
**Solution**: Check `types` filter includes correct FeedTypes enum value.

**Issue**: Feed appears but no content syncing\
**Solution**: Check feed `state`. If `DISABLED`, feed is not syncing. Re-enable with `updateFeed()`.

### Production Example

**Feed management dashboard**:

```typescript
// Get all feeds with details
const feeds = await graphlit.queryFeeds();

console.log('=== FEED INVENTORY ===\n');

// Group by type
const byType = new Map<string, typeof feeds.feeds.results>();

feeds.feeds.results.forEach(feed => {
  const type = feed.type;
  if (!byType.has(type)) {
    byType.set(type, []);
  }
  byType.get(type)!.push(feed);
});

// Print by type
for (const [type, feedList] of byType) {
  console.log(`\n${type} Feeds (${feedList.length}):`);
  
  for (const feed of feedList) {
    const status = feed.state === EntityState.Enabled ? '' : '';
    console.log(`  ${status} ${feed.name} (${feed.id})`);
    
    // Check if syncing is done
    const isDone = await graphlit.isFeedDone(feed.id);
    const syncStatus = isDone.isFeedDone.result ? 'Complete' : 'Syncing';
    console.log(`     Status: ${syncStatus}`);
    
    // Count synced content
    const content = await graphlit.queryContents({
      feeds: [{ id: feed.id }],
      limit: 1  // Just get count
    });
    console.log(`     Content: ${content.contents.results.length} items`);
  }
}
```

**Find and update feed**:

```typescript
// Find feed by name
const results = await graphlit.queryFeeds({
  search: 'Engineering Slack'
});

if (results.feeds.results.length === 0) {
  console.log('Feed not found');
} else {
  const feed = results.feeds.results[0];
  console.log(`Found feed: ${feed.name} (${feed.id})`);
  
  // Get full details
  const fullFeed = await graphlit.getFeed(feed.id);
  
  // Check if it's Slack feed
  if (fullFeed.feed.type === FeedTypes.Slack && fullFeed.feed.slack) {
    console.log('Channels:', fullFeed.feed.slack.channels?.map(c => c.name).join(', '));
  }
  
  // Check sync status
  const isDone = await graphlit.isFeedDone(feed.id);
  console.log(`Sync complete: ${isDone.isFeedDone.result}`);
  
  // Count content
  const content = await graphlit.queryContents({
    feeds: [{ id: feed.id }]
  });
  console.log(`Synced items: ${content.contents.results.length}`);
}
```

**Health check script**:

```typescript
// Check all feeds are healthy
const feeds = await graphlit.queryFeeds();

console.log('=== FEED HEALTH CHECK ===\n');

for (const feed of feeds.feeds.results) {
  const status = {
    name: feed.name,
    type: feed.type,
    enabled: feed.state === EntityState.Enabled,
    syncComplete: false,
    contentCount: 0
  };
  
  // Check sync status
  const isDone = await graphlit.isFeedDone(feed.id);
  status.syncComplete = isDone.isFeedDone.result || false;
  
  // Count content
  const content = await graphlit.queryContents({
    feeds: [{ id: feed.id }]
  });
  status.contentCount = content.contents.results.length;
  
  // Report
  const healthIcon = status.enabled && status.contentCount > 0 ? '' : '';
  console.log(`${healthIcon} ${status.name}`);
  console.log(`   Enabled: ${status.enabled}`);
  console.log(`   Synced: ${status.syncComplete ? 'Yes' : 'In Progress'}`);
  console.log(`   Content: ${status.contentCount} items\n`);
}
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.graphlit.dev/api-guides/use-cases/feeds/feed-query.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
