Skip to content

Repository files navigation

api

The GraphQL gateway for the @imqueue Car-Wash tutorial.

It is the single public entry point in front of the backend fleet (user, auth, car, time-table): it exposes one Relay-style GraphQL schema and orchestrates the typed @imqueue/rpc services behind it, resolving each GraphQL field to one or more RPC calls. The React front-end web-app talks to this gateway.

Its REST counterpart, api-rest, fronts the very same fleet over OpenAPI — the two gateways are the whole point of the tutorial.

About the tutorial

This repo is one piece of the imqueue-sandbox tutorial — a complete car-wash booking app built from independent RPC microservices that communicate over a Redis-backed message queue.

Repo Role Store
user Customer accounts & their garage MongoDB
auth Login, JWT issuing & revocation Redis
car Car catalog (makes / models / types) in-memory
time-table Washing reservations & schedule PostgreSQL
api GraphQL gateway orchestrating the fleet
api-rest REST/OpenAPI gateway over the same fleet
web-app React front-end on api (GraphQL/Relay)
web-app-rest React front-end on api-rest (REST)

How it works

  • Built on express 5 + graphql-yoga. On start it boots the four generated RPC clients (src/clients/) into a shared context and mounts the GraphQL endpoint at /.
  • Relay conventions: global IDs (graphql-relay), a node interface, connection-based pagination for users, and mutationWithClientMutationId for every mutation.
  • Field projection: graphql-fields-list turns the client's selection set into the minimal fields argument for each RPC call, so services only compute what was asked for.
  • Authorization: field-level validators enforce owner/admin rules; non-admin users listings are capped at 100 records.

Schema surface

Queriesnode, user, users, car, cars, brands, options, reservation, reservations.

Mutationslogin, logout, updateUser (create/update), addCar, removeCar, reserve, cancelReservation.

The printed SDL is committed at src/schema.graphql.

Authentication

Clients send the JWT issued by the login mutation in the X-Auth-User header. The gateway resolves it to the current user via the auth service (auth.verify) for every request.

Configuration

Environment variables (loaded from an optional .env via process.loadEnvFile()):

Variable Default Purpose
API_PORT 8888 HTTP port (auto-increments if busy).
IMQ_REDIS localhost:6379 Redis endpoint(s) for the RPC message queue.
NODE_ENV development Enables the GraphiQL IDE at / in development.
API_SSL_KEY / API_SSL_CERT TLS key/cert paths; used only with the --SECURED flag.

Running

Development mode (rebuilds and restarts on change; GraphiQL enabled):

npm run dev

Production mode:

npm start
  • GraphQL endpoint: http://localhost:8888/
  • GraphiQL IDE (development only): http://localhost:8888/

Requires the backend fleet running and reachable over IMQ_REDIS.

Maintenance scripts

  • npm run rebuild-clients — regenerate the four RPC clients in src/clients/ from the live services using the imq CLI.
  • npm run update-schema — build and re-print the GraphQL SDL to src/schema.graphql.

License

ISC License

About

GraphQL API application for tutorial application based on @imqueue services.

Resources

Stars

0 stars

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages