Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/LanceGin/GraphQL-Server-Demo
GraphQL server demo with nodejs
https://github.com/LanceGin/GraphQL-Server-Demo
demo graphql graphql-demo graphql-server
Last synced: 15 days ago
JSON representation
GraphQL server demo with nodejs
- Host: GitHub
- URL: https://github.com/LanceGin/GraphQL-Server-Demo
- Owner: LanceGin
- License: mit
- Created: 2018-07-17T11:47:46.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2018-07-24T12:34:36.000Z (over 6 years ago)
- Last Synced: 2024-08-01T02:28:39.871Z (3 months ago)
- Topics: demo, graphql, graphql-demo, graphql-server
- Language: JavaScript
- Homepage:
- Size: 67.4 KB
- Stars: 18
- Watchers: 4
- Forks: 3
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# GraphQL-Server-Demo
[中文文档](https://github.com/LanceGin/GraphQL-Server-Demo/blob/master/README_zh.md)
> `GraphQL-Server-Demo` is a typical example of starting a GraphQL Server with node.js. It is an easy and readable project to learn and understand [GraphQL](https://graphql.org/).
## Screenshots
### Query
![](http://orhcxc3kd.bkt.clouddn.com/query.png)
### Mutation
![](http://orhcxc3kd.bkt.clouddn.com/mutation.png)
## Structure
```
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` -- server engine of this project
* `dev.sqlite` -- test database
* `schemas` -- basic schema to create the `GraphQLSchema`, contanins the basic `queryType` and `mutationType`
* `types` -- all the `GraphQLObjectType` that user defined
* `resolvers` -- all the resolvers to resolve the Type data## Quick Start
Excute the commands below:
```shell
git clone [email protected]:LanceGin/GraphQL-Server-Demo.git
cd GraphQL-Server-Demo
yarn && yarn start
```Open the url `http://localhost:4000/graphql`, you will see the `GraphiQL` GUI in the window, and you can excute the example query and mution operations.
## Query Operation
### Request
```graphql
query {
user(id: 1) {
name
nickname
message {
id
content
}
}
}
```### Response
```json
{
"data": {
"user": [
{
"name": "gin",
"nickname": "lancegin",
"message": [
{
"id": "1",
"content": "test message"
},
{
"id": "2",
"content": "hello"
},
{
"id": "3",
"content": "world"
}
]
}
]
}
}
```## Mutation Operation
### Request
```graphql
mutation {
createMessage(input: {user_id: "1", content: "hello world111"}) {
id
content
}
}
```### Response
```json
{
"data": {
"createMessage": {
"id": "10",
"content": "hello world111"
}
}
}
```