mirror of https://gitee.com/antv-l7/antv-l7
f7e5376b7d | ||
---|---|---|
.. | ||
lib | ||
LICENSE | ||
README.md | ||
package.json |
README.md
graphql-type-json
JSON scalar type for GraphQL.js.
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 });