graphql-schema
Create GraphQL schemas with a fluent/chainable interface.
Notice to <=0.3.0 users:
The API has been changed significantly. Rather than hacking ES7 classes, graphql-schema
now implements a fluent/chainable API. As a bonus, we can define entire schemas.
Installation
npm install graphql-schema
Basic Usage
const rootQueryType = ;
becomes
var rootQueryType = name: 'RootQueryType' description: 'TODO: Description' fields: hello: type: GraphQLString description: 'Say Hello to someone' args: name: name: 'name' type: GraphQLString description: 'The name of the person to say Hello to' `Hello, `; ;
Full Example
; const episodeEnum = value'NEWHOPE' 4 'Released in 1977.' value'EMPIRE' 5 'Released in 1980.' value'JEDI' 6 'Released in 1983.' ; const characterInterface = ; const humanType = ; const droidType = ; const queryType = ; const mutationType = ; const starWarsSchema = ;
Cyclic Types
graphql-schema
supports cyclic types. Instead of passing in a reference, just pass in a function instead:
const userType = ;
API
enumType(name, description)
Define a new GraphQLEnumType
.value(name, value, description)
.deprecated(deprecationReason)
interfaceType(name, description)
Define a new GraphQLInterfaceType
.
.field(name, type, description)
.deprecated(deprecationReason)
.arg(name, type, defaultValue, description)
.resolve(fn)
objectType(name, [interfaces], description)
Define a new GraphQLObjectType
.
.field(name, type, description)
.deprecated(deprecationReason)
.arg(name, type, defaultValue, description)
.resolve(fn)
schemaFrom(queryRootType, mutationRootType)
Define a new GraphQLSchema
from the given root types.
listOf(type)
Define a new GraphQLList(type)
.
notNull(type)
Define a new GraphQLNonNull(type)
.
Thanks
Thanks to Florent Cailhol for the chainable interface idea!