Registry / storage / graphql-custom-types

graphql-custom-types

JSON →
library1.7.0jsnpmunverified

Collection of custom GraphQL scalar types including Email, URL, DateTime, LimitedString, Password, and UUID. Current stable version is 1.7.0. The package has a low release cadence (last release in 2022) and supports a wide range of GraphQL versions (0.6 to 16). It provides ready-to-use types for common domain-specific validations, with type definitions included. Alternatives like graphql-type-json or graphql-scalars offer broader collections, but this package focuses on essential types with minimal configuration.

npm install graphql-custom-types
INSTALL
IMPORT
SIG · GRAPHQL-CUSTOM-TYP
G
graphql-custom-types
storagejavascriptv1.7.0
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.

GraphQLEmail
import { GraphQLEmail } from 'graphql-custom-types'
const GraphQLEmail = require('graphql-custom-types').GraphQLEmail
Default named import; no default export exists.
GraphQLLimitedString
import { GraphQLLimitedString } from 'graphql-custom-types'
import GraphQLLimitedString from 'graphql-custom-types'
Must use named import; default import will be undefined.
GraphQLUUID
import { GraphQLUUID } from 'graphql-custom-types'
const { GraphQLUUID: uuid } = require('graphql-custom-types')
Correct require destructuring but note the renaming is allowed.

Shows how to define a GraphQL schema using custom scalar types Email, URL, and UUID, and attach them to resolvers.

import { buildSchema } from 'graphql'; import { GraphQLEmail, GraphQLURL, GraphQLUUID } from 'graphql-custom-types'; const schema = buildSchema(` scalar Email scalar URL scalar UUID type User { email: Email website: URL id: UUID } type Query { user: User } `); // When attaching to resolvers, use the custom types directly const resolvers = { Email: GraphQLEmail, URL: GraphQLURL, UUID: GraphQLUUID }; // query { user { email website } } console.log('Schema ready');
Debug
Known issues
deprecatedGraphQLDateTime is deprecated in favor of using a more complete library like graphql-scalars.
fix
Switch to graphql-scalars for DateTime type.
affects: >=1.0.0
gotchaGraphQLLimitedString must be instantiated with 'new' when passing parameters, e.g., new GraphQLLimitedString(1, 100).
fix
Use 'new' keyword: const LimitedString = new GraphQLLimitedString(1, 100);
affects: >=1.0.0
breakingPeer dependency graphql >= 0.6.0 to < 17, but GraphQL v16 requires custom scalar parsing changes. This package may not fully work with v16.
fix
Pin graphql to v15.x or verify compatibility.
affects: >=1.7.0
gotchaThe package does not provide a default export; all imports must be named.
fix
Use import { GraphQLEmail } from 'graphql-custom-types';
affects: >=1.0.0
Errors
Common errors & fixes
Error: Cannot find module 'graphql-custom-types'
Missing package installation or missing graphql peer dependency.
fix
Run npm install graphql graphql-custom-types
Cannot use GraphQLScalarType from a different module; module graphql-custom-types expects 'graphql' version ^14.0.0 but you have graphql@16.0.0
Peer dependency mismatch; graphql versions may be incompatible.
fix
Install graphql v14 or v15: npm install graphql@15
TypeError: Class constructor GraphQLLimitedString cannot be invoked without 'new'
GraphQLLimitedString with parameters must be instantiated with new.
fix
Use 'new GraphQLLimitedString(...)'
Upgrade
Version history
1.7.0latest on npm
Audit
Dependencies
graphqlrequiredPeer dependency; required to define GraphQL types.
Agent activity
32 hits · last 30 days
node
28
OpenAI (training)
1
Resources
graphql-custom-types — npm install graphql-custom-types · libregistry