feat(backend): add additive GraphQL layer alongside REST API - #20
Open
Alithiel31 wants to merge 1 commit into
Open
feat(backend): add additive GraphQL layer alongside REST API#20Alithiel31 wants to merge 1 commit into
Alithiel31 wants to merge 1 commit into
Conversation
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
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.mereproduit ce queanalytics.controller.ts#overviewassemble 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).middleware/auth.tsdans le contexte GraphQL (src/graphql/context.ts).DataLoader(src/graphql/dataloaders.ts) surMedication.intakesetDailyEntry.symptomLogs, avec des tests qui prouvent le batching (un seulfindManygroupé au lieu d'un par élément parent).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 decontextet 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.mdpour 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 proprenpm run lint— cleannpm test— suite Vitest complète verte (75/75, REST existant + nouveaux tests GraphQL)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)dataloaders.test.ts: batching prouvé indépendamment d'Express/Apolloentries.controller.test.tsGenerated by Claude Code