Registry / database / hasura-om

hasura-om

JSON →
library1.4.6jsnpmunverified

Hasura-om is a Node.js ORM library (v1.4.6) that provides an object-oriented way to interact with Hasura GraphQL API. It focuses on fragments: base fragments are auto-generated from your database schema, then you can extend or create custom fragments. The library simplifies query building by allowing JavaScript objects to represent GraphQL operations. It supports queries, mutations, subscriptions, aggregate queries, nested queries, JWT authorization, and is available for both Node.js (CommonJS/ESM) and browser with bundlers. Key differentiator: fragment-first approach reduces boilerplate and keeps queries standardized. Current release cadence is irregular but active. Not to be confused with Hasura's own ORM tools or other GraphQL wrappers.

npm install hasura-om
INSTALL
IMPORT
SIG · HASURA-OM
H
hasura-om
databasejavascriptv1.4.6
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.

Hasura
const { Hasura } = require('hasura-om')
const Hasura = require('hasura-om')
CommonJS require should use destructuring to get the Hasura class. Using import { Hasura } from 'hasura-om' for ESM (note: ESM support may require bundler).
QueryBuilder
const { QueryBuilder } = require('hasura-om')
import QueryBuilder from 'hasura-om'
QueryBuilder is a named export, not default. Use destructuring.
default export
import hasuraOM from 'hasura-om'
The package also exports a default object? Verify in docs. Some versions may have default export but recommended to use named 'Hasura'.

Initializes Hasura ORM, generates fragments from schema, and performs a simple query limiting to 5 users ordered by name.

const { Hasura } = require('hasura-om'); const om = new Hasura({ graphqlUrl: process.env.HASURA_URL || 'http://localhost:8080/v1/graphql', adminSecret: process.env.HASURA_ADMIN_SECRET || 'myadminsecretkey' }); async function main() { await om.generateTablesFromAPI(); const [err, result] = await om.query({ user: { limit: 5, order_by: { name: 'asc' }, fields: ` id name email ` } }); if (err) { console.error('Error:', err); } else { console.log('Users:', result.user); } } main().catch(console.error);
Debug
Known issues
breakingVersion 0.0.18 changed Hasura constructor options: 'endpoint' renamed to 'graphqlUrl'. Existing code using 'endpoint' will break.
fix
Update to v0.0.18+ and use 'graphqlUrl' instead of 'endpoint'.
affects: <0.0.18
deprecatedThe method 'generateTablesFromAPI' is deprecated as of v1.0.0. Use 'fetchSchema' instead.
fix
Replace om.generateTablesFromAPI() with om.fetchSchema().
affects: >=1.0.0
gotchaWhen using adminSecret, the header 'x-hasura-admin-secret' is set. If your Hasura instance requires a different header (like 'x-hasura-role'), you must configure it manually via 'headers' option.
fix
Pass custom headers in Hasura constructor: new Hasura({ graphqlUrl, headers: { 'x-hasura-role': 'admin' } })
affects: all
gotchaIn browser, the library requires a bundler (Webpack, Rollup, etc.) to work. It does not come with a pre-built UMD bundle. Attempting to use it directly via <script> tag will fail.
fix
Use a bundler like Webpack and import 'hasura-om'. Alternatively, bundle it yourself.
affects: >=1.2.0
Errors
Common errors & fixes
Error: Cannot find module 'node-fetch'
Missing dependency 'node-fetch' when using the library in Node.js environment.
fix
Run 'npm install node-fetch' to install the peer dependency.
TypeError: om.generateTablesFromAPI is not a function
The method 'generateTablesFromAPI' was renamed to 'fetchSchema' in v1.0.0.
fix
Update code to use 'await om.fetchSchema()' instead.
UnhandledPromiseRejectionWarning: Error: graphqlUrl is required
Missing 'graphqlUrl' in Hasura constructor options.
fix
Ensure you pass an object with 'graphqlUrl' property when instantiating Hasura: new Hasura({ graphqlUrl: '...' })
Error: Admin secret is required
Missing 'adminSecret' in Hasura constructor options but Hasura endpoint requires admin secret.
fix
Pass 'adminSecret' in the constructor. If not needed, set to empty string or use 'headers' for authentication.
Error: Not Found - Schema introspection might be disabled
Hasura endpoint returned 404 during schema fetch. Usually because GraphQL introspection is disabled in Hasura.
fix
Enable introspection in Hasura or manually define fragments using 'setTable' method instead of auto-generating.
Upgrade
Version history
1.4.6latest on npm
Audit
Dependencies
node-fetchrequiredUsed for HTTP requests to Hasura endpoint
Agent activity
4 hits · last 30 days
node
4
Resources
hasura-om — npm install hasura-om · libregistry