Registry / database / graphql-anywhere-mongodb

graphql-anywhere-mongodb

JSON →
library0.5.2jsnpmunverified

An experimental library that bridges GraphQL queries to MongoDB collections using graphql-anywhere. Version 0.5.2 is the latest and only stable release. It allows querying MongoDB with GraphQL syntax, supporting projections, filtering (eq, gte, gt, etc.), pagination (limit/skip), sorting via @sort/@sortDesc directives, and multiple collections per query. Key differentiator: schemaless querying without defining a GraphQL schema upfront. However, it is explicitly marked as not production-ready and has no recent updates since 2017. Use with caution for prototyping only.

npm install graphql-anywhere-mongodb
INSTALL
IMPORT
SIG · GRAPHQL-ANYWHERE-M
G
graphql-anywhere-mongodb
databasejavascriptv0.5.2
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.

default
import graphql from 'graphql-anywhere-mongodb'
import graphql from 'graphql-anywhere-mongodb'
Default import is the only way; named exports are not available. ESM-only, no CJS support.
forUri
const mongo = await graphql.forUri('mongodb://...')
const mongo = graphql.forUri('mongodb://...')
forUri returns a promise; must be awaited or chained with .then().
forConnection
const mongo = graphql.forConnection(existingDbConnection)
const mongo = graphql.forConnection('mongodb://...')
forConnection expects a MongoDB Db instance, not a URI string.

Connects to MongoDB, executes a GraphQL query on the 'users' collection with limit and filter, then prints results.

import graphql from 'graphql-anywhere-mongodb'; import gql from 'graphql-tag'; async function main() { const mongo = await graphql.forUri(process.env.MONGO_URI ?? 'mongodb://localhost:27017/mydb'); const query = gql` { users (limit: 10) { firstName lastName age (gte: 21) } } `; const results = await mongo.find(query, {}); console.log(results); } main().catch(console.error);
Debug
Known issues
deprecatedThis library is marked as experimental and not recommended for production use.
fix
Consider using an alternative like graphql-compose-mongoose or PostGraphile for production.
affects: >0.0.0
gotchaImports must be the default import; named imports (e.g., import { forUri }) will fail.
fix
Use import graphql from 'graphql-anywhere-mongodb' and then call graphql.forUri().
affects: >=0.0.0
gotchaforUri() returns a Promise; must be awaited or used with .then() to get the executor.
fix
Always use await: const mongo = await graphql.forUri(...).
affects: >=0.0.0
breakingSince v0.5.0, the library switched to ESM-only; CommonJS require() will not work.
fix
Use ES modules and import syntax. If you need CJS, stick to v0.4.x or transpile.
affects: >=0.5.0
gotchaThe MongoDB _id field is always returned regardless of the GraphQL query projection.
fix
Be aware that _id is always included in results; filter if needed.
affects: >=0.0.0
Errors
Common errors & fixes
graphql.forUri is not a function
Incorrect import: using named import instead of default import.
fix
Replace import { forUri } from 'graphql-anywhere-mongodb' with import graphql from 'graphql-anywhere-mongodb'.
TypeError: graphql.forUri(...) is undefined
forUri returns a Promise not caught properly.
fix
Use await: const mongo = await graphql.forUri(...).
Cannot find module 'graphql-anywhere'
Peer dependency graphql-anywhere is missing.
fix
Install the peer dependency: npm install graphql-anywhere.
MissingSchemaError: Schema hasn't been registered for model "users"
This error is from mongoose, not this library. Ensure you are using native MongoDB driver, not Mongoose.
fix
Use mongodb native driver instead of mongoose.
Upgrade
Version history
0.5.2latest on npm
Audit
Dependencies
graphql-tagrequiredRequired for parsing GraphQL queries using the gql template literal.
graphql-anywhererequiredCore dependency providing the graphql-anywhere infrastructure for custom resolvers.
mongodbrequiredNative MongoDB driver for connection and query execution.
Agent activity
4 hits · last 30 days
node
4
Resources
graphql-anywhere-mongodb — npm install graphql-anywhere-mongodb · libregistry