Registry / database / graphql-objectid-scalar

graphql-objectid-scalar

JSON →
library1.0.5jsnpmunverified

graphql-objectid-scalar (v1.0.5) is a lightweight GraphQL.js scalar type for MongoDB ObjectId values. It serializes ObjectId instances from mongodb to strings, parses strings back into ObjectId, and validates ObjectId format. Ships TypeScript types, requires peer dependencies graphql >=0.8.0 and mongodb >=3.0.0. Key differentiator: minimal, tested in CI, designed for use with graphql-tools. Released with low maintenance cadence.

npm install graphql-objectid-scalar
INSTALL
IMPORT
SIG · GRAPHQL-OBJECTID-S
G
graphql-objectid-scalar
databasejavascriptv1.0.5
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.

GraphQLObjectId
import { GraphQLObjectId } from 'graphql-objectid-scalar'
const GraphQLObjectId = require('graphql-objectid-scalar')
Default export not available; must use named import.
default
import graphqlObjectId from 'graphql-objectid-scalar'
import { default } from 'graphql-objectid-scalar'
Package does not export a default; use named import GraphQLObjectId.
GraphQLObjectId (resolver)
resolvers: { GraphQLObjectId: GraphQLObjectId }
resolvers: { GraphQLObjectId: graphqlObjectId }
When using as resolver in graphql-tools, must use the same named export.

Shows how to define and use the GraphQLObjectId scalar in a GraphQL schema with graphql-tools.

import { GraphQLObjectId } from 'graphql-objectid-scalar';\nimport { makeExecutableSchema } from '@graphql-tools/schema';\n\nconst typeDefs = `\n scalar GraphQLObjectId\n\n type User {\n _id: GraphQLObjectId\n name: String\n }\n\n type Query {\n user(id: GraphQLObjectId): User\n }\n`;\n\nconst resolvers = {\n GraphQLObjectId,\n Query: {\n user: (_, { id }) => ({ _id: id, name: 'John Doe' })\n }\n};\n\nconst schema = makeExecutableSchema({ typeDefs, resolvers });\nconsole.log('Schema created with GraphQLObjectId scalar');
Debug
Known issues
breakingRequires mongodb peer dependency >=3.0.0; ObjectId class may change in mongodb driver v5+
fix
Update mongodb to v3.x or v4.x; check ObjectId compatibility for v5.
affects: <1.0.0
deprecatedgraphql-tools package is legacy; use @graphql-tools/schema instead.
fix
Replace import from 'graphql-tools' to '@graphql-tools/schema'.
affects: >=1.0.0
gotchaThe scalar validates ObjectId format only; may not handle all edge cases (e.g., 12-byte hex strings).
fix
Ensure input is a 24-character hex string.
affects: >=0.0.0
Errors
Common errors & fixes
Cannot find module 'graphql-objectid-scalar'
Package not installed or missing from dependencies.
fix
Run npm install graphql-objectid-scalar graphql mongodb
GraphQLObjectId is not a constructor
Using require incorrectly or importing default instead of named export.
fix
Use import { GraphQLObjectId } from 'graphql-objectid-scalar'
TypeError: Cannot read properties of undefined (reading 'prototype')
Missing peer dependency mongodb.
fix
Install mongodb: npm install mongodb
Upgrade
Version history
1.0.5latest on npm
Audit
Dependencies
graphqlrequiredpeer dependency for GraphQL scalar type definition
mongodbrequiredpeer dependency for ObjectId class; required at runtime
Agent activity
24 hits · last 30 days
node
22
Resources
graphql-objectid-scalar — npm install graphql-objectid-scalar · libregistry