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.
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 projectdev.sqlite
-- test databaseschemas
-- basic schema to create theGraphQLSchema
, contanins the basicqueryType
andmutationType
types
-- all theGraphQLObjectType
that user definedresolvers
-- all the resolvers to resolve the Type data
Excute the commands below:
git clone git@github.com: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 {
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"
}
}
}