graphql-scalars

A drop-in library of 70+ precise, spec-compliant GraphQL scalar types for emails, dates, IDs, currencies, and geodata.

Library
npm
v2.0.0
1,930stars
MIT License

Repository Health

Pre-computed score based on development activity, maintenance, community, maturity, and trend momentum.How we score it →
68/100Good
Development Activity52
Maintenance60
Community60
Maturity60
Momentum40

Technical Analysis

AI-assessed by reading the actual repository — architecture, code quality, innovation, and documentation.How we score it →
79/100Good
Architecture78
Code Quality88
Innovation72
Learning Curve78

graphql-scalars is a collection of custom GraphQL scalar types that plug directly into any GraphQL.js-based schema, replacing loosely-typed String and Int fields with scalars that validate real-world formats — email addresses, ISO dates, UUIDs, phone numbers, currency codes, hex colors, IBANs, and dozens more. Each scalar implements the full GraphQLScalarType contract (serialize, parseValue, parseLiteral) so invalid input is rejected at the GraphQL layer itself, before it ever reaches resolver logic.

Maintained by The Guild (the team behind GraphQL Tools, GraphQL Mesh, and GraphQL Yoga), the library ships matching type definitions, resolver maps, and mock values for every scalar, plus optional JSON Schema and codegen-scalar metadata so tools like GraphQL Code Generator can infer the right TypeScript type automatically. It supports both graphql@16 and graphql@17 and is published as a dual ESM/CJS package.

What You Get

  • 70+ prebuilt GraphQL scalar types covering dates/times, network addresses, financial identifiers, geodata, and more
  • Matching typeDefs, mocks, and resolver maps exported per-scalar for drop-in use with any schema
  • A GeoJSON scalar with full type validation for Point, LineString, Polygon and other geometry types
  • JSON Schema and codegen-scalar metadata attached to scalars for GraphQL Code Generator integration
  • Dual ESM/CJS build with TypeScript typings, compatible with graphql@16 and graphql@17

Common Use Cases

  • Enforcing email/phone/URL format at the schema boundary instead of in every resolver
  • Representing dates and times precisely (Date, DateTime, LocalTime, Duration, Timestamp) across timezones
  • Validating financial and identity fields — IBAN, currency codes, SSNs, patents, ISBNs — in fintech and commerce APIs
  • Accepting arbitrary JSON payloads via the JSON/JSONObject scalars for flexible or legacy data
  • Generating mock data and TypeScript types automatically via GraphQL Code Generator’s codegen-scalar support

Under The Hood

Architecture The library is organized as a flat collection of independent scalar modules under src/scalars/, each built from a shared serialize/parseValue/parseLiteral triplet, plus a base RegularExpression class (src/RegularExpression.ts) that many scalars extend for regex-based validation, and a shared createGraphQLError helper (src/error.ts) that shims between graphql v16 and v17 error constructors. Subdirectories (GeoJSON/, iso-date/, json/, library/, patent/, ssn/) group related scalars needing dedicated validators or formatters. All scalars, plus their generated mocks (src/mocks.ts) and SDL typeDefs (src/typeDefs.ts), are re-exported through a single src/index.ts barrel file, so the architecture is a flat, additive registry rather than a layered runtime — there’s no central dispatch, and each scalar file is fully self-contained and independently testable. Changing the shared error helper or RegularExpression base class is the only thing that ripples across the package; adding a new scalar is a pure addition needing no coordination elsewhere.

Tech Stack Written in TypeScript, targeting the graphql package as a peer dependency (^16.0.0 || ^17.0.0) with runtime code depending only on tslib. Built with bob-the-bundler into dual ESM and CJS outputs plus separate typings, matching the package.json exports map. Tests run on Vitest with a graphql-16/graphql-17 matrix, linting via ESLint with typescript-eslint and import/n/promise plugins, formatting via Prettier and The Guild’s shared config, with pre-commit enforcement via Husky and lint-staged. Releases are managed with Changesets, publishing to npm with provenance. A companion Next.js documentation site (graphql-scalars.dev) is built and deployed separately. CI runs on GitHub Actions using The Guild’s shared reusable workflows across multiple Node versions.

Code Quality Virtually every scalar has a matching test file exercising serialize/parseValue/parseLiteral for both valid and invalid inputs, plus dedicated common and snapshot tests. Error handling is explicit and typed: invalid input always throws via the shared createGraphQLError helper with a descriptive message, never swallowed or silently coerced. TypeScript is used throughout with real generic type parameters on scalar configs, and naming is consistent (GraphQL<Name> for the scalar instance, GraphQL<Name>Config for its config object). ESLint, Prettier, and a pre-commit hook enforce style, and CI runs the full test matrix across Node versions and both supported graphql major versions before merge.

API Design The core value isn’t a novel algorithm but disciplined API design: every scalar is exported multiple ways (the scalar instance, a resolver alias, a mock value, and an SDL type definition) so consumers can cherry-pick just the piece they need — a resolver map for schema stitching, a mock for testing, or an SDL string for schema-first tooling — without pulling in the whole package. The codegenScalarType and jsonSchema extensions on each scalar are a genuinely useful developer-experience touch: they let GraphQL Code Generator and JSON-Schema-consuming tools infer the correct underlying type automatically instead of requiring manual per-scalar config. Getting started requires no boilerplate — import the named scalar and attach it to a resolver map. The tradeoff is breadth over depth: scalars are intentionally simple format validators rather than configurable systems, which keeps the API predictable but means custom validation logic still requires wrapping.

Used by 7 apps in this directory

TypeScript
87%
Other

AFFiNE

Productivity · Project Management · Note Taking

72,238

Write, draw, and plan in one infinite canvas — the open-source alternative to Notion and Miro that keeps your data yours.

View details
91
Repo Health
87
Technical
67
Dependency
Built with
TypeScript87%
Updated yesterday
TypeScript
99%
MIT

GraphQL Hive

Developer Tools · Devops · Monitoring

484

Open-source GraphQL schema registry and observability platform with breaking change detection, federation support, and CI/CD integration for teams of any size.

View details
89
Repo Health
81
Technical
69
Dependency
Built with
TypeScript99%
Updated 2 days ago
TypeScript
96%
MIT

Payload CMS

Developer Tools · Blogging · CMS

44,600

The open-source, Next.js-native headless CMS that lives inside your /app folder and gives you a full TypeScript backend instantly.

View details
91
Repo Health
88
Technical
65
Dependency
Built with
TypeScript96%
Updated 3 days ago
TypeScript
96%
Apache 2.0

Pezzo

AI Development · Monitoring

3,270

Open-source LLMOps platform for prompt management, AI observability, intelligent caching, and real-time cost tracking across LLM providers.

View details
63
Repo Health
75
Technical
66
Dependency
Built with
TypeScript96%
Updated 2 weeks ago
TypeScript
88%
Other

strapi

CMS

73,083

Open-source headless CMS that auto-generates REST and GraphQL APIs from your content models, with a fully customizable admin panel you control.

View details
93
Repo Health
84
Technical
66
Dependency
Built with
TypeScript88%
JavaScript12%
Updated yesterday
TypeScript
80%
Other

twenty

CRM

56,361

The open-source CRM you build, ship, and version like the rest of your stack — with customizable objects, AI agents, and a TypeScript SDK.

View details
92
Repo Health
82
Technical
64
Dependency
Built with
TypeScript80%
MDX17%
Updated yesterday
TypeScript
85%
Other

Webiny JS

Ecommerce · Blogging · CMS

8,032

Open-source, self-hosted CMS on AWS serverless — a TypeScript framework you extend with code, not a product you configure through a UI.

View details
90
Repo Health
86
Technical
62
Dependency
Built with
TypeScript85%
JavaScript14%
Updated yesterday

Join founders buildingwith open source

Opinionated takes, migration guides, cost-saving tips, and insights from the open source ecosystem.

Subscribe on Substack
Join 750+ subscribers

Search