mongoose-graphql

0.0.8 • Public • Published

mongoose-graphql CircleCI

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]
}

Versions

Current Tags

  • Version
    Downloads (Last 7 Days)
    • Tag
  • 0.0.8
    0
    • latest

Version History

Package Sidebar

Install

npm i mongoose-graphql

Weekly Downloads

0

Version

0.0.8

License

MIT

Last publish

Collaborators

  • jperl