# graphql-type-json

> JSON scalar types for GraphQL.js

Latest version **0.3.2** (published 2020-06-10) · MIT license · 0 weekly downloads

## Install

```sh
npm install graphql-type-json
pnpm add graphql-type-json
yarn add graphql-type-json
bun add graphql-type-json
```

## Health

**Score 45/100 (D)** — status: abandoned.

Positive: has types; esm support; no vulnerabilities; high maintenance score; high quality score.

Warnings: low downloads; pre 1.0.

Negative: abandoned.

## Facts

| | |
|---|---|
| Version | 0.3.2 |
| Published | 2020-06-10 |
| First published | 2016-04-28 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 0 |
| Unpacked size | 11.1 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 983 |
| Author | Jimmy Jia |
| Maintainers | taion |
| Keywords | graphql |

## Links

- npm: https://www.npmjs.com/package/graphql-type-json
- Repository: https://github.com/taion/graphql-type-json
- Homepage: https://github.com/taion/graphql-type-json#readme
- Issues: https://github.com/taion/graphql-type-json/issues
- npm.io page: https://npm.io/package/graphql-type-json

## Alternatives

- [apollo-link-http-common](https://npm.io/package/apollo-link-http-common.md) — 879.0K weekly downloads
- [react-relay](https://npm.io/package/react-relay.md) — 336.8K weekly downloads
- [relay-test-utils](https://npm.io/package/relay-test-utils.md) — 181.6K weekly downloads
- [@vendure/core](https://npm.io/package/@vendure/core.md) — 14.8K weekly downloads
- [@pnpm/deps.graph-sequencer](https://npm.io/package/@pnpm/deps.graph-sequencer.md) — 13.4K weekly downloads

## Recent versions

- 0.3.2 (latest) — 2020-06-10
- 0.3.1 — 2019-11-20
- 0.3.0 — 2019-04-12
- 0.2.4 — 2019-03-29
- 0.2.3 — 2019-03-29
- 0.2.2 — 2019-03-19
- 0.2.1 — 2018-04-13
- 0.2.0 — 2018-02-21
- 0.1.4 — 2016-11-12
- 0.1.3 — 2016-09-06
- 0.1.2 — 2016-06-16
- 0.1.1 — 2016-04-29
- 0.1.0 — 2016-04-28

## README

# graphql-type-json [![Travis][build-badge]][build] [![npm][npm-badge]][npm]

JSON scalar types for [GraphQL.js](https://github.com/graphql/graphql-js).

[![Codecov][codecov-badge]][codecov]

## Usage

This package exports a JSON value scalar GraphQL.js type:

```js
import GraphQLJSON from 'graphql-type-json';
```

It also exports a JSON object scalar type:

```js
import { GraphQLJSONObject } from 'graphql-type-json';
```

These types can also be imported as follows using CommonJS:

```js
const { GraphQLJSON, GraphQLJSONObject } = require('graphql-type-json');
```

`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:

```js
import GraphQLJSON, { GraphQLJSONObject } from 'graphql-type-json';

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

  fields: {
    myValue: { type: GraphQLJSON },
    myObject: { type: GraphQLJSONObject },
  },
});
```

### SDL with [GraphQL-tools](https://github.com/apollographql/graphql-tools)

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

```js
import { makeExecutableSchema } from 'graphql-tools';
import GraphQLJSON, { GraphQLJSONObject } from 'graphql-type-json';

const typeDefs = `
scalar JSON
scalar JSONObject

type MyType {
  myValue: JSON
  myObject: JSONObject
}

# ...
`;

const resolvers = {
  JSON: GraphQLJSON,
  JSONObject: GraphQLJSONObject,
};

export default makeExecutableSchema({ typeDefs, resolvers });
```

[build-badge]: https://img.shields.io/travis/taion/graphql-type-json/master.svg
[build]: https://travis-ci.org/taion/graphql-type-json
[npm-badge]: https://img.shields.io/npm/v/graphql-type-json.svg
[npm]: https://www.npmjs.com/package/graphql-type-json
[codecov-badge]: https://img.shields.io/codecov/c/github/taion/graphql-type-json/master.svg
[codecov]: https://codecov.io/gh/taion/graphql-type-json

---
_Source: https://npm.io/package/graphql-type-json · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
