Registry /
database / graphql-objectid-scalar
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');
Errors
Common errors & fixes
Cannot find module 'graphql-objectid-scalar'
Package not installed or missing from dependencies.
fixRun npm install graphql-objectid-scalar graphql mongodb
GraphQLObjectId is not a constructor
Using require incorrectly or importing default instead of named export.
fixUse import { GraphQLObjectId } from 'graphql-objectid-scalar' TypeError: Cannot read properties of undefined (reading 'prototype')
Missing peer dependency mongodb.
fixInstall mongodb: npm install mongodb
Audit
Dependencies
graphqlrequiredpeer dependency for GraphQL scalar type definition
mongodbrequiredpeer dependency for ObjectId class; required at runtime