Skip to content

Commit 80635c4

Browse files
committed
Add tasks service example
0 parents  commit 80635c4

28 files changed

Lines changed: 1077 additions & 0 deletions

.gitignore

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
.DS_Store
2+
.tmp
3+
*.log
4+
*.zip
5+
*.rej
6+
.idea
7+
*.swp
8+
9+
node_modules
10+
.serverless
11+
.env*
12+
.aws-credentials.*
13+
.cloudfrontSignerPrivateKey.*
14+
!*.example

README.md

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
# Fastapi Graphql Postgres Example tasks service
2+
3+
## Required software
4+
5+
Follow `pyenv` setup instructions in https://github.com/pyenv/pyenv
6+
7+
Install Python `3.9.7`
8+
9+
Install `pipenv` for package management
10+
11+
python3.9 -m pip install --user pipenv --upgrade pip
12+
13+
Finally install required packages for service
14+
15+
pipenv install -d
16+
17+
18+
## Run service locally
19+
20+
You can use `Postgres.app` to run PostgreSQL locally. You can dump and import project database from test environment
21+
22+
Launch Postgres db and ensure there is data in tables
23+
24+
pipenv run uvicorn main:app --reload
25+
26+
Refer to api-doc.md regarding available endpoints
27+
28+
curl -X POST http://0.0.0.0:8000/...
29+
30+
## Development
31+
32+
Add new Python packages with
33+
34+
pipenv install xxx
35+
36+
Add development-only package, for example for testing, with
37+
38+
pipenv install xxx --dev
39+
40+
After experimenting (with new packages) run `pipenv clean` to remove unused packages
41+
42+
### Lint code
43+
44+
- pipenv run mypy -config-file=mypy.ini .
45+
- pipenv run flake8 --append-config=.flake8 .
46+
47+
## Testing
48+
49+
Use Graphql Playground or CURL

app/.env.example

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# necessary for deploy
2+
STAGE=example
3+
4+
# necessary for service
5+
DB_STR='postgresql://xxx'

app/.flake8

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
[flake8]
2+
max-line-length = 120
3+
exclude = migrations
4+
per-file-ignores =
5+
__init__.py: F401,F403,X100

app/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
*.pyc

app/.python-version

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
3.9.7

app/Pipfile

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
[[source]]
2+
url = "https://pypi.org/simple"
3+
verify_ssl = true
4+
name = "pypi"
5+
6+
[packages]
7+
mangum = "*"
8+
python-dotenv = "*"
9+
pip = "*"
10+
fastapi = "==0.68.2"
11+
ariadne = "*"
12+
sqlalchemy = "*"
13+
psycopg2-binary = "*"
14+
stripe = "*"
15+
boto3 = "*"
16+
pydash = "*"
17+
18+
[dev-packages]
19+
uvicorn = "*"
20+
pylint = "*"
21+
pep8 = "*"
22+
mypy = "*"
23+
flake8 = "*"
24+
25+
[requires]
26+
python_version = "3.9"

app/Pipfile.lock

Lines changed: 552 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

app/__init__.py

Whitespace-only changes.

app/api-doc.md

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
# Fastapi Graphql Postgres Example tasks service documentation
2+
3+
## auth_create_task
4+
5+
mutation {
6+
auth_create_task(
7+
params: {
8+
description: "test"
9+
}
10+
) {
11+
... Task fields
12+
}
13+
}
14+
15+
curl -v 'https://xxx/auth' \
16+
-H 'content-type: application/json' \
17+
-H 'authorization: Bearer xxx' \
18+
--data-raw '{"operationName":null,"variables":{},"query":"mutation {\n auth_create_task(params: {data: {}}) {\n created_at\n description\n id\n updated_at\n }\n}\n"}'
19+
20+
## create_task
21+
22+
mutation {
23+
create_task(
24+
params: {
25+
description: "test"
26+
}
27+
) {
28+
... Task fields
29+
}
30+
}
31+
32+
curl 'https://xxx/public' -X POST --data-raw '{"operationName":null,"variables":{},"query":"mutation {\n create_task(params: { description: \"test\" }) {\n description\n id\n }\n}\n"}'
33+
34+
## get_task
35+
36+
query {
37+
get_task(
38+
id: 123
39+
) {
40+
... Task fields
41+
}
42+
}
43+
44+
curl 'https://xxx/public' -X POST --data-raw '{"operationName":null,"variables":{},"query":"{\n get_task(id: 123) {\n description\n id\n }\n}\n"}'

0 commit comments

Comments
 (0)