mongoose-graphql
mongoose-graphql converts a mongoose model to graphql types.
Installation
Using npm:
$ npm install --save mongoose-graphql
// using ES6 modules; // using CommonJS modulesvar mongooseGraphQL = ;var modelToType = mongooseGraphQLmodelToType;
API
modelToType
modelToType(model, options)
Convert a mongoose model to graphql types.
You can use this type definition in graphql-tools to build an executable schema.
const CategorySchema = type: String; const BookModel = mongoose; const typeDef = ; console;
Outputs:
type BookCategory {
_id: String
genre: Genre
type: String
}
type Book {
_id: String
category: BookCategory
name: String
publishers: [Publisher]
}
Graphql private properties
Graphql does not allow properties beginning with "__" in types. Otherwise, it will print a message error like this :
Name "__t" must not begin with "__", which is reserved by GraphQL introspection. In a future release of graphql this will become a hard error.
By default, this kind of properties is removed by mongoose-graphql.