npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

graphql-mongoose-schemabuilder

v1.0.10

Published

Auto generate graphql compose schema from mongoose models

Readme

graphql-mongoose-schemabuilder

This is a plugin for graphql-compose-mongoose and graphql-compose, which derives GraphQLType from your mongoose model. Also derives bunch of internal GraphQL Types. Auto generates schema composer, including graphql connection, also provided basic search via operators ($lt, $gt and so on) with a added feature to Search by regular expression.

Installation

npm install graphql graphql-compose mongoose graphql-compose-mongoose graphql-mongoose-schemabuilder --save

Modules graphql, graphql-compose, mongoose, graphql-compose-mongoose are in peerDependencies, so should be installed explicitly in your app. They have global objects and should not have ability to be installed as submodule.

Example

Source code: https://github.com/ShaneAlexGraham/graphql-mongoose-example

const mongoose = require('mongoose');
const { buildSchemaFromModels } = require('graphql-mongoose-schemabuilder');

// STEP 1: DEFINE MONGOOSE SCHEMA AND MODEL
const LanguagesSchema = new mongoose.Schema({
  language: String,
  skill: {
    type: String,
    enum: [ 'basic', 'fluent', 'native' ],
  },
});

const UserSchema = new mongoose.Schema({
  name: String, // standard types
  age: {
    type: Number,
    index: true,
  },
  ln: {
    type: [LanguagesSchema], // you may include other schemas (here included as array of embedded documents)
    default: [],
    alias: 'languages', // in schema `ln` will be named as `languages`
  },
  contacts: { // another mongoose way for providing embedded documents
    email: String,
    phones: [String], // array of strings
  },
  gender: { // enum field with values
    type: String,
    enum: ['male', 'female'],
  },
  someMixed: {
    type: mongoose.Schema.Types.Mixed,
    description: 'Can be any mixed type, that will be treated as JSON GraphQL Scalar Type',
  },
});
const User = mongoose.model('User', UserSchema);

const NotesSchema = new mongoose.Schema({
  name: String,
  description: String,
  type: {
    type: String,
    enum: [ 'sticky', 'default'],
  },
  createdby: {  type: mongoose.Schema.Types.ObjectId,  ref: 'User'  }
});
const Note = mongoose.model('User', UserSchema);

// STEP 2: DEFINE MODEL TO IMPORT (THIS CAN ALSO BE A STANDARD ARRAY INSTEAD OF A OBJECT)
const models = {
    Notes: Note,
    Users: User
}

// STEP 3: USE MODELS TO BUILD SCHEMA
const schema = buildSchemaFromModels(models);

// STEP 4: USE SCHEMA IN YOUR FAVORITE GRAPHQL ENGINE
const gqlServer = new ApolloServer({
  schema: schema 
});

Query

Filter by fields

Filter by fields

Filter by fields

Forward pagination argument for returning at most first edges

Forward pagination argument for returning at most first edges

Backward pagination argument for returning at most last edges

Backward pagination argument for returning at most last edges

Filter by fields

Sort argument for data ordering

Page number for displaying

Filter by fields

Mutation

Create one document with mongoose defaults, setters, hooks and validation

Creates Many documents with mongoose defaults, setters, hooks and validation

Update one document: 1) Retrieve one document by findById. 2) Apply updates to mongoose document. 3) Mongoose applies defaults, setters, hooks and validation. 4) And save it.

Update one document: 1) Retrieve one document via findOne. 2) Apply updates to mongoose document. 3) Mongoose applies defaults, setters, hooks and validation. 4) And save it.

Filter by fields

Update many documents without returning them: Use Query.update mongoose method. Do not apply mongoose defaults, setters, hooks and validation.

Filter by fields

Remove one document: 1) Retrieve one document and remove with hooks via findByIdAndRemove. 2) Return removed document.

Remove one document: 1) Remove with hooks via findOneAndRemove. 2) Return removed document.

Filter by fields

Remove many documents without returning them: Use Query.remove mongoose method. Do not apply mongoose defaults, setters, hooks and validation.

Filter by fields

Objects

CreateManyExamplePayload

Created document ID

Created documents

Count of all documents created

CreateOneExamplePayload

Created document ID

Created document

Example

ExampleConnection

A connection to a list of items.

Total object count.

Information to aid in pagination.

Information to aid in pagination.

ExampleEdge

An edge in a connection.

The item at the end of the edge

A cursor for use in pagination

ExamplePagination

List of items with pagination.

Total object count.

Array of objects.

Information to aid in pagination.

PageInfo

Information about pagination in a connection.

When paginating forwards, are there more items?

When paginating backwards, are there more items?

When paginating backwards, the cursor to continue.

When paginating forwards, the cursor to continue.

PaginationInfo

RemoveByIdExamplePayload

Removed document ID

Removed document

RemoveManyExamplePayload

Affected documents number

RemoveOneExamplePayload

Removed document ID

Removed document

UpdateByIdExamplePayload

Updated document ID

Updated document

UpdateManyExamplePayload

Affected documents number

UpdateOneExamplePayload

Updated document ID

Updated document

Inputs

CreateManyExampleInput

CreateOneExampleInput

ExampleSearch

String or Regular Expression

field to apply regular expression

FilterExampleInput

List of indexed fields that can be filtered via operators.

FilterFindManyExampleInput

List of indexed fields that can be filtered via operators.

Search by String or Regular Expression

FilterFindOneExampleInput

List of indexed fields that can be filtered via operators.

FilterRemoveManyExampleInput

List of indexed fields that can be filtered via operators.

FilterRemoveOneExampleInput

List of indexed fields that can be filtered via operators.

FilterUpdateManyExampleInput

List of indexed fields that can be filtered via operators.

FilterUpdateOneExampleInput

List of indexed fields that can be filtered via operators.

OperatorsFilterExampleInput

For performance reason this type contains only indexed fields.

OperatorsFilterFindManyExampleInput

For performance reason this type contains only indexed fields.

OperatorsFilterFindOneExampleInput

For performance reason this type contains only indexed fields.

OperatorsFilterRemoveManyExampleInput

For performance reason this type contains only indexed fields.

OperatorsFilterRemoveOneExampleInput

For performance reason this type contains only indexed fields.

OperatorsFilterUpdateManyExampleInput

For performance reason this type contains only indexed fields.

OperatorsFilterUpdateOneExampleInput

For performance reason this type contains only indexed fields.

UpdateByIdExampleInput

UpdateManyExampleInput

UpdateOneExampleInput

_idOperatorsFilterExampleInput

_idOperatorsFilterFindManyExampleInput

_idOperatorsFilterFindOneExampleInput

_idOperatorsFilterRemoveManyExampleInput

_idOperatorsFilterRemoveOneExampleInput

_idOperatorsFilterUpdateManyExampleInput

_idOperatorsFilterUpdateOneExampleInput

Enums

SortConnectionExampleEnum

SortFindByIdsExampleInput

SortFindManyExampleInput

SortFindOneExampleInput

SortRemoveOneExampleInput

SortUpdateManyExampleInput

SortUpdateOneExampleInput

Scalars

Boolean

The Boolean scalar type represents true or false.

Int

The Int scalar type represents non-fractional signed whole numeric values. Int can represent values between -(2^31) and 2^31 - 1.

MongoID

The ID scalar type represents a unique MongoDB identifier in collection. MongoDB by default use 12-byte ObjectId value (https://docs.mongodb.com/manual/reference/bson-types/#objectid). But MongoDB also may accepts string or integer as correct values for _id field.

String

The String scalar type represents textual data, represented as UTF-8 character sequences. The String type is most often used by GraphQL to represent free-form human-readable text.

License

MIT