Skip to content

Instantly share code, notes, and snippets.

@philippegirard
Last active March 28, 2020 20:22
Show Gist options
  • Save philippegirard/a574c611f68ded2f8073d36bbcc6fc64 to your computer and use it in GitHub Desktop.
Save philippegirard/a574c611f68ded2f8073d36bbcc6fc64 to your computer and use it in GitHub Desktop.
FastAPI : async GraphQL (Graphene)
import graphene
from fastapi import FastAPI
from starlette.graphql import GraphQLApp
from graphql.execution.executors.asyncio import AsyncioExecutor
class Query(graphene.ObjectType):
hello = graphene.String(
name=graphene.String(default_value="stranger")
)
async def resolve_hello(self, info, name):
# We can make asynchronous network calls here.
return "Hello " + name
app = FastAPI()
app.add_route(
"/graphql",
GraphQLApp(
schema=graphene.Schema(query=Query),
executor_class=AsyncioExecutor
)
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment