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 🙏

© 2024 – Pkg Stats / Ryan Hefner

mgs-graphql-node

v1.1.0

Published

The simple way to generates GraphQL schemas and Sequelize models from your models definition,microservice supported

Downloads

2

Readme

Simple-GraphQL

JavaScript Style Guide

Simple-GraphQL generates GraphQL schemas and Sequelize models from your models definition(support FlowType static type check). The generated GraphQL schema is compatible with Relay.

GraphQL is a query language for your API, and a server-side runtime for executing queries by using a type system you define for your data.

Sequelize is a promise-based ORM for Node.js. It supports the dialects PostgreSQL, MySQL, SQLite and MSSQL and features solid transaction support, relations, read replication and more.

FlowType is a static type checker for your JavaScript code. It does a lot of work to make you more productive. Making you code faster, smarter, more confidently, and to a bigger scale.

Document

Install

npm install graphql graphql-relay simple-graphql --save

Roadmap

Demo & Usage

// @flow
const Sequelize = require('sequelize')
const express = require('express')
const graphqlHTTP = require('express-graphql')
const SG from 'simple-graphql'

// 定义Schema
const TodoSchema = SG.schema('Todo').fields({
  title: {
    $type: String,
    required: true
  },
  description: String,
  completed: {
    $type: Boolean,
    required: true
  },
  dueAt: Date
}).queries({
  dueTodos: {
    description: 'Find all due todos',
    $type: ['Todo'],
    args: {
      dueBefore: {
        $type: Date,
        required: true
      }
    },
    resolve: async function ({ dueBefore}, context, info, {models:{Todo}}) {
      return Todo.find({
        where: {
          completed: false,
          dueAt: {
            $lt: dueBefore
          }
        }
      })
    }
  }
}).mutations({
  completedTodo: {
    description: 'Mark the todo task completed.',
    inputFields: {
      todoId: {
        $type: 'Todo',
        required: true
      }
    },
    outputFields: {
      changedTodo: 'Todo'
    },
    mutateAndGetPayload: async function ({todoId}, context, info, {models:{Todo}}) {
      const todo = await Todo.findOne({where: {id: todoId}})
      if (!todo) {
        throw new Error('Todo entity not found.')
      }
      if (!todo.completed) {
        todo.completed = true
        await todo.save()
      }
      return {changedTodo: todo}
    }
  }
})

// 定义Sequelize 链接
const sequelize = new Sequelize('test1', 'postgres', 'Password', {
  host: 'localhost',
  dialect: 'sqlite',
  pool: {
    max: 5,
    min: 0,
    idle: 10000
  },
  // SQLite only
  storage: ':memory:'
})

// 生成GraphQL的schema
const schema = SG.build({sequelize:sequelize, schemas:[TodoSchema]}).graphQLSchema

// 自动建立数据库表
sequelize.sync({
  force: false, // if true, it will drop all existing table and recreate all.
  logging: console.log
}).then(() => console.log('Init DB Done'), (err) => console.log('Init DB Fail', err))

// 启动http服务器
const app = express()

app.use('/graphql', graphqlHTTP({
  schema: schema,
  graphiql: true
}))
app.listen(4000)

License

MIT