Security News
Introducing the Socket Python SDK
The initial version of the Socket Python SDK is now on PyPI, enabling developers to more easily interact with the Socket REST API in Python projects.
simple-graphql
Advanced tools
The simple way to generates GraphQL schemas and Sequelize models from your models definition.
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
Check out the project code (https://github.com/logerzhu/simple-graphql).
cd simple-graphql
npm install # install dependencies in the main folder
npm run start # run the demo and open your browser: http://localhost:9413/graphql
Todo.js
// @flow
import SG from 'simple-graphql'
const TodoType = SG.modelRef('Todo') // Reference to Todo model type
export default SG.model('Todo').fields({
title: {
$type: String,
required: true
},
description: String,
completed: {
$type: Boolean,
required: true
},
dueAt: Date
}).queries({
dueTodos: {
description: "Find all due todos",
$type: [TodoType],
args: {
dueBefore: {
$type: Date,
required: true
}
},
resolve: async function ({ dueBefore}, context, info, {Todo}) {
return Todo.find({
where: {
completed: false,
dueAt: {
$lt: dueBefore
}
}
})
}
}
}).mutations({
cpmpletedTodo: {
description: "Mark the todo task completed.",
inputFields: {
todoId: {
$type: TodoType,
required: true
}
},
outputFields: {
changedTodo: TodoType
},
mutateAndGetPayload: async function ({todoId}, context, info, {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}
}
}
})
import Sequelize from 'sequelize'
import SG from 'simple-graphql'
import express from 'express'
import graphqlHTTP from 'express-graphql'
import Todo from './Todo'
// Config the Sequelize database connection.
const sequelize = new Sequelize('test1', 'postgres', 'Password', {
host: 'localhost',
port: 5432,
dialect: 'postgres',
pool: {
max: 5,
min: 0,
idle: 10000
}
})
// Generate the GraphQL Schema
const schema = GS.build(sequelize, [Todo], {})
// After GS.bulid completed, all sequelize models have defined, and call sequelize.sync will automatic create the schema in database.
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))
// Start the GraphQL server
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.
The npm package simple-graphql receives a total of 0 weekly downloads. As such, simple-graphql popularity was classified as not popular.
We found that simple-graphql demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer 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
The initial version of the Socket Python SDK is now on PyPI, enabling developers to more easily interact with the Socket REST API in Python projects.
Security News
Floating dependency ranges in npm can introduce instability and security risks into your project by allowing unverified or incompatible versions to be installed automatically, leading to unpredictable behavior and potential conflicts.
Security News
A new Rust RFC proposes "Trusted Publishing" for Crates.io, introducing short-lived access tokens via OIDC to improve security and reduce risks associated with long-lived API tokens.