JSON scalar type for GraphQL.js
Clone or download

README.md

graphql-type-json Travis npm

JSON scalar type for GraphQL.js.

Codecov

Usage

This package exports a JSON scalar GraphQL.js type:

import GraphQLJSON from 'graphql-type-json';

Programmatically-constructed schemas

You can use this in a programmatically-constructed schema as with any other scalar type:

import { GraphQLObjectType } from 'graphql';
import GraphQLJSON from 'graphql-type-json';

export default new GraphQLObjectType({
  name: 'MyType',

  fields: {
    myField: { type: GraphQLJSON },
  },
});

SDL with GraphQL-tools

When using the SDL with GraphQL-tools, define GraphQLJSON as the resolver for the appropriate scalar type in your schema:

import { makeExecutableSchema } from 'graphql-tools';
import GraphQLJSON from 'graphql-type-json';

const typeDefs = `
scalar JSON

type MyType {
  myField: JSON
}

# ...
`;

const resolvers = {
  JSON: GraphQLJSON,
};

export default makeExecutableSchema({ typeDefs, resolvers });