mongoose-graphql
v0.0.8
Published
Convert a mongoose model to a GraphQL type string
Downloads
4
Readme
mongoose-graphql
mongoose-graphql converts a mongoose model to graphql types.
Installation
Using npm:
$ npm install --save mongoose-graphql
// using ES6 modules
import { modelToType } from 'mongoose-graphql';
// using CommonJS modules
var mongooseGraphQL = require('mongoose-graphql');
var modelToType = mongooseGraphQL.modelToType;
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 = new Schema({
type: String,
});
const BookModel = mongoose.model('Book', new Schema({
category: CategorySchema,
name: String,
}));
const typeDef = modelToType(BookModel, {
extend: {
Book: {
publishers: '[Publisher]',
},
BookCategory: {
genre: 'Genre',
},
},
});
console.log(typeDef);
Outputs:
type BookCategory {
_id: String
genre: Genre
type: String
}
type Book {
_id: String
category: BookCategory
name: String
publishers: [Publisher]
}