Registry / database / graphql-to-sqlite-ddl

graphql-to-sqlite-ddl

JSON →
library2.0.4jsnpmunverified

Parse GraphQL type definitions into SQLite DDL statements, including CREATE TABLE with auto-generated id, created_at, updated_at, triggers, and support for directives (default, unique, index, primary, autoIncrement) and ORM relations (belongsTo, hasAndBelongsToMany). Current version 2.0.4. Lightweight, no external dependencies beyond GraphQL.js. Distinct from general ORMs by translating GraphQL schemas directly to SQL for SQLite.

npm install graphql-to-sqlite-ddl
INSTALL
IMPORT
SIG · GRAPHQL-TO-SQLITE-
G
graphql-to-sqlite-ddl
databasejavascriptv2.0.4
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.

parse
import { parse } from 'graphql-to-sqlite-ddl'
const parse = require('graphql-to-sqlite-ddl').parse
The package exports a single function 'parse' as named export. CommonJS users can use require but must access .parse.
default import
import graphqlToSqlite from 'graphql-to-sqlite-ddl'
const graphqlToSqlite = require('graphql-to-sqlite-ddl')
This package does not have a default export; the entire module is the parse function. Use named import.
buildSchema (from graphql)
import { buildSchema } from 'graphql'
You need graphql to create a schema object before passing to parse().

Shows basic usage: define a GraphQL schema, parse it, and output SQLite DDL string.

import { buildSchema } from 'graphql'; import { parse } from 'graphql-to-sqlite-ddl'; const schema = buildSchema(` type Person { name: String! age: Int } `); const sql = parse(schema); console.log(sql);
Debug
Known issues
gotchaThe parse function expects a GraphQLSchema object, not a string. Use buildSchema from 'graphql' first.
fix
Ensure you pass a schema object created with buildSchema().
affects: >=0.0.1
gotchaThe library automatically adds id, created_at, updated_at columns and an update trigger to every table. There is no way to disable this.
fix
If you don't want these columns, you may need to modify the output manually or use a different tool.
affects: >=0.0.1
deprecatedbelongsTo relationship using 'belongsTo: Type' syntax in GraphQL schema. This is a non-standard directive-like field.
fix
Use the documented directive syntax with foreignKey to specify custom column names.
affects: >=0.0.1
gotchaThe id column uses a random-like default expression based on timestamp and random, not autoincrement. This may cause collisions in high-concurrency scenarios.
fix
If you want true autoincrement, add the @autoIncrement directive to the id field or manually alter the table.
affects: >=0.0.1
deprecatedThe package does not follow semver strictly; minor versions may introduce breaking changes.
fix
Pin to exact version if using in production.
affects: >=2.0.0
Errors
Common errors & fixes
TypeError: schema is not a valid GraphQL schema
Passing a string instead of a GraphQLSchema object to parse()
fix
Use buildSchema(sdlString) to create a schema object before passing to parse().
Cannot find module 'graphql'
The graphql package is a peer dependency and must be installed separately
fix
Run: npm install graphql
ReferenceError: parse is not defined
Trying to call parse() without importing it correctly, possibly using default import instead of named import
fix
Use: import { parse } from 'graphql-to-sqlite-ddl'
Upgrade
Version history
2.0.4latest on npm
Audit
Dependencies
graphqlrequiredRequired to build and parse GraphQL schemas
Agent activity
8 hits · last 30 days
node
8
Resources
graphql-to-sqlite-ddl — npm install graphql-to-sqlite-ddl · libregistry