Boilerplate Serverless implementation of GraphQL server in Python using Graphene
- Code-first approach
- Implemented in Python
- Serverless
- Hosting on Azure Cloud
- Modular
- Support for ASGI
- Lightweight
- Test-driven Development
- Active Azure cloud account
- Local development environment setup for Azure functions using Python
- Clone the repo,
git clone https://github.com/vizeit/GraphQLServer-Graphene-AzureFunc.git
- Install graphene and starlette for graphene
pip install graphene starlette-graphene3
-
Go to __init__.py
-
Import Schema class from Graphene
from graphene import Schema
- Import GraphQLApp and make_graphiql_handler from starlette_graphene3
from starlette_graphene3 import GraphQLApp, make_graphiql_handler
- Import AsgiMiddleware class from azure.functions module
from azure.functions import AsgiMiddleware
- Create app object from GraphQLApp class
app = GraphQLApp(schema, on_get=make_graphiql_handler())
If you prefer to turn off the GraphiQL playground, remove the second parameter to the GraphQLApp constructor
app = GraphQLApp(schema)
- Return AsgiMiddleware object from the main function
return AsgiMiddleware(app).handle(req, context)
-
Define GraphQL types in Types.py
-
Write GraphQL query resolvers in Queries.py
-
Add the unit tests under tests folder. Run the unit tests after any changes,
python -m unittest -v tests/*.py