Registry / database / graphql-gene

graphql-gene

JSON →
library1.3.7jsnpmunverified

graphql-gene (v1.3.7) automatically generates an executable GraphQL schema and resolvers from your ORM models, supporting TypeScript out of the box. It focuses on performance by leveraging a lookahead pattern (via graphql-lookahead) to only fetch the data required by the client, reducing over-fetching. Stable release cadence; requires GraphQL 16.x. Differentiator: ORM introspection + lookahead-driven resolution, removing manual resolver boilerplate while optimizing database queries.

npm install graphql-gene
INSTALL
IMPORT
SIG · GRAPHQL-GENE
G
graphql-gene
databasejavascriptv1.3.7
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.

generateSchema
import { generateSchema } from 'graphql-gene'
const { generateSchema } = require('graphql-gene')
graphql-gene is ESM-only. CommonJS require will fail; use dynamic import if needed.
type GenerateSchemaOptions
import type { GenerateSchemaOptions } from 'graphql-gene'
import { GenerateSchemaOptions } from 'graphql-gene'
This is a type-only export; import using 'import type' to avoid runtime error.
default export
import gene from 'graphql-gene'
const gene = require('graphql-gene')
The package also exports a default object containing functions. Use ESM import.

Shows how to generate a GraphQL schema from ORM models and serve it with graphql-http.

import { generateSchema } from 'graphql-gene'; import { models } from './models'; // your ORM models const schema = generateSchema(models, { schemaDirectives: { // optional directives }, scalars: { // custom scalar types }, }); // Use schema with graphql-http or Apollo Server import { createHandler } from 'graphql-http/lib/use/http'; import http from 'http'; const handler = createHandler({ schema }); const server = http.createServer(handler); server.listen(4000); console.log('GraphQL server running on http://localhost:4000/graphql');
Debug
Known issues
breakingGraphQL v16 required; v15 not supported.
fix
Upgrade to graphql@^16.0.0.
affects: >=1.0.0
breakingESM-only since v1.0.0; CommonJS require will throw.
fix
Use ESM imports (import syntax) or dynamic import require('.cjs') if available. This package does not provide a CJS entry.
affects: >=1.0.0
deprecatedgenerateSchema no longer accepts options as second argument in v1.3.0; use a single options object.
fix
Pass all options as the second argument: generateSchema(models, options) where options includes schemaDirectives, scalars, etc.
affects: >=1.3.0
gotchagraphql-lookahead peer dependency must be installed manually.
fix
Run npm install graphql-lookahead.
affects: >=1.0.0
gotchaModels must follow a specific shape; otherwise generation fails silently.
fix
Ensure models export an array of model classes/objects with 'name' and 'fields' properties. Refer to documentation for exact shape.
affects: >=1.0.0
Errors
Common errors & fixes
Cannot find module 'graphql-lookahead'
Missing peer dependency.
fix
npm install graphql-lookahead
TypeError: generateSchema is not a function
CommonJS require used on ESM-only module.
fix
Use import { generateSchema } from 'graphql-gene' instead of require.
TypeError: Cannot read property 'prototype' of undefined
Models passed to generateSchema do not have expected structure.
fix
Verify models export an array of model classes with 'name' and 'fields'.
Upgrade
Version history
1.3.7latest on npm
Audit
Dependencies
graphqlrequiredPeer dependency: required for schema generation and execution
graphql-lookaheadrequiredPeer dependency: used for lookahead query analysis to optimize data fetching
Agent activity
6 hits · last 30 days
node
6
Resources
graphql-gene — npm install graphql-gene · libregistry