GraphQL API built with Flask, MySQL, SQLAlchemy, Graphene and Python 3.7
This app works with 3 basic entities (user, profile, skill) that are exposed via a GraphQL API.
- Python 3.7
- Pip 3
- Virtualenv
- Docker
- Docker Compose
After cloning the project create a virtual environment and activate it:
$ virtualenv venv
$ source venv/bin/activate
Install dependencies from requirements.txt:
(venv) $ pip3 install -r requirements.txt
This application is deployed in its own Docker image and the example DB is in a MySQL image. In order to run them both, there's a Docker Compose yml file ready to go:
$ docker-compose build
$ docker-compose run
To test the application, access http://localhost:5000/graphql
This application implements both data mutation and queries. For example, the following mutation creates a user:
mutation {
mutateUser(username: "mrbrown", name: "Quentin", lastName: "Tarantino") {
user {
username
name
lastName
}
}
}
Then with another mutation a profile with skills can be created for the previous user:
mutation {
mutateProfile(description: "Javascript developer since forever", role: "JS Developer", userId: 1, skills: [{
name: "JavaScript",
score: 5
}, {
name: "TypeScript",
score: 2
}]) {
profile {
description
role
skills {
name
score
}
}
}
}
This is an example query filtering by username and score, projecting only the user's name, profile's role and all information about skills:
{
users(username: "mrbrown") {
name
profile {
role
skills(score: 2) {
name
score
}
}
}
}