graphql-type-json

A JSON scalar type for GraphQL.js schemas

Library
npm
v0.3.2
983 stars
MIT License

Repository Health

Pre-computed score based on development activity, maintenance, community, maturity, and trend momentum. How we score it →
52 /100 Fair
Development Activity 48
Maintenance 20
Community 52
Maturity 60
Momentum 28

Technical Analysis

AI-assessed by reading the actual repository — architecture, code quality, innovation, and documentation. How we score it →
65 /100 Good
Architecture 60
Code Quality 70
Innovation 55
Learning Curve 75

graphql-type-json provides a ready-made JSON scalar type for GraphQL.js, letting schema authors accept and return arbitrary JSON values or JSON objects without hand-writing a custom scalar. It ships both a permissive GraphQLJSON scalar for any JSON-serializable value and a stricter GraphQLJSONObject scalar that only accepts objects, covering the two most common cases teams run into when a field genuinely needs an untyped payload.

The package is a small, focused utility rather than a framework: you import the scalar, wire it into your schema (programmatically or via SDL with graphql-tools), and GraphQL.js handles serialization, parsing, and literal parsing for you. It has been a de facto standard in the GraphQL.js ecosystem for years, with wide adoption across servers built on Apollo Server, express-graphql, and similar tooling.

What You Get

  • A GraphQLJSON scalar type that serializes, parses, and validates any JSON-serializable value (strings, numbers, booleans, arrays, objects, null)
  • A GraphQLJSONObject scalar type that restricts values to JSON objects, rejecting arrays and primitives at the type level
  • Full support for GraphQL literal parsing, so JSON values can appear directly in query documents, not just as variables
  • TypeScript type definitions bundled with the package for both scalars
  • Both CommonJS and ES module builds, plus SDL-friendly resolver map usage with graphql-tools

Common Use Cases

  • Exposing a legacy or third-party API’s loosely-typed JSON payload through a GraphQL field without modeling every possible shape
  • Storing and returning flexible metadata blobs (e.g. user preferences, feature flags, arbitrary config) attached to a typed GraphQL entity
  • Bridging a REST endpoint that returns free-form JSON into a GraphQL schema during incremental migration

Under The Hood

Architecture: The package is a thin wrapper around GraphQL.js’s GraphQLScalarType API. src/index.js defines two scalar instances by supplying serialize, parseValue, and parseLiteral functions; there is no class hierarchy, no build-time codegen, and no runtime state beyond the two exported constants. parseLiteral recursively walks the GraphQL AST (parseLiteral/parseObject helpers) to support JSON literals embedded directly in query documents, which is the one piece of nontrivial logic in the codebase.

Tech Stack: Written in ES2015+ JavaScript, compiled with Babel to both CommonJS (lib/) and ES module (es/) output for dual consumption. The only runtime dependency is a peer dependency on graphql (>=0.8.0); dev dependencies cover Babel, ESLint, Prettier, Jest, and dtslint for type-definition testing.

Code Quality: A single test/index.test.js file exercises both scalars’ serialize/parseValue/parseLiteral paths, including error cases for non-object values passed to GraphQLJSONObject. ESLint and Prettier are enforced via lint-staged pre-commit hooks. The code is small enough (roughly 70 lines) that naming and structure are straightforward; there is no dedicated error-handling layer beyond throwing TypeError for invalid JSONObject values.

API Design: The public surface is exactly two exports (GraphQLJSON default export, GraphQLJSONObject named export), usable with zero configuration — import and drop into a schema’s field type or resolver map. TypeScript definitions are bundled so consumers get type safety without an extra @types install. The README documents both programmatic-schema and SDL/graphql-tools usage patterns, keeping the learning curve minimal.

Used by 5 apps in this directory

TypeScript
96%
Other

Amplication

AI Code Assistants · Automation · Developer Tools

16,015

Create production-ready backend services with your organization's standards baked in — generating NestJS, Prisma, and GraphQL code that you own and control.

View details
58
Repo Health
84
Technical
60
Dependency
Built with
TypeScript 96%
Updated 3 months ago
TypeScript
93%
AGPL 3.0

CourseLit

Blogging · Ecommerce

1,268

Open-source, self-hosted LMS for selling online courses, digital downloads, and building communities on your own branded website.

View details
77
Repo Health
74
Technical
68
Dependency
Built with
TypeScript 93%
Updated 5 days ago
TypeScript
95%
AGPL 3.0

HeyForm

Forms Surveys · No Code Platforms

8,984

Open-source conversational form builder with AI generation, conditional logic, and 30+ integrations — self-host with full data ownership.

View details
83
Repo Health
67
Technical
67
Dependency
Built with
TypeScript 95%
Updated 3 weeks ago
TypeScript
96%
Apache 2.0

Pezzo

AI Development · Monitoring

3,275

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

View details
61
Repo Health
75
Technical
66
Dependency
Built with
TypeScript 96%
Updated 1 months ago
TypeScript
82%
Other

twenty

CRM

57,585

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
TypeScript 82%
MDX 15%
Updated 4 days ago

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