Registry / database / graphql-type-json

graphql-type-json

JSON →
library0.3.2jsnpmunverified

A GraphQL.js library providing JSON scalar types (GraphQLJSON and GraphQLJSONObject) for representing arbitrary JSON values in GraphQL schemas. Current stable version 0.3.2, maintained with low release cadence. Supports GraphQL.js >=0.8.0. Ships TypeScript definitions. Key differentiator: simple, lightweight solution for JSON scalars without additional dependencies. GraphQLJSON handles any JSON-serializable value; GraphQLJSONObject only accepts objects, providing stricter validation. Commonly used in Apollo Server, graphql-tools, and programmatic schema construction.

npm install graphql-type-json
INSTALL
IMPORT
SIG · GRAPHQL-TYPE-JSON
G
graphql-type-json
databasejavascriptv0.3.2
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.

GraphQLJSON
import GraphQLJSON from 'graphql-type-json';
const { GraphQLJSON } = require('graphql-type-json');
Default export for ESM; named export for CJS. In TypeScript, both import patterns may work, but default import is preferred in ESM.
GraphQLJSONObject
import { GraphQLJSONObject } from 'graphql-type-json';
const GraphQLJSONObject = require('graphql-type-json').GraphQLJSONObject;
Named export only. Not a default export.
GraphQLJSON, GraphQLJSONObject
import GraphQLJSON, { GraphQLJSONObject } from 'graphql-type-json';
const { GraphQLJSON, GraphQLJSONObject } = require('graphql-type-json');
For CJS, use named exports only; default export not available.

Creates a GraphQL schema with JSON and JSONObject scalar types using @graphql-tools/schema and graphql-type-json.

import { makeExecutableSchema } from '@graphql-tools/schema'; import GraphQLJSON, { GraphQLJSONObject } from 'graphql-type-json'; const typeDefs = ` scalar JSON scalar JSONObject type Query { myValue: JSON myObject: JSONObject } `; const resolvers = { JSON: GraphQLJSON, JSONObject: GraphQLJSONObject, }; const schema = makeExecutableSchema({ typeDefs, resolvers }); console.log(JSON.stringify(schema, null, 2));
Debug
Known issues
gotchaGraphQLJSON accepts any JSON-serializable value (arrays, objects, scalars), but GraphQLJSONObject rejects non-object values including arrays and null. Use the correct one for your schema.
fix
Use GraphQLJSON for any JSON value; use GraphQLJSONObject for objects only.
affects: >=0.1.0
deprecatedGraphQLJSONObject is not a default export; cannot be imported as default from the package.
fix
Use named import: import { GraphQLJSONObject } from 'graphql-type-json';
affects: >=0.2.0
gotchaThis package requires graphql as a peer dependency. Using an incompatible version may cause runtime errors.
fix
Ensure graphql >=0.8.0 is installed in your project.
affects: >=0.8.0
gotchaWhen using with Apollo Server, the scalar resolvers must be added to the resolver map; they are not automatically applied.
fix
Add JSON: GraphQLJSON and JSONObject: GraphQLJSONObject to your resolvers.
affects: >=0.3.0
Errors
Common errors & fixes
GraphQLError: Type "JSON" not found in document
Missing scalar definition in typeDefs or missing resolver in resolvers map.
fix
Add `scalar JSON` to your typeDefs and map `JSON: GraphQLJSON` in resolvers.
TypeError: GraphQLJSONObject is not a function
Attempting to call GraphQLJSONObject as a function instead of using it as a GraphQL scalar type object.
fix
Use GraphQLJSONObject as a type reference, e.g., `type: GraphQLJSONObject`, not `GraphQLJSONObject()`.
Upgrade
Version history
0.3.2latest on npm
Audit
Dependencies
graphqlrequiredpeer dependency required for GraphQL scalar type integration
Agent activity
8 hits · last 30 days
node
8
Resources
graphql-type-json — npm install graphql-type-json · libregistry