Registry / database / graphile-schema

graphile-schema

JSON →
library1.22.1jsnpmunverified

A utility library for building GraphQL SDL (Schema Definition Language) from PostgreSQL databases using PostGraphile v5. It provides a `SchemaBuilder` class that simplifies constructing GraphQL schemas programmatically by introspecting database schemas and generating types and relationships. Key differentiators: integrates directly with PostGraphile v5's plugin system, eliminates manual schema stitching, and supports dynamic schema generation. Current stable version (1.22.1) is actively maintained with weekly releases. Ships TypeScript types and is part of the Constructive ecosystem.

npm install graphile-schema
INSTALL
IMPORT
SIG · GRAPHILE-SCHEMA
G
graphile-schema
databasejavascriptv1.22.1
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

SchemaBuilder
import { SchemaBuilder } from 'graphile-schema';
const { SchemaBuilder } = require('graphile-schema');
ESM-only since v1. ESM imports are required; CommonJS require() will fail in Node >=12.
buildSchema
import { buildSchema } from 'graphile-schema';
import buildSchema from 'graphile-schema';
Default export is not supported. Use named import.
SchemaType
import type { SchemaType } from 'graphile-schema';
TypeScript users should use 'import type' for type-only imports to avoid bundle bloat in ESM.

Creates a SchemaBuilder instance, uses PostGraphile v5 to generate a schema from a PostgreSQL database, then outputs the SDL string.

import { SchemaBuilder } from 'graphile-schema'; import { createPostGraphileSchema } from 'postgraphile'; const builder = new SchemaBuilder(); const schema = await createPostGraphileSchema(process.env.DATABASE_URL ?? 'postgres://localhost/mydb', { plugins: [builder.plugin] }); const sdl = builder.toSDL(); console.log(sdl);
Debug
Known issues
breakingVersion 1.0.0 dropped support for CommonJS. All imports must use ESM syntax.
fix
Replace require() with import statements.
affects: >=1.0.0
deprecatedThe 'buildSchema' function signature changed in v1.20.0; old parameters are deprecated.
fix
Update calls to use the new configuration object format.
affects: <1.20.0
gotchaSchemaBuilder is not thread-safe. Do not share instances across concurrent requests.
fix
Instantiate a new SchemaBuilder per request or use a pool.
affects: >=1.0.0
gotchaRequires Node.js >=16.0.0.
fix
Upgrade Node.js or use an older version of the package (pre-1.0).
affects: >=1.0.0
Errors
Common errors & fixes
Error: Cannot find module 'graphile-schema'
CommonJS require() used instead of ESM import
fix
Change require('graphile-schema') to import { SchemaBuilder } from 'graphile-schema'.
TypeError: (intermediate value).plugin is not a function
Missing or incorrect PostGraphile plugin configuration
fix
Ensure you pass builder.plugin to the PostGraphile schema creation options.
SyntaxError: Unexpected token 'export'
Package is ESM-only but used with CommonJS environment (e.g., Node <12 or without "type": "module")
fix
Add "type": "module" to package.json or use dynamic import().
TypeError: builder.toSDL is not a function
SchemaBuilder instance not properly initialized or schema not built first
fix
Ensure you call createPostGraphileSchema and pass builder.plugin before calling toSDL().
Upgrade
Version history
1.22.1latest on npm
Audit
Dependencies
postgraphileoptionalPostGraphile v5 is a peer dependency for schema introspection and plugin support.
Agent activity
4 hits · last 30 days
node
4
Resources
graphile-schema — npm install graphile-schema · libregistry