Skip to content

vizeit/GraphQLServer-Graphene-AzureFunc

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

GraphQL Server - Graphene - Azure Function

Boilerplate Serverless implementation of GraphQL server in Python using Graphene

Features

  • Code-first approach
  • Implemented in Python
  • Serverless
  • Hosting on Azure Cloud
  • Modular
  • Support for ASGI
  • Lightweight
  • Test-driven Development

Quickstart

Prerequisites

Steps

  1. Clone the repo,
git clone https://github.com/vizeit/GraphQLServer-Graphene-AzureFunc.git
  1. Install graphene and starlette for graphene
pip install graphene starlette-graphene3
  1. Go to __init__.py

  2. Import Schema class from Graphene

from graphene import Schema
  1. Import GraphQLApp and make_graphiql_handler from starlette_graphene3
from starlette_graphene3 import GraphQLApp, make_graphiql_handler
  1. Import AsgiMiddleware class from azure.functions module
from azure.functions import AsgiMiddleware
  1. 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)
  1. Return AsgiMiddleware object from the main function
return AsgiMiddleware(app).handle(req, context)
  1. Define GraphQL types in Types.py

  2. Write GraphQL query resolvers in Queries.py

  3. Add the unit tests under tests folder. Run the unit tests after any changes,

python -m unittest -v tests/*.py