syedfaisalsaleeem / FastApi-Strawberry-GraphQL-SqlAlchemy-BoilerPlate

Boiler plate project for using GraphQL (Strawberry) with FastAPI and Async SQL Alchemy 🍓
https://graphql-stickynotes.herokuapp.com/graphql
MIT License
139 stars 23 forks source link
async fastapi graphql-server postgresql python sqlalchemy strawberry-graphql

Fast Api Strawberry GraphQL Async SQL Alchemy Boiler Plate

Description

This code is a boiler plate for the implementation of GraphQL with Fast Api using Strawberry Library. For GraphQL server we have used Strawberry.

Features

To run the project in your local environment::

  1. Clone the repository::

    $ git clone https://github.com/syedfaisalsaleeem/FastApi-Strawberry-GraphQL-SqlAlchemy-BoilerPlate.git
    $ cd FastApi-Strawberry-GraphQL-SqlAlchemy-BoilerPlate
  2. Create and activate a virtual environment::

    $ virtualenv env -p python3
    $ source env/bin/activate
  3. Install requirements::

    $ pip install -r requirements.txt
  4. Run the application::

    $ python main_dev.py

    To run the project using Docker Container:

  5. Clone the repository::

    $ git clone https://github.com/syedfaisalsaleeem/FastApi-Strawberry-GraphQL-SqlAlchemy-BoilerPlate.git
    $ cd FastApi-Strawberry-GraphQL-SqlAlchemy-BoilerPlate
  6. Run this command on CMD::

    $ docker-compose up -d --build

    Usage Examples

Launch the fast api server at specified port default 5000 (open the UI at http://localhost:5000/graphql): ::

$ python main_dev.py

Launch using docker: ::

$ docker-compose up -d --build

Tests

Test are run with pytest. If you are not familiar with this package you can get some more info from their website <https://pytest.org/>_.

To run the tests, from the project directory, simply::

$ pip install -r requirements.txt
$ python test.py

You should see output similar to::

----------- coverage: platform win32, python 3.8.8-final-0 -----------
Name                                Stmts   Miss  Cover
-------------------------------------------------------
tests\conftest.py                      18      4    78%
tests\graphql\mutations.py              3      0   100%
tests\graphql\queries.py                2      0   100%
tests\graphql\test_stickynotes.py       0      0   100%
tests\graphql\test_user.py             43      0   100%
tests\load_test_env.py                  4      4     0%
-------------------------------------------------------
TOTAL                                  70      8    89%

=================== 8 passed in 0.59s =================

Migrations

To run the project in your local environment::

$ alembic revision --autogenerate -m "migration string"
$ alembic upgrade head

License

This project is licensed under the terms of the MIT license. If you have any question about this opinionated list, do not hesitate to contact me @SyedFaisal on Linkedin or open an issue on GitHub.