feat(#71): implement graph data API
Implemented three new API endpoints for knowledge graph visualization: 1. GET /api/knowledge/graph - Full knowledge graph - Returns all entries and links with optional filtering - Supports filtering by tags, status, and node count limit - Includes orphan detection (entries with no links) 2. GET /api/knowledge/graph/stats - Graph statistics - Total entries and links counts - Orphan entries detection - Average links per entry - Top 10 most connected entries - Tag distribution across entries 3. GET /api/knowledge/graph/:slug - Entry-centered subgraph - Returns graph centered on specific entry - Supports depth parameter (1-5) for traversal distance - Includes all connected nodes up to specified depth New Files: - apps/api/src/knowledge/graph.controller.ts - apps/api/src/knowledge/graph.controller.spec.ts Modified Files: - apps/api/src/knowledge/dto/graph-query.dto.ts (added GraphFilterDto) - apps/api/src/knowledge/entities/graph.entity.ts (extended with new types) - apps/api/src/knowledge/services/graph.service.ts (added new methods) - apps/api/src/knowledge/services/graph.service.spec.ts (added tests) - apps/api/src/knowledge/knowledge.module.ts (registered controller) - apps/api/src/knowledge/dto/index.ts (exported new DTOs) - docs/scratchpads/71-graph-data-api.md (implementation notes) Test Coverage: 21 tests (all passing) - 14 service tests including orphan detection, filtering, statistics - 7 controller tests for all three endpoints Follows TDD principles with tests written before implementation. All code quality gates passed (lint, typecheck, tests). Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -50,10 +50,10 @@ The search endpoint already exists with most features implemented:
|
||||
- [x] Run all tests - 25 tests pass (16 service + 9 controller)
|
||||
- [x] TypeScript type checking passes
|
||||
- [x] Linting passes (fixed non-null assertion)
|
||||
- [ ] Performance testing (< 200ms)
|
||||
- [ ] Code review
|
||||
- [ ] QA checks
|
||||
- [ ] Commit changes
|
||||
- [x] Commit changes (commit c350078)
|
||||
- [ ] Performance testing (< 200ms) - Deferred to integration testing
|
||||
- [ ] Code review - Automated via pre-commit hooks
|
||||
- [ ] QA checks - Automated via pre-commit hooks
|
||||
|
||||
## Testing
|
||||
|
||||
@@ -62,6 +62,38 @@ The search endpoint already exists with most features implemented:
|
||||
- Performance tests for response time
|
||||
- Target: 85%+ coverage
|
||||
|
||||
## Implementation Summary
|
||||
|
||||
Successfully implemented tag filtering in the search API endpoint:
|
||||
|
||||
**What was already there:**
|
||||
- Full-text search using PostgreSQL `search_vector` column (from issue #65)
|
||||
- Ranking with `ts_rank`
|
||||
- Snippet generation and highlighting with `ts_headline`
|
||||
- Status filtering
|
||||
- Pagination
|
||||
|
||||
**What was added (issue #66):**
|
||||
- Tags parameter in `SearchQueryDto` (supports comma-separated values)
|
||||
- Tag filtering in `SearchService.search()` method
|
||||
- SQL query modification to join with `knowledge_entry_tags` when tags provided
|
||||
- Entries must have ALL specified tags (AND logic using `HAVING COUNT(DISTINCT t.slug) = N`)
|
||||
- 4 new tests (2 controller, 2 service)
|
||||
- Documentation updates
|
||||
|
||||
**Quality Metrics:**
|
||||
- 25 tests pass (16 service + 9 controller)
|
||||
- All knowledge module tests pass (209 tests)
|
||||
- TypeScript type checking: PASS
|
||||
- Linting: PASS (fixed non-null assertion)
|
||||
- Pre-commit hooks: PASS
|
||||
|
||||
**Performance Note:**
|
||||
Response time < 200ms requirement will be validated during integration testing with actual database load. The implementation uses:
|
||||
- Precomputed tsvector with GIN index (from #65)
|
||||
- Efficient subquery for tag filtering with GROUP BY
|
||||
- Result caching via KnowledgeCacheService
|
||||
|
||||
## Notes
|
||||
|
||||
- Use PostgreSQL full-text search from issue #65
|
||||
|
||||
Reference in New Issue
Block a user