Graphqlize
Warning: Work In Progress
This library creates a GraphQL schema from plain JavaScript classes. With this code:
/** * List a few comments * @param * @param * @param * @param * @return */ static { return text: 'hello world!' } { /** @type {string!} - The id of a comment */ thisid = null /** @type */ thistext = null /** @type */ thisdeleted = null } /** * Gets whatever * @param * @return */ { return Promise }
Just using graphqlize
const createSchema = const schema =
You get a GraphQL schema with this schema:
type Comment {
# The id of a comment
id: String!
# The content of a comment
text: String
# Flag that indicates if the comment was deleted
deleted: Boolean
whatever: String
}
type Query {
list(limit: Int, offset: Int): [Comment]
}
Once you have the schema you can run a server with it:
var app = app
Based on JSDocs
Each class represents a GraphQL type
. You annotate the classes with standard JSDocs attributes. It supports the following types:
- string: maps to GraphQLString
- number or float: maps to GraphQLFloat
- int: maps to GraphQLInt
- boolean: maps to GraphQLBoolean
- ID: GraphQLID
- Custom types
- Arrays of any previous type
- not-nullability with
{type!}
- using
@param {context}
in a particular field you will get the GraphQL context injected for that argument
You just need to call createSchema
passing all the types/classes that you want to expose
The first class will be the root
in the schema. Methods act like attributes with arguments. They can be static
or not.