Registry / database / orchid-graphql

orchid-graphql

JSON →
library1.9.1jsnpmunverified

orchid-graphql is a helper library for resolving GraphQL queries directly with Orchid ORM tables and relations (version 1.9.1). It selects only requested fields and relations, supports unlimited nested resolvers, pagination, filters (e.g., date-based, __in), query modifiers, and field result hooks for access control. Released pre-release (not battle-tested), it is a quick adaptation of objection-graphql-resolver. Requires graphql ^16 and orchid-orm ^1.31.5 as peer dependencies. Node.js >=14. Ships TypeScript types, but typings are not fully ready (returns generic Query).

npm install orchid-graphql
INSTALL
IMPORT
SIG · ORCHID-GRAPHQL
O
orchid-graphql
databasejavascriptv1.9.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.

graph
import { graph } from 'orchid-graphql'
import * as r from 'orchid-graphql'
Common pattern is to import all as 'r' (e.g., r.graph), but named import is also valid.
r
import * as r from 'orchid-graphql'
import r from 'orchid-graphql'
There is no default export; use namespace import.
graph
import { graph } from 'orchid-graphql'
const { graph } = require('orchid-graphql')
Package is ESM-only; CommonJS require may not work.

Full example setting up Apollo Server with orchid-graphql: defines a Post table, creates GraphQL schema, maps table to resolver with r.graph, and runs server.

import { ApolloServer } from '@apollo/server'; import { startStandaloneServer } from '@apollo/server/standalone'; import gql from 'graphql-tag'; import * as r from 'orchid-graphql'; import { createBaseTable, orchidORM } from 'orchid-orm'; const BaseTable = createBaseTable(); class PostTable extends BaseTable { readonly table = 'post'; columns = this.setColumns(t => ({ id: t.identity().primaryKey(), text: t.text(0, 5000), })); } const db = orchidORM({ databaseURL: process.env.DATABASE_URL ?? '', log: true, }, { post: PostTable }); await db.$query` create table post ( id serial primary key, text text not null ); `; const typeDefs = gql` type Post { id: Int! text: String! } type Mutation { create_post(text: String!): Post! } type Query { posts: [Post!]! } `; const graph = r.graph({ Post: r.table(db.post) }); const resolvers = { Mutation: { async create_post(_parent: any, args: { text: string }, context: any, info: any) { const post = await db.post.create(args); return await graph.resolve(db.post.find(post.id), { context, info }); }, }, Query: { async posts(_parent: any, _args: any, context: any, info: any) { return await graph.resolve(db.post, { context, info }); }, }, }; const server = new ApolloServer({ typeDefs, resolvers }); const { url } = await startStandaloneServer(server, { listen: { port: 4000 } }); console.log(`Listening on ${url}`);
Debug
Known issues
gotchaThe library is pre-release and not battle tested. May have bugs or incomplete features.
fix
Use with caution; test thoroughly in production-like environments.
affects: <2.0
gotchaTypings are incomplete; resolver returns generic 'Query' type instead of specific shapes.
fix
Cast or use type assertions when needed (e.g., as unknown as YourType).
affects: >=1.0
gotchaPackage does not export a default export; must use named imports like import { graph } or import * as r.
fix
Use namespace import (import * as r from 'orchid-graphql') or named import (import { graph }).
affects: >=1.0
gotchaRequires graphql ^16 and orchid-orm ^1.31.5 as peer dependencies; missing them causes runtime errors.
fix
Install peer deps: npm install graphql orchid-orm
affects: >=1.0
gotchaThe r.table() function expects a table object with a query method; passing wrong object causes cryptic errors.
fix
Ensure you pass a table instance from orchid-orm, e.g., r.table(db.post).
affects: >=1.0
Errors
Common errors & fixes
Cannot find module 'orchid-graphql'
Package not installed or ESM not configured.
fix
Run npm install orchid-graphql and ensure project uses ES modules (type: 'module' in package.json or .mjs files).
TypeError: r.graph is not a function
Namespace import used incorrectly (e.g., import r from 'orchid-graphql') instead of import * as r.
fix
Use import * as r from 'orchid-graphql' or import { graph } from 'orchid-graphql'.
Cannot read properties of undefined (reading 'resolve')
graph object returned from r.graph() is used before being assigned or destructured incorrectly.
fix
Ensure you call r.graph() and then use the returned object's resolve method: const graph = r.graph({...}); graph.resolve(...).
Type 'typeof import("orchid-orm")' is not assignable to parameter of type 'Table'
Passing the ORM object instead of a table instance to r.table().
fix
Pass a specific table: r.table(db.post) instead of r.table(db).
Upgrade
Version history
1.9.1latest on npm
Audit
Dependencies
graphqlrequiredpeer dependency for GraphQL integration
orchid-ormrequiredpeer dependency for ORM integration
Agent activity
2 hits · last 30 days
node
2
Resources
orchid-graphql — npm install orchid-graphql · libregistry