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

cgs

v0.2.3

Published

Create GraphQL Server

Readme

Create GraphQL Server

1. 安装

$ brew install yarn
$ npm i -g cgs

2. 使用

初始化空项目

$ cgs init <project-directory>

添加类型

$ cd <project-directory>
$ cgs add <path-to-schema.graphql>

由模板生成整个项目

$ cd <project-directory>
$ cgs add <inputDir> 

3. 开发

$ git clone https://github.com/wmzhai/cgs.git && cd cgs
$ yarn install
$ npm link

注意:仅在node版本7.6.0以上支持vscode调试

4. Schema编写指南

4.1 命名规范

  • 文件名小写开头驼峰形式文件,后缀为graphql
  • add type时会自动添加id, createdAt和updatedAt,所以在编写inputSchema时不需要添加
  • 字段名称小写开头驼峰形式

4.2 关联关系

类型之间有相互引用关系,这里可以使用特定的关联语法来描述这种关系,并说明如何在mongodb里面生成相应的数据结构。

单关联字段 Singleton fields

字段引用其它类型的单个实例:

  • @belongsTo - 外键在这个类型中以${fieldName}Id形式保存
  • @hasOne - 外键保存在被引用类型里的 the foreign key is stored on the referenced type as ${typeName}Id. Provide the "as": X argument if the name is different. [NOTE: this is not yet fully implemented].

多关联字段 Paginated fields

字段引用其它类型的多个示例:

  • @belongsToMany - 在这个类里保存了一个外键列表${fieldName}Ids(默认形式)
  • @hasMany - 外键以${typeName}Id形式保存在被引用类型里面。如果名称不一样,则使用"as": X参数来表示,这个和1对多的@belongsTo相反。
  • @hasAndBelongsToMany - 在被引用类型里面,外键以${typeName}Ids形式表示. 如果名称不一样,则使用"as": X参数来表示,这个是多对多的@belongsToMany相反。
type User {
  username: String!
  bio: String

  tweets: [Tweet!] @hasMany(as: "author")
  liked: [Tweet!] @belongsToMany

  following: [User!] @belongsToMany
  followers: [User!] @hasAndBelongsToMany(as: "following")
}

type Tweet {
  author: User! @unmodifiable
  body: String!

  likers: [User!] @hasAndBelongsToMany(as: "liked")
}