Skip to content

Commit

Permalink
Add real usage example to README (#32)
Browse files Browse the repository at this point in the history
  • Loading branch information
cooperka authored and taion committed May 20, 2018
1 parent 93ae4ab commit 5790abc
Showing 1 changed file with 44 additions and 0 deletions.
44 changes: 44 additions & 0 deletions README.md
Expand Up @@ -6,8 +6,52 @@ JSON scalar type for [GraphQL.js](https://github.com/graphql/graphql-js).

## Usage

This package exports a JSON scalar GraphQL.js type:

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

### Programmatically-constructed schemas

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

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

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

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

### 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 from 'graphql-type-json';

const typeDefs = `
scalar JSON
type MyType {
myField: JSON
}
# ...
`;

const resolvers = {
JSON: GraphQLJSON,
};

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

[build-badge]: https://img.shields.io/travis/taion/graphql-type-json/master.svg
Expand Down

0 comments on commit 5790abc

Please sign in to comment.