Skip to content

Commit a3ba293

Browse files
feat: add Compass GraphQL API integration (Phase 4) (#146)
* feat: add Compass GraphQL API integration (Phase 4) Add optional API mode alongside existing YAML file mode, allowing the generator to pull components directly from a Compass cloud instance via GraphQL. Includes cursor-based pagination, Basic auth with env var resolution for secrets, and full mapping of API responses to the existing CompassConfig type so downstream code works unchanged. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> * fix: enforce HTTPS for baseUrl and fix custom field value mapping Address review comments: add HTTPS validation on baseUrl to prevent credential leakage to non-HTTPS endpoints, and use nullish coalescing (??) instead of logical OR (||) for custom field values to preserve empty strings. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> * fix: align GraphQL schema with Compass API documentation Corrected field names and response shapes based on Atlassian Compass GraphQL API docs: typeId (not type), labels as objects, fields as array with CompassEnumField fragments, and nodeId (not endNodeAri). Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> * docs: update PLAN.md with GraphQL schema correction details Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> * fix: redact apiToken and email from debug output Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 97037be commit a3ba293

File tree

8 files changed

+796
-45
lines changed

8 files changed

+796
-45
lines changed

PLAN.md

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,7 @@ Test fixtures updated with cross-referencing DEPENDS_ON ARNs:
218218

219219
---
220220

221-
## Phase 4: Compass GraphQL API Integration
221+
## Phase 4: Compass GraphQL API Integration ✅ COMPLETE
222222

223223
**Release**: v0.4.0
224224
**Effort**: High (largest phase)
@@ -342,15 +342,27 @@ function resolveValue(value: string): string {
342342
}
343343
```
344344

345-
### 4.7 — Tests for Phase 4
345+
### 4.7 — Schema corrections (post-implementation validation)
346346

347-
- Mock the GraphQL endpoint (use `msw` or simple fetch mock)
347+
After initial implementation, the GraphQL query and response types were validated against the Atlassian Compass API documentation and community examples. Four field-name mismatches were found and corrected:
348+
349+
- Component type field is `typeId` (not `type`)
350+
- Labels are objects `{ name: string }` (not plain strings)
351+
- Lifecycle/tier fields use the `CompassEnumField` inline fragment: `fields { definition { name } ... on CompassEnumField { value } }` (not `{ lifecycle: { label }, tier: { label } }`)
352+
- Relationship nodes use `nodeId` (not `endNodeAri`)
353+
354+
Helper functions were added to handle the corrected shapes: `extractField()` searches the fields array by definition name, `mapLifecycle()` normalizes both uppercase (ACTIVE) and title case (Active) values, and `mapTier()` extracts the numeric tier from strings like "Tier 1".
355+
356+
### 4.8 — Tests for Phase 4
357+
358+
- Mock the GraphQL endpoint (simple fetch mock via `vi.stubGlobal`)
348359
- Test that API mode fetches and processes components
349360
- Test pagination (multiple pages)
350361
- Test auth header is correctly formed
351362
- Test env var resolution
352363
- Test error handling (401, 403, 429 rate limit, network errors)
353364
- Test that YAML mode still works unchanged
365+
- All mocks use corrected response shapes matching actual API
354366

355367
---
356368

@@ -400,7 +412,7 @@ If Compass provides team/owner data via the API, use `writeTeam()` and `writeUse
400412
| 1 | 0.1.0 | No (new default `overrideExisting: true` is additive) | Richer services, update support, validation | ✅ Complete |
401413
| 2 | 0.2.0 | No (previously errored types now work) | All Compass types supported | ✅ Complete |
402414
| 3 | 0.3.0 | No | Relationship mapping | ✅ Complete |
403-
| 4 | 0.4.0 | No (API mode is opt-in) | Compass API integration | ⏳ Planned |
415+
| 4 | 0.4.0 | No (API mode is opt-in) | Compass API integration | ✅ Complete |
404416
| 5 | 0.5.0 | No | OpenAPI specs, scorecards, MDX, teams | ⏳ Planned |
405417

406418
---
@@ -417,13 +429,13 @@ src/
417429
├── domain.ts # Domain processing (minimal changes)
418430
├── validation.ts # Zod schemas (phase 1)
419431
└── test/
420-
├── plugin.test.ts # Main tests (extended each phase, 34 tests)
432+
├── plugin.test.ts # Main tests (extended each phase, 36 tests)
421433
├── my-service-compass.yml # SERVICE fixture (with DEPENDS_ON refs)
422434
├── my-application-compass.yml # APPLICATION fixture (with DEPENDS_ON refs)
423435
├── my-library-compass.yml # LIBRARY fixture
424436
├── my-capability-compass.yml # CAPABILITY fixture
425437
├── my-other-compass.notsupported.yml # OTHER fixture (with partial DEPENDS_ON refs)
426-
└── compass-api.test.ts # NEW: API client tests (phase 4)
438+
└── compass-api.test.ts # API client tests (phase 4, 21 tests)
427439
```
428440

429441
---

pnpm-lock.yaml

Lines changed: 32 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)