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 🙏

© 2025 – Pkg Stats / Ryan Hefner

mongoose2gql

v0.0.4

Published

## 警告 > 這個套件目前還在實驗階段

Downloads

12

Readme

Mongoose Schema To GraphQL Object

警告

這個套件目前還在實驗階段

前言

這個套件參考了 https://github.com/sarkistlt/mongoose-schema-to-graphql

並且新增了一些目前我需要的東西,分別是:

  1. 將GraphQL Fields 定義改為閉包(Closure)的方式,讓各個Type間可以循環參照 (當然你不一定要讓他循環參照)

  2. 不採用亂數命名的方式 (命名管理起來太亂了)

  3. Array型態不單單只轉變成[String]

  4. 加入了GraphQLNonNull的支持

Install

$ npm i -S mongoose2gql

Method

/**
 * @params {string} name
 * @params {mongooseSchema} schema
 * @params {string} class Enum["GraphQLObjectType", "GraphQLInputObjectType"]
 * @params {string} description
 * @params {function} extends
 *         @return Object
 * @return GraphQLType[class]
 */
createType({
  name,
  schema,
  class,
  description,
  extends
})

Exmaple

schema

import mongoose from "mongoose"
import {
  GraphQLFloat
} from "graphql"
import b from "./b";

let Schema = mongoose.Schema;
export default Schema({
  stringType: String,
  numberType: Number,
  floatType: {
    type: Number,
    graphql: GraphQLFloat   //強制使用這個型別
  },
  dateType: Date,
  requiredType: {
    required: true,
    type: String
  },
  arrayTypeString: [String],
  arrayTypeNumber: [Number],
  tree: {
    title: String,
    tree: {
      title: String,
      titleArray: [String],
      titleObject: {
        subTitle: String,
        subsubTitle: String,
        createAt: Date
      }
    }
  },
  EmbeddedB: b,
  EmbeddedBArray: [b],
  __v: Number
}, {timestamp: true});

import createType from "../../src";
import schema from "../schema/a";
import BType from "./BType";

export default createType({
  name: "AType",
  schema,
  extends: () => ({
    BType: {
      type: BType
    }
  }),
  exclude: ["_id"]
})

這個範例會等於

type AType {
  stringType: String
  numberType: Int
  floatType: Float
  dateType: String
  requiredType: String!
  arrayTypeString: [String]
  arrayTypeNumber: [Int]
  EmbeddedB: AType_EmbeddedB
  EmbeddedBArray: [AType_EmbeddedBArray]
  tree: AType_tree
  BType: BType
}