simple-graphql
Advanced tools
Comparing version 1.0.23 to 1.0.24
{ | ||
"name": "simple-graphql", | ||
"version": "1.0.23", | ||
"version": "1.0.24", | ||
"description": "The simple way to generates GraphQL schemas and Sequelize models from your models definition.", | ||
@@ -40,2 +40,3 @@ "main": "lib/index.js", | ||
"moment": "^2.18.1", | ||
"mysql2": "^1.4.2", | ||
"sequelize": "^4.8.2" | ||
@@ -42,0 +43,0 @@ }, |
@@ -54,5 +54,5 @@ 'use strict'; | ||
case JSON: | ||
return _sequelize2.default.JSONB; | ||
return _sequelize2.default.JSON; | ||
} | ||
return null; | ||
return _sequelize2.default.JSON; | ||
}; | ||
@@ -59,0 +59,0 @@ _lodash2.default.forOwn(schema.config.fields, function (value, key) { |
@@ -68,5 +68,5 @@ 'use strict'; | ||
graphQLOutputType: _graphql3.default.Json, | ||
columnType: _sequelize2.default.JSONB | ||
columnType: _sequelize2.default.JSON | ||
}) | ||
} | ||
}; |
{ | ||
"name": "simple-graphql", | ||
"version": "1.0.23", | ||
"version": "1.0.24", | ||
"description": "The simple way to generates GraphQL schemas and Sequelize models from your models definition.", | ||
@@ -40,2 +40,3 @@ "main": "lib/index.js", | ||
"moment": "^2.18.1", | ||
"mysql2": "^1.4.2", | ||
"sequelize": "^4.8.2" | ||
@@ -42,0 +43,0 @@ }, |
@@ -15,3 +15,2 @@ # Simple-GraphQL | ||
- [API](https://github.com/logerzhu/simple-graphql/wiki/API) | ||
- [Transaction](https://github.com/logerzhu/simple-graphql/wiki/Transaction) | ||
@@ -25,11 +24,2 @@ | ||
## Demo | ||
Check out the project code (<https://github.com/logerzhu/simple-graphql>). | ||
```shell | ||
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 | ||
``` | ||
## Roadmap | ||
@@ -40,15 +30,12 @@ - [ ] Query cache with [dataloader](https://github.com/facebook/dataloader) | ||
## Usage | ||
### Define the model | ||
Todo.js | ||
```javascript | ||
## Demo & Usage | ||
``` | ||
// @flow | ||
import Sequelize from 'sequelize' | ||
import express from 'express' | ||
import graphqlHTTP from 'express-graphql' | ||
import SG from 'simple-graphql' | ||
const TodoType = SG.modelRef('Todo') // Reference to Todo model type | ||
export default SG.model('Todo').fields({ | ||
// 定义Schema | ||
const TodoSchema = SG.schema('Todo').fields({ | ||
title: { | ||
@@ -66,4 +53,4 @@ $type: String, | ||
dueTodos: { | ||
description: "Find all due todos", | ||
$type: [TodoType], | ||
description: 'Find all due todos', | ||
$type: ['Todo'], | ||
args: { | ||
@@ -87,7 +74,7 @@ dueBefore: { | ||
}).mutations({ | ||
cpmpletedTodo: { | ||
description: "Mark the todo task completed.", | ||
completedTodo: { | ||
description: 'Mark the todo task completed.', | ||
inputFields: { | ||
todoId: { | ||
$type: TodoType, | ||
$type: 'Todo', | ||
required: true | ||
@@ -97,3 +84,3 @@ } | ||
outputFields: { | ||
changedTodo: TodoType | ||
changedTodo: 'Todo' | ||
}, | ||
@@ -103,3 +90,3 @@ mutateAndGetPayload: async function ({todoId}, context, info, {Todo}) { | ||
if (!todo) { | ||
throw new Error("Todo entity not found.") | ||
throw new Error('Todo entity not found.') | ||
} | ||
@@ -114,20 +101,7 @@ if (!todo.completed) { | ||
}) | ||
``` | ||
### Generate the GraphQL Schema and start the server | ||
```javascript | ||
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. | ||
// 定义Sequelize 链接 | ||
const sequelize = new Sequelize('test1', 'postgres', 'Password', { | ||
host: 'localhost', | ||
port: 5432, | ||
dialect: 'postgres', | ||
dialect: 'sqlite', | ||
pool: { | ||
@@ -137,10 +111,11 @@ max: 5, | ||
idle: 10000 | ||
} | ||
}, | ||
// SQLite only | ||
storage: ':memory:' | ||
}) | ||
// 生成GraphQL的schema | ||
const schema = SG.build(sequelize, [TodoSchema], {}) | ||
// 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({ | ||
@@ -151,9 +126,8 @@ force: false, // if true, it will drop all existing table and recreate all. | ||
// Start the GraphQL server | ||
// 启动http服务器 | ||
const app = express() | ||
app.use('/graphql', graphqlHTTP({ | ||
schema: schema, | ||
graphiql: true | ||
schema: schema, | ||
graphiql: true | ||
})) | ||
@@ -160,0 +134,0 @@ app.listen(4000) |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
307075
86
5380
5
131
+ Addedmysql2@^1.4.2
+ Addeddenque@1.5.1(transitive)
+ Addedgenerate-function@2.3.1(transitive)
+ Addediconv-lite@0.5.2(transitive)
+ Addedis-property@1.0.2(transitive)
+ Addedlong@4.0.0(transitive)
+ Addedlru-cache@5.1.17.18.3(transitive)
+ Addedmysql2@1.7.0(transitive)
+ Addednamed-placeholders@1.1.3(transitive)
+ Addedsafer-buffer@2.1.2(transitive)
+ Addedseq-queue@0.0.5(transitive)
+ Addedsqlstring@2.3.3(transitive)
+ Addedyallist@3.1.1(transitive)