GraphQL-Server-Demo
是一个帮助大家更好的学习和理解GraphQL的简单且易读的示例项目,通过nodejs创建服务
GraphQL-Server-Demo
├── README.md
├── LICENSE
├── .babelrc
├── .gitignore
├── package.json
├── yarn.lock
├── dev.sqlite
├── app.js
├── schemas
│ └── index.js
├── resolvers
│ ├── userResolver.js
│ ├── messageResolver.js
│ └── ...
└── types
├── query.js
├── mutation.js
├── queries
│ ├── userType.js
│ ├── messageType.js
│ └── ...
└── mutations
├── userInputType.js
├── messageInputType.js
└── ...
app.js
-- 项目服务引擎dev.sqlite
-- 测试数据库schemas
-- 用来创建GraphQLSchema
的基本schema文件, 包含最基本的queryType
和mutationType
types
-- 所有用户自定义的GraphQLObjectType
resolvers
-- 所有类型字段的解析器
输入以下命令:
git clone [email protected]:LanceGin/GraphQL-Server-Demo.git
cd GraphQL-Server-Demo
yarn && yarn start
打开url http://localhost:4000/graphql
,窗口中会显示 GraphiQL
GUI ,可以用来执行查询或者变更操作
query {
user(id: 1) {
name
nickname
message {
id
content
}
}
}
{
"data": {
"user": [
{
"name": "gin",
"nickname": "lancegin",
"message": [
{
"id": "1",
"content": "test message"
},
{
"id": "2",
"content": "hello"
},
{
"id": "3",
"content": "world"
}
]
}
]
}
}
mutation {
createMessage(input: {user_id: "1", content: "hello world111"}) {
id
content
}
}
{
"data": {
"createMessage": {
"id": "10",
"content": "hello world111"
}
}
}