UNPKG

graphile-settings

Version:
174 lines (132 loc) โ€ข 9.31 kB
# graphile-settings <p align="center" width="100%"> <img height="250" src="https://raw.githubusercontent.com/launchql/launchql/refs/heads/main/assets/outline-logo.svg" /> </p> <p align="center" width="100%"> <a href="https://github.com/launchql/launchql/actions/workflows/run-tests.yaml"> <img height="20" src="https://github.com/launchql/launchql/actions/workflows/run-tests.yaml/badge.svg" /> </a> <a href="https://github.com/launchql/launchql/blob/main/LICENSE"><img height="20" src="https://img.shields.io/badge/license-MIT-blue.svg"/></a> <a href="https://www.npmjs.com/package/graphile-settings"><img height="20" src="https://img.shields.io/github/package-json/v/launchql/launchql?filename=packages%2Fgraphile-settings%2Fpackage.json"/></a> </p> **`graphile-settings`** is a batteries-included configuration builder for [PostGraphile](https://www.graphile.org/postgraphile/), purpose-built for the [LaunchQL](https://github.com/launchql/launchql) ecosystem. It centralizes plugin setup, schema wiring, and feature flags into a single, composable interface โ€” enabling consistent, high-performance GraphQL APIs across projects. ## ๐Ÿš€ Installation ```bash npm install graphile-settings ``` ## โœจ Features * Built-in support for: * โœ… Connection filters * ๐Ÿ” Full-text search * ๐ŸŒ PostGIS support (with filters) * ๐Ÿงฉ Many-to-many helpers * ๐Ÿ†Ž Simplified inflectors * ๐Ÿ—‚ Upload field support (S3/MinIO) * ๐ŸŒ i18n support via `graphile-i18n` * ๐Ÿง  Meta schema plugin * ๐Ÿ”Ž Graphile search plugin * Smart schema and plugin configuration via environment or options * Express-compatible with support for request-aware context ## ๐Ÿ“ฆ Usage ```ts import { getGraphileSettings } from 'graphile-settings'; import { postgraphile } from 'postgraphile'; import express from 'express'; const app = express(); const settings = getGraphileSettings({ server: { port: 5000, host: '0.0.0.0', strictAuth: true, }, graphile: { schema: ['app_public'], metaSchemas: ['meta_public'], }, features: { postgis: true, simpleInflection: true, oppositeBaseNames: true, }, cdn: { bucketName: 'media-bucket', awsRegion: 'us-west-1', awsAccessKey: 'AKIA...', awsSecretKey: 'secret', minioEndpoint: 'http://localhost:9000' } }); app.use(postgraphile({ ...settings, pgPool: myPool // your initialized pg.Pool })); app.listen(settings.port); ``` ## ๐Ÿงฐ Configuration Options ### `LaunchQLOptions` #### `server` * `port` โ€” (number) Port to use * `host` โ€” (string) Hostname * `trustProxy` โ€” (boolean) Whether to trust proxy headers (e.g. for real IPs) * `origin` โ€” (string) Origin for CORS/auth logic * `strictAuth` โ€” (boolean) Whether to enforce strict auth #### `graphile` * `schema` โ€” (string or string\[]) Required list of main GraphQL schemas * `metaSchemas` โ€” (string\[]) Optional list of meta/introspection schemas * `isPublic` โ€” (boolean) Flag for public GraphQL instance * `appendPlugins` โ€” (Plugin\[]) Additional Graphile plugins * `graphileBuildOptions` โ€” (PostGraphileOptions.graphileBuildOptions) Extra build options * `overrideSettings` โ€” (Partial<PostGraphileOptions>) Manual overrides of generated config #### `features` * `simpleInflection` โ€” Use simplified inflection (e.g. `fooByBarId`) * `oppositeBaseNames` โ€” Enable smart reverse relation names * `postgis` โ€” Enable PostGIS and filter plugin #### `cdn` * `bucketName` โ€” Required for upload plugin (S3 or MinIO) * `awsRegion` โ€” AWS region * `awsAccessKey` โ€” Access key for upload * `awsSecretKey` โ€” Secret key * `minioEndpoint` โ€” Optional override for MinIO compatibility ## ๐Ÿ”Œ Included Plugins * `postgraphile-plugin-connection-filter` * `@pyramation/postgraphile-plugin-fulltext-filter` * `@pyramation/postgis` * `postgraphile-plugin-connection-filter-postgis` * `postgraphile-derived-upload-field` * `graphile-simple-inflector` * `graphile-i18n` * `graphile-meta-schema` * `@graphile-contrib/pg-many-to-many` * `graphile-search-plugin` * `./plugins/types` (custom LaunchQL plugin) ## Related LaunchQL Tooling ### ๐Ÿงช Testing * [launchql/pgsql-test](https://github.com/launchql/launchql/tree/main/packages/pgsql-test): **๐Ÿ“Š Isolated testing environments** with per-test transaction rollbacksโ€”ideal for integration tests, complex migrations, and RLS simulation. * [launchql/graphile-test](https://github.com/launchql/launchql/tree/main/packages/graphile-test): **๐Ÿ” Authentication mocking** for Graphile-focused test helpers and emulating row-level security contexts. * [launchql/pg-query-context](https://github.com/launchql/launchql/tree/main/packages/pg-query-context): **๐Ÿ”’ Session context injection** to add session-local context (e.g., `SET LOCAL`) into queriesโ€”ideal for setting `role`, `jwt.claims`, and other session settings. ### ๐Ÿง  Parsing & AST * [launchql/pgsql-parser](https://github.com/launchql/pgsql-parser): **๐Ÿ”„ SQL conversion engine** that interprets and converts PostgreSQL syntax. * [launchql/libpg-query-node](https://github.com/launchql/libpg-query-node): **๐ŸŒ‰ Node.js bindings** for `libpg_query`, converting SQL into parse trees. * [launchql/pg-proto-parser](https://github.com/launchql/pg-proto-parser): **๐Ÿ“ฆ Protobuf parser** for parsing PostgreSQL Protocol Buffers definitions to generate TypeScript interfaces, utility functions, and JSON mappings for enums. * [@pgsql/enums](https://github.com/launchql/pgsql-parser/tree/main/packages/enums): **๐Ÿท๏ธ TypeScript enums** for PostgreSQL AST for safe and ergonomic parsing logic. * [@pgsql/types](https://github.com/launchql/pgsql-parser/tree/main/packages/types): **๐Ÿ“ Type definitions** for PostgreSQL AST nodes in TypeScript. * [@pgsql/utils](https://github.com/launchql/pgsql-parser/tree/main/packages/utils): **๐Ÿ› ๏ธ AST utilities** for constructing and transforming PostgreSQL syntax trees. * [launchql/pg-ast](https://github.com/launchql/launchql/tree/main/packages/pg-ast): **๐Ÿ” Low-level AST tools** and transformations for Postgres query structures. ### ๐Ÿš€ API & Dev Tools * [launchql/server](https://github.com/launchql/launchql/tree/main/packages/server): **โšก Express-based API server** powered by PostGraphile to expose a secure, scalable GraphQL API over your Postgres database. * [launchql/explorer](https://github.com/launchql/launchql/tree/main/packages/explorer): **๐Ÿ”Ž Visual API explorer** with GraphiQL for browsing across all databases and schemasโ€”useful for debugging, documentation, and API prototyping. ### ๐Ÿ” Streaming & Uploads * [launchql/s3-streamer](https://github.com/launchql/launchql/tree/main/packages/s3-streamer): **๐Ÿ“ค Direct S3 streaming** for large files with support for metadata injection and content validation. * [launchql/etag-hash](https://github.com/launchql/launchql/tree/main/packages/etag-hash): **๐Ÿท๏ธ S3-compatible ETags** created by streaming and hashing file uploads in chunks. * [launchql/etag-stream](https://github.com/launchql/launchql/tree/main/packages/etag-stream): **๐Ÿ”„ ETag computation** via Node stream transformer during upload or transfer. * [launchql/uuid-hash](https://github.com/launchql/launchql/tree/main/packages/uuid-hash): **๐Ÿ†” Deterministic UUIDs** generated from hashed content, great for deduplication and asset referencing. * [launchql/uuid-stream](https://github.com/launchql/launchql/tree/main/packages/uuid-stream): **๐ŸŒŠ Streaming UUID generation** based on piped file contentโ€”ideal for upload pipelines. * [launchql/upload-names](https://github.com/launchql/launchql/tree/main/packages/upload-names): **๐Ÿ“‚ Collision-resistant filenames** utility for structured and unique file names for uploads. ### ๐Ÿงฐ CLI & Codegen * [@launchql/cli](https://github.com/launchql/launchql/tree/main/packages/cli): **๐Ÿ–ฅ๏ธ Command-line toolkit** for managing LaunchQL projectsโ€”supports database scaffolding, migrations, seeding, code generation, and automation. * [launchql/launchql-gen](https://github.com/launchql/launchql/tree/main/packages/launchql-gen): **โœจ Auto-generated GraphQL** mutations and queries dynamically built from introspected schema data. * [@launchql/query-builder](https://github.com/launchql/launchql/tree/main/packages/query-builder): **๐Ÿ—๏ธ SQL constructor** providing a robust TypeScript-based query builder for dynamic generation of `SELECT`, `INSERT`, `UPDATE`, `DELETE`, and stored procedure callsโ€”supports advanced SQL features like `JOIN`, `GROUP BY`, and schema-qualified queries. * [@launchql/query](https://github.com/launchql/launchql/tree/main/packages/query): **๐Ÿงฉ Fluent GraphQL builder** for PostGraphile schemas. โšก Schema-aware via introspection, ๐Ÿงฉ composable and ergonomic for building deeply nested queries. ## Disclaimer AS DESCRIBED IN THE LICENSES, THE SOFTWARE IS PROVIDED "AS IS", AT YOUR OWN RISK, AND WITHOUT WARRANTIES OF ANY KIND. No developer or entity involved in creating this software will be liable for any claims or damages whatsoever associated with your use, inability to use, or your interaction with other users of the code, including any direct, indirect, incidental, special, exemplary, punitive or consequential damages, or loss of profits, cryptocurrencies, tokens, or anything else of value.