graphql-type-json
JSON scalar types for GraphQL.js.
Usage
This package exports a JSON value scalar GraphQL.js type:
;
It also exports a JSON object scalar type:
;
These types can also be imported as follows using CommonJS:
const GraphQLJSON GraphQLJSONObject = ;
GraphQLJSON
can represent any JSON-serializable value, including scalars, arrays, and objects. GraphQLJSONObject
represents specifically JSON objects, which covers many practical use cases for JSON scalars.
Programmatically-constructed schemas
You can use this in a programmatically-constructed schema as with any other scalar type:
; ;
GraphQL-tools
SDL withWhen using the SDL with GraphQL-tools, define GraphQLJSON
as the resolver for the appropriate scalar type in your schema:
;; const typeDefs = `scalar JSONscalar JSONObject type MyType { myValue: JSON myObject: JSONObject} # ...`; const resolvers = JSON: GraphQLJSON JSONObject: GraphQLJSONObject; typeDefs resolvers ;