@cubicecho/server-kit
v0.8.1
Published
The server code every cubicecho GraphQL backend shares: database boot, id columns and the checks that keep a schema to the standard.
Maintainers
Readme
@cubicecho/server-kit
The server code every cubicecho GraphQL backend shares. Each server used to copy it, and the copies drifted: a fix reached one repo and not the next. It is functions an app calls, not a framework: the app keeps its own schema, auth setup and boot order.
Install
npm i @cubicecho/server-kit [email protected] postgres@4Quick start
import { connectionOptions, DatabaseBootError, prepareDatabase } from '@cubicecho/server-kit/db';
import { drizzle } from 'drizzle-orm/postgres-js';
const url = process.env.DATABASE_URL ?? '';
const isProduction = process.env.NODE_ENV === 'production';
const db = drizzle({ connection: { url, ...connectionOptions(url, isProduction) } });
try {
await prepareDatabase(db, { url, isProduction });
} catch (error) {
if (error instanceof DatabaseBootError) {
console.error(`[db] ${error.message}`);
process.exit(1);
}
throw error;
}It waits for Postgres, creates the database when it is missing, and refuses a server older than 18, with a message that says what to do.
Documentation
License
MIT
