Employee Database
This repo is a GraphQL implementation of a single table (employees) using Flask and Graphene. The app has authentication (JWT) and exposes the web based graphiQL editor too. Qxf2 uses this app to practice writing tests, learning to make graphQL queries and as a starting point to understanding the relationship between schemas and the exposed queries.
Setup
-
Clone this repo
-
Setup a virtual environment (Python 3.7 or higher) and activate it
virtualenv -p python3.8 venv-employee-database
-
pip install -r requirements.txt
-
Setup some fake data with
sqlite3 data/employee_database.sqlite3
.mode csv
.import data/dummy_data.csv employee
select * from employee; #You should see a couple of rows
.quit
-
Update
employees/secret.py
with any secret string you want to use -
Add a new file called
employees/allowed_users.py
and the following lines:USERS = {'A_USERNAME_YOU_SELECT':'A_PASSWORD_YOU_SET', 'ANOTHER_USERNAME':'ANOTHER_PASSWORD'}
-
Start your server with
python run.py
Usage
- Visit
http://localhost:5000/graphql
in your browser - Try the following query:
mutation { auth(password: "A_PASSWORD_YOU_SET", username: "A_USERNAME_YOU_SELECT") { accessToken refreshToken } }
- If all goes well, step 2 will return an acessToken in the field - copy it
- Use a browser plugin to modify your header. Add a
Authorization
key and set it toBearer accessToken
whereaccessToken
is the token you copied in step 3. - Now try the 3 different queries allowed:
5a. Query all the employees
```
query findAllEmployees{
allEmployees{
edges{
node{
email
employeeId
dateJoined
isActive
blogAuthorName
}
}
}
}
```
5b. Query by employee email
```
query FindEmployeeByEmail($email: String = "lasker@qxf2.com") {
findEmployee(email: $email) {
githubId
blogAuthorName
phone
skypeId
}
}
```
5c. Query by employee Skype id
```
query FindEmployeeBySkype($skype_id: String = "emmanuel.lasker.qxf2") {
findEmployee(skypeId: $skype_id) {
email
blogAuthorName
phone
}
}
```
- If all goes well, you should be seeing data returned. The dummy database currently has two employees populated - WIlhelm Steinitz and Emmanuel Lasker.