feat: add the GraphQL server with the catalog queries #65
+1,990
−254
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
Adds the GraphQL server, so the catalog and the search can be used through GraphQL. Until now the schema, the database, the seed and the search function existed, but nothing could call them. This is the main part of hand-in 2 ("a running backend and a client with some interaction").
The user data and the login are not part of it. Those operations answer a clear error until they are built (see below).
What is in it
backend/src/schema.graphql). Port 3001, endpoint/graphql.npm run backend(restarts on changes) ornpm run start -w backend.apparatus,elementGroup,element,vault,catalogItemandsearchCatalogas a connection.CatalogItemis resolved toElementorVault,imageUrlis built fromIMAGE_BASE_URL, andvariantslists the other variants of a code that are not removed.totalCountonly when the query asks for it, also through fragments, and not when@skipor@includeleaves it out. A client writestotalCount @include(if: $firstPage).BadUserInputErrorbecomesBAD_USER_INPUT. An unexpected error gives "Internal server error" and no details (they go to the log). A depth limit of 8 levels rejects a query before it runs (GRAPHQL_VALIDATION_FAILED); the introspection fields are not counted, so Apollo Sandbox still works./images/<apparatus>/<file>for the drawings (kept 30 days by the browser; Apache will serve them on the virtual machine) and/health. A request body above 100 kB is refused, and CORS only lets the addresses inCORS_ORIGINcall the API.mereturnsnull.gymnast,routineand every mutation that needs a coach answerUNAUTHENTICATED.loginandcalculateDScoreanswerNOT_IMPLEMENTED, a temporary code that goes away when they are built. A test checks that every mutation in the schema has a resolver.PORT,IMAGE_BASE_URLandCORS_ORIGINinbackend/.env.example.docs/API.mdwith the decisions.docs/AI_USAGE.mdhas an entry.What changed because of #66
#66 has a first server (
backend/src/index.ts,backend/src/resolvers.ts) and some scripts. This PR keeps everything that is not the same server twice, and the work in #66 is kept where it can be:setupscript (migrations, then the seed; I ran it on an empty database and it works), thebuildscript, Prisma^7.10.1,base: '/project2/'invite.config.tsand the packages that were added at the root.backend/src/index.ts(the name from 26 set up the database on the VM #66, sodevandsetupkeep their meaning), now with the full server. The first resolvers inbackend/src/resolvers.tsare replaced bybackend/src/server/resolvers/, which resolveCatalogItemtoElementorVaultas the schema needs.startrunstsx src/index.tsand notnode dist/index.js:backend/tsconfig.jsonhasnoEmit, so there is nodist/to run.@prisma/adapter-pgis moved to^7.10.1anddotenvto^18.0.8inbackend/package.json, so each package has one version across the root and the backend (Prisma recommends the same version forprisma,@prisma/clientand the adapter).Choices
graphqlversion^16, and the latest release is 17tsxanddotenvtsxand loadsbackend/.env. Install withnpm ci, not--omit=devvariantsvariants.length + 1(this settles the question in #58)originalErrordirectlyunwrapResolverErrorfails when two copies ofgraphqlare loaded (found by a test)Testing
npm run lint,npm run typecheck -w backend,npm run buildandnpm testpass on the merged result: 105 tests, 60 of them inbackend/src/server/, including the database tests against the seeded catalog.npm run setup -w backend(from 26 set up the database on the VM #66) creates the tables and seeds an empty database, andnpm run start -w backendthen starts the server fromindex.ts:/healthanswers, and a search for "hecht" gives 24 results.totalCountonly when asked, everyBAD_USER_INPUTcase, the depth limit, introspection, hidden details of an unexpected error, the operations that are not built, and HTTP (health, a query, a drawing and its cache header, 404, a path outside the images folder, CORS, a body above 100 kB).Notes
dev. The schema changes in feat: add the missing fields to the GraphQL schema #49 do not block it, and the API behind them is built in the follow-up issues.dScore,calculateDScore, GraphQL Code Generator, running the server on the virtual machine (Set up the database on the VM #26), and Apollo Client in the frontend.Closes #28
🤖 Generated with Claude Code