Skip to content

feat(backend): add additive GraphQL layer alongside REST API - #20

Open
Alithiel31 wants to merge 1 commit into
mainfrom
claude/graphql-microservices-eval-oiftvr
Open

feat(backend): add additive GraphQL layer alongside REST API#20
Alithiel31 wants to merge 1 commit into
mainfrom
claude/graphql-microservices-eval-oiftvr

Conversation

@Alithiel31

Copy link
Copy Markdown
Owner

Summary

  • Ajoute un endpoint POST /graphql (Apollo Server 5) en plus de la REST API existante — rien n'est retiré, déprécié ou modifié côté /api/*.
  • Query.me reproduit ce que analytics.controller.ts#overview assemble aujourd'hui « à la main » (plusieurs requêtes Prisma en parallèle), mais laisse le client composer exactement la forme imbriquée dont il a besoin (me { medications { intakes } } , dailyEntries { symptomLogs { symptom } }, labResults).
  • Auth JWT pontée depuis middleware/auth.ts dans le contexte GraphQL (src/graphql/context.ts).
  • Anti-N+1 avec DataLoader (src/graphql/dataloaders.ts) sur Medication.intakes et DailyEntry.symptomLogs, avec des tests qui prouvent le batching (un seul findMany groupé au lieu d'un par élément parent).
  • Deux mutations de démonstration : logMedicationIntake, addSymptomLog — avec la même garde de propriété (userId) que les controllers REST.
  • backend/docs/graphql.md : pourquoi c'est additif, le comparatif avant/après, le walkthrough N+1, le modèle d'auth (dont la différence de statut HTTP entre une erreur de context et une erreur de resolver), et la liste assumée des simplifications de scope.

Contexte : c'est une pièce de démonstration pour portfolio (pas motivée par un besoin de performance sur cette app — voir docs/graphql.md pour l'honnêteté sur ce point), qui montre la maîtrise du modèle GraphQL : schéma, resolvers imbriqués, gestion N+1, auth.

Test plan

  • npm run build — compilation TypeScript propre
  • npm run lint — clean
  • npm test — suite Vitest complète verte (75/75, REST existant + nouveaux tests GraphQL)
  • Tests d'intégration resolvers.test.ts : query imbriquée avec preuve anti-N+1, rejet non authentifié (401, erreur de contexte) et distinction avec une erreur de resolver (200, NOT_FOUND)
  • Tests unitaires dataloaders.test.ts : batching prouvé indépendamment d'Express/Apollo
  • Pas de test manuel avec une vraie base Postgres (pas de daemon Docker disponible dans cet environnement) — les tests mockent Prisma comme le fait déjà entries.controller.test.ts

Generated by Claude Code

Portfolio demo: exposes /graphql (Apollo Server 5) next to the existing
REST API without touching it. Query.me mirrors what
analytics.controller.ts assembles by hand today, but lets the client
compose exactly the nested shape it needs in one request.

- JWT auth bridged from middleware/auth.ts into the GraphQL context
- DataLoader batching on Medication.intakes and DailyEntry.symptomLogs
  to avoid N+1 queries, with tests proving the batching
- Tests mirror the existing vitest + supertest + mocked-Prisma pattern
- docs/graphql.md explains the before/after, the N+1 walkthrough, and
  the scope cuts made for this demo

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_018trGZcjw2yvEQHmuCQ7hyx
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants