Security News
Supply Chain Attack Detected in Solana's web3.js Library
A supply chain attack has been detected in versions 1.95.6 and 1.95.7 of the popular @solana/web3.js library.
mgs-graphql
Advanced tools
The simple way to generates GraphQL schemas and Sequelize models from your models definition,microservice supported
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
andMSSQL
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.
npm install graphql graphql-relay simple-graphql --save
// @flow
import Sequelize from 'sequelize'
import express from 'express'
import graphqlHTTP from 'express-graphql'
import 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)
FAQs
The simple way to generates GraphQL schemas and Sequelize models from your models definition,microservice supported
The npm package mgs-graphql receives a total of 9 weekly downloads. As such, mgs-graphql popularity was classified as not popular.
We found that mgs-graphql demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 5 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
A supply chain attack has been detected in versions 1.95.6 and 1.95.7 of the popular @solana/web3.js library.
Research
Security News
A malicious npm package targets Solana developers, rerouting funds in 2% of transactions to a hardcoded address.
Security News
Research
Socket researchers have discovered malicious npm packages targeting crypto developers, stealing credentials and wallet data using spyware delivered through typosquats of popular cryptographic libraries.