Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,28 @@ The default frontend GraphQL endpoint is `/graphql`. To use a different endpoint

**Note:** `db:import:musicbrainz` adds or updates the real catalog without deleting albums, reviews or crate items. `db:seed` and `db:seed:large` are reset commands: they replace the catalog and delete associated tracks, reviews and crate items. Do not use either seed command on a database containing data you want to keep. See [VM setup](docs/VM-setup.md) for deployment instructions.

### Server environment variables

The API reads `server/.env` (when present) and process environment variables:

| Variable | Default | Description |
| ----------------------------------- | ------------ | -------------------------------------------------------------------------------------------------------- |
| `DATABASE_URL` | _(required)_ | PostgreSQL connection string |
| `HOST` | `127.0.0.1` | Interface the HTTP server binds to |
| `PORT` | `3001` | HTTP server port |
| `NODE_ENV` | _(unset)_ | Set to `production` to disable GraphiQL and schema introspection (`__schema` / `__type`) |
| `CORS_ORIGIN` | _(unset)_ | Comma-separated allowlist of allowed browser origins; unset disables CORS |
| `RATE_LIMIT_MAX_REQUESTS` | `180` | Max requests per client IP per rate-limit window (`0` disables rate limiting) |
| `RATE_LIMIT_WINDOW_MS` | `60000` | Rate-limit window duration in milliseconds |
| `GRAPHQL_MAX_DEPTH` | `8` | Maximum GraphQL selection depth |
| `GRAPHQL_MAX_ALIASES` | `10` | Maximum aliased fields per GraphQL operation |
| `GRAPHQL_MAX_COMPLEXITY` | `200` | Maximum weighted complexity score per GraphQL operation |
| `GRAPHQL_MAX_BODY_BYTES` | `65536` | Maximum HTTP request body size in bytes (returns `413` when exceeded) |
| `PG_POOL_MAX` | `10` | Maximum PostgreSQL pool connections |
| `PG_CONNECTION_TIMEOUT_MS` | `5000` | PostgreSQL connection acquisition timeout in milliseconds |
| `PG_STATEMENT_TIMEOUT_MS` | `10000` | PostgreSQL `statement_timeout` in ms (`0` disables; CLI DB scripts default to `0` unless set explicitly) |
| `PG_IDLE_IN_TRANSACTION_TIMEOUT_MS` | `15000` | PostgreSQL `idle_in_transaction_session_timeout` in milliseconds (`0` disables) |

### Checks and useful commands

Before opening a PR, run:
Expand Down
34 changes: 34 additions & 0 deletions server/src/albums.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import { eq } from 'drizzle-orm';
import { GraphQLError } from 'graphql';

import type { Db } from './db/client.js';
import { album } from './db/schema.js';

export type AlbumRecord = {
id: number;
title: string;
releaseYear: number | null;
musicBrainzReleaseGroupId: string | null;
};

const albumColumns = {
id: album.id,
title: album.title,
releaseYear: album.releaseYear,
musicBrainzReleaseGroupId: album.musicBrainzReleaseGroupId,
};

export async function findAlbumById(db: Db, id: number): Promise<AlbumRecord | null> {
const [found] = await db
.select(albumColumns)
.from(album)
.where(eq(album.id, id))
.limit(1);
return found ?? null;
}

export async function findAlbum(db: Db, id: number): Promise<AlbumRecord> {
const found = await findAlbumById(db, id);
if (!found) throw new GraphQLError('Album not found.');
return found;
}
Loading