{"id":42814,"library":"graphql-scalar-objectid","title":"GraphQL ObjectId Scalar","description":"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.","status":"active","version":"0.1.2","language":"javascript","source_language":"en","source_url":"https://github.com/isayme/graphql-scalar-objectid","tags":["javascript","graphql","scalar","type","objectid","ObjectId","mongo","mongodb"],"install":[{"cmd":"npm install graphql-scalar-objectid","lang":"bash","label":"npm"},{"cmd":"yarn add graphql-scalar-objectid","lang":"bash","label":"yarn"},{"cmd":"pnpm add graphql-scalar-objectid","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"peer dependency; required for GraphQL type definitions","package":"graphql","optional":false}],"imports":[{"note":"Package exposes a single default export (CommonJS). Do not destructure.","wrong":"const { GraphQLObjectId } = require('graphql-scalar-objectid')","symbol":"GraphQLObjectId","correct":"const GraphQLObjectId = require('graphql-scalar-objectid')"},{"note":"No named export; default import only. Package does not ship ESM; this requires transpilation.","wrong":"import { GraphQLObjectId } from 'graphql-scalar-objectid'","symbol":"GraphQLObjectId (ESM)","correct":"import GraphQLObjectId from 'graphql-scalar-objectid'"},{"note":"No type definitions included. Use @types/graphql for GraphQL types. May need esModuleInterop for default import.","wrong":"import GraphQLObjectId from 'graphql-scalar-objectid' (may fail without esModuleInterop)","symbol":"GraphQLObjectId in TypeScript","correct":"const GraphQLObjectId = require('graphql-scalar-objectid')"}],"quickstart":{"code":"const { GraphQLObjectType, GraphQLString, GraphQLSchema, graphql } = require('graphql');\nconst GraphQLObjectId = require('graphql-scalar-objectid');\n\nconst UserType = new GraphQLObjectType({\n  name: 'User',\n  fields: {\n    _id: { type: GraphQLObjectId },\n    name: { type: GraphQLString }\n  }\n});\n\nconst schema = new GraphQLSchema({ query: UserType });\n\n// Example query (requires a resolver)\ngraphql(schema, '{ _id name }', null, { User: { _id: new (require('mongodb').ObjectId)('507f1f77bcf86cd799439011'), name: 'John' } }).then(console.log);","lang":"javascript","description":"Defines a GraphQL object type with _id field using GraphQLObjectId scalar and runs a simple query."},"warnings":[{"fix":"Use require() or transpile with Babel/TypeScript. Install @types if needed.","message":"Package uses CommonJS only; no ESM support or type definitions.","severity":"gotcha","affected_versions":">=0.0.0"},{"fix":"Ensure input values are 24-character hex strings or ObjectId instances.","message":"GraphQLObjectId expects string input or a valid ObjectId hex string; non-hex strings or numbers will throw.","severity":"gotcha","affected_versions":">=0.0.0"},{"fix":"Validate ObjectId strings before passing to GraphQL, or use a custom scalar with error messages.","message":"No validation for incorrect ObjectId format; GraphQL errors may be cryptic.","severity":"gotcha","affected_versions":">=0.0.0"}],"env_vars":null,"search_vec":"'0.1.2':19 '6':62 'beyond':40 'broader':58 'current':17 'depend':39,43 'differenti':44 'focus':47 'function':29 'graphql':1,5,34,41,53,65,68 'graphql-type-json':52 'handl':31 'implement':46 'javascript':67 'json':55 'lightweight':36 'minim':45 'modul':16 'mongo':73 'mongodb':9,74 'node.js':61 'npm':15 'objectid':2,10,32,50,71,72 'packag':11 'parseliter':28 'parsevalu':26 'peer':42 'provid':24 'recent':21 'releas':22 'scalar':3,6,69 'schema':35 'serial':25 'simpl':14 'sole':48 'suitabl':59 'type':7,54,70 'unlik':51 'version':18,66","created_at":"2026-06-05T16:56:48.288733+00:00","updated_at":"2026-06-05T16:56:48.288733+00:00","problems":[{"fix":"Use it as a type in GraphQL schema definitions, e.g., type: GraphQLObjectId, not new GraphQLObjectId().","cause":"Attempted to use GraphQLObjectId as a constructor or function instead of a GraphQL scalar type.","error":"TypeError: ObjectId is not a function"},{"fix":"Provide a 24-character hex string or a MongoDB ObjectId instance (serialized to string).","cause":"Input value is not a valid ObjectId string (e.g., wrong length, non-hex characters).","error":"Expected value of type \"ObjectId\" but got: ..."},{"fix":"Run npm install graphql-scalar-objectid or yarn add graphql-scalar-objectid.","cause":"Package not installed or import path incorrect.","error":"Cannot find module 'graphql-scalar-objectid'"}],"ecosystem":"npm","meta_description":null,"install_score":null,"quickstart_score":null,"quickstart_tag":null,"pypi_latest":null,"cli_name":null,"cli_version":null,"type":"library","homepage":"https://github.com/isayme/graphql-scalar-objectid#readme","github":"https://github.com/isayme/graphql-scalar-objectid","docs":null,"changelog":null,"pypi":null,"npm":"graphql-scalar-objectid","openapi_spec":null,"status_page":null,"smithery":null,"categories":["database"],"base_url":null,"auth_type":null,"provenance":{"verified_status":null,"verified_at":null,"last_verified":"2026-06-05","next_check":"2026-09-03","install_tag":null}}