A GraphQL scalar type for MongoDB ObjectId, packaged as a simple npm module. Current version 0.1.2 (no recent releases). It provides serialize, parseValue, and parseLiteral functions to handle ObjectId in GraphQL schemas. Lightweight with no dependencies beyond graphql peer dependency. Differentiator: minimal implementation focused solely on ObjectId, unlike graphql-type-json which is broader. Suitable for Node.js >=6 with any GraphQL version.
npm install graphql-scalar-objectidNo compatibility data collected yet for this library.
Verified import paths — ran on the pinned version, not inferred.
Defines a GraphQL object type with _id field using GraphQLObjectId scalar and runs a simple query.
Use require() or transpile with Babel/TypeScript. Install @types if needed.
Ensure input values are 24-character hex strings or ObjectId instances.
Validate ObjectId strings before passing to GraphQL, or use a custom scalar with error messages.
Use it as a type in GraphQL schema definitions, e.g., type: GraphQLObjectId, not new GraphQLObjectId().
Provide a 24-character hex string or a MongoDB ObjectId instance (serialized to string).
Run npm install graphql-scalar-objectid or yarn add graphql-scalar-objectid.