project that allows you to understand the basics of graphql
The tools you need to let this project run are :
- docker
- docker-compose
- npm
git clone https://github.com/felixleo22/starter-express-graphql-mongo
Before you start the starter, make sure have download all dependencies with npm.
# Start ez-unpaywall as daemon
docker-compose up -d
# Stop ez-unpaywall
docker-compose stop
# Get the status of ez-unpaywall services
docker-compose ps
- 8080 : graphql
- 8081 : mongo-express
- 27017 : mongoDB
method: POST, url: "/graphql" Body:
{
"query": "{authors{id,name,age}}",
}
Status: 200 Response:
{
"data": {
"authors": [
{
"id": "5f86e6c0b8feb6001245ecbd",
"name": "Nicolas",
"age": 35
},
{
"id": "5f86e75bb8feb6001245ecbe",
"name": "Vincent",
"age": 32
}
]
}
}
method: POST, url: "/graphql" Body:
{
"query": "{author{id:\"5f86e6c0b8feb6001245ecbd\"}}",
}
Status: 200 Response:
{
"data": {
"author": {
"id": "5f86e6c0b8feb6001245ecbd",
"name": "Nicolas",
"age": 35,
"books": [
{
"id": "5f870c5b2775130267a7c603",
"name": "nice book",
"genre": "book"
},
{
"id": "5f870c88cd3fc40292e6ae21",
"name": "a other nice book",
"genre": "book"
}
]
}
}
}
method: POST, url: "/graphql" Body:
{
"query": "mutation {addAuthor(name: \"Yannick\", age: 28){id,name}}",
}
Status: 200 Response:
{
"data": {
"addAuthor": {
"id": "5f870e61d183a702bbe1063f",
"name": "Yannick"
}
}
}
method: POST, url: "/graphql" Body:
{
"query": "mutation {updateAuthor(_id: \"5f870e61d183a702bbe1063f\", name: \"Steven\", age: 24){id,name}}"
}
Status: 200 Response:
{
"data": {
"updateAuthor": {
"id": "5f870e61d183a702bbe1063f",
"name": "Steven"
}
}
}
method: POST, url: "/graphql" Body:
{
"query": "mutation {deleteAuthor(_id: \"5f870e61d183a702bbe1063f\"){id,name}}"
}
Status: 200 Response:
{
"data": {
"deleteAuthor": {
"id": "5f870e61d183a702bbe1063f",
"name": "Steven"
}
}
}
It's the same
I will put complete documentation of API with api-doc on a github.io. If i think about it