Library
GraphQL API and frontend for the next implementation of my offline library, implemented with Haskell and Elm, using mu-haskell, postgres-typed and elm-graphql. (there is also previous implementation in Elm without backend)
Key feature: compile-time typecheck against PostgreSQL and GraphQL schemas and (both backend and frontend).
- TODO
- GraphQL queries (curl)
- URL structure
- UI design (Figma, work in progress)
Setting up and running
docker-compose up -d
— run PostgreSQLcd backend
stack build --exec backend --file-watch
— check schemas, run API server and watch for file changes
cd frontend
npm i
— install dependenciesnpm start
— generate query library from schema, start dev-server, open http://localhost:8000/:
Notes
stack build --ghc-options -O2 --copy-bins && ~/.local/bin/backend
— API production build (later use in dockerfile)
Design choices and tradeoffs
- Mu-haskell does not join sql queries, so I decided to exclude books from Authors. By making this tradeoff I can manually join sql queries.
- GraphQL currently does not support input unions. But I want admin app to create book either with new author, or with existing one.
What could I do:
- Accept nullable fields in inputs:
newAuthor
,existingAuthorId
, and then choose first filled (aka workaround input unions) - Decide on frontend and compose tasks that create author before book, if necessary (but it is not transactional which could be very confusing in case of any failure and retry)
- Provide different mutations for such cases, and let frontend decide. This means enough typesafety, ability to make a proper SQL transaction and little work on frontend. This is my choice.
- Accept nullable fields in inputs: