Last active
March 28, 2020 20:22
-
-
Save philippegirard/a574c611f68ded2f8073d36bbcc6fc64 to your computer and use it in GitHub Desktop.
FastAPI : async GraphQL (Graphene)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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