Registry / database / join-monster

join-monster

JSON →
library4.0.1jsnpmunverified

Join Monster is a GraphQL-to-SQL query execution layer that automatically generates SQL JOINs from GraphQL queries and batch-fetches data in minimal round trips. Current stable version is 4.0.1 (released 2023, maintained actively). It differs from alternatives like DataLoader by generating single SQL queries with JOINs instead of N+1 batched queries, reducing database load. It supports multiple SQL dialects (PostgreSQL, MySQL, SQLite) and ships with TypeScript type definitions. Peer dependency on GraphQL 16+ and Node.js 14+.

npm install join-monster
INSTALL
IMPORT
SIG · JOIN-MONSTER
J
join-monster
databasejavascriptv4.0.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.

joinMonster
import joinMonster from 'join-monster'
const joinMonster = require('join-monster')
joinMonster is a default export; CJS require also works but ESM is preferred since v4.
joinMonster
import joinMonster from 'join-monster'
import { joinMonster } from 'join-monster'
Named export 'joinMonster' does not exist; it's a default export.
default
import joinMonster from 'join-monster'
import * as joinMonster from 'join-monster'
Star import works but yields { default: ... }; default import is simpler.
joinMonster.default
const jm = require('join-monster').default
const jm = require('join-monster')
When using CJS, .default is needed because the module is an ESM default export.
JoinMonsterOptions
import type { JoinMonsterOptions } from 'join-monster'
Type imports are available for TypeScript users.

Creates an Express server with a GraphQL endpoint using joinMonster to resolve a 'user' query that joins 'users' table and virtual fields.

import express from 'express'; import { graphqlHTTP } from 'express-graphql'; import { GraphQLSchema, GraphQLObjectType, GraphQLString, GraphQLInt } from 'graphql'; import joinMonster from 'join-monster'; const app = express(); const UserType = new GraphQLObjectType({ name: 'User', fields: () => ({ id: { type: GraphQLInt }, fullName: { type: GraphQLString, sqlExpr: (table, args) => `CONCAT(${table}.first_name, ' ', ${table}.last_name)` }, email: { type: GraphQLString } }) }); const QueryRoot = new GraphQLObjectType({ name: 'Query', fields: { user: { type: UserType, args: { id: { type: GraphQLInt } }, sqlTable: 'users', uniqueKey: 'id', resolve: (parent, args, context, resolveInfo) => { return joinMonster(resolveInfo, context, sql => { return context.db.query(sql); }, { dialect: 'mysql' }); } } } }); const schema = new GraphQLSchema({ query: QueryRoot }); app.use('/graphql', graphqlHTTP({ schema })); app.listen(4000, () => console.log('Server running on port 4000'));
Debug
Known issues
breakingVersion 4.0.0+ requires GraphQL 16 as a peer dependency, dropping support for GraphQL 15.
fix
Upgrade GraphQL to ^16.0.0.
affects: >=4.0.0
breakingjoinMonster() now returns a Promise that resolves to the result data; previously it mutated resolveInfo and returned nothing.
fix
Update resolve functions to await joinMonster() and return its result.
affects: >=4.0.0
deprecatedThe old 'require('join-monster').default' is no longer necessary; default export works directly in ESM.
fix
Use 'import joinMonster from 'join-monster'' instead of require('join-monster').default.
affects: >=4.0.0
gotchasqlTable and uniqueKey must be defined on each GraphQL object type field that uses joinMonster; otherwise resolve fails silently.
fix
Ensure every field that is resolved via joinMonster has sqlTable and uniqueKey properties.
affects: *
gotchajoinMonster does not support GraphQL aliases; using aliases may lead to unexpected SQL or missing data.
fix
Avoid using GraphQL aliases on queries intended to be processed by joinMonster.
affects: *
Errors
Common errors & fixes
joinMonster is not a function
Default import used incorrectly (e.g., import { joinMonster } instead of import joinMonster).
fix
Use default import: import joinMonster from 'join-monster'
Cannot find module 'join-monster'
Package not installed or incorrect import path.
fix
Run npm install join-monster and ensure import path is correct.
TypeError: resolveInfo is not a plain object
joinMonster requires the fourth argument of resolve function (resolveInfo) to be a valid GraphQLResolveInfo object.
fix
Pass resolveInfo directly from the resolve function's arguments.
sqlExpr function not working as expected
sqlExpr is defined on the field but the table alias is not properly referenced.
fix
Use the 'table' parameter provided to sqlExpr, e.g., `table.column_name`.
Upgrade
Version history
4.0.1latest on npm
Audit
Dependencies
graphqlrequiredpeer dependency required for schema introspection and query execution
Agent activity
4 hits · last 30 days
node
4
Resources
join-monster — npm install join-monster · libregistry