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-type-object-id'
✗ const GraphQLObjectId = require('graphql-type-object-id')
Default import works in TypeScript and ESM; common mistake is using require (CJS) with a package that has no named default export in CJS.
GraphQLObjectId
✓ import { GraphQLObjectId } from 'graphql-type-object-id'
✗ import { GraphQLObjectId } from 'graphql-type-object-id' is actually correct, but note that the package also supports default import; no wrong pattern for named import aside from using CJS require.
Named import also works as the package exports both a default and a named export.
GraphQLObjectId
✓ const { GraphQLObjectId } = require('graphql-type-object-id')
✗ const GraphQLObjectId = require('graphql-type-object-id').default or require('graphql-type-object-id')
For CommonJS, destructure from the module (which has a named export). Direct require returns an object with GraphQLObjectId property.
Shows how to define a GraphQL schema with ObjectId scalar using graphql-type-object-id and @graphql-tools/schema.
import { makeExecutableSchema } from '@graphql-tools/schema';
import GraphQLObjectId from 'graphql-type-object-id';
const typeDefs = `
scalar ObjectId
type User {
id: ObjectId!
name: String!
}
type Query {
user(id: ObjectId!): User
}
`;
const resolvers = {
ObjectId: GraphQLObjectId,
};
const schema = makeExecutableSchema({ typeDefs, resolvers });
Errors
Common errors & fixes
Error: Cannot find module 'graphql'
Missing or incompatible peer dependency graphql.
fixInstall graphql@16: npm install graphql@16
TypeError: ObjectId is not a function
Incorrect import: using default import in CommonJS without destructuring.
fixUse: const { GraphQLObjectId } = require('graphql-type-object-id'); Error: You must provide a MongoDB ObjectId instance
Passing a plain string instead of ObjectId to the scalar for serialization/validation.
fixEnsure input is a valid ObjectId string (24 hex chars) or a MongoDB ObjectId instance.
Audit
Dependencies
graphqlrequiredPeer dependency for GraphQL scalar type
mongodbrequiredPeer dependency for MongoDB ObjectId class