-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
37 lines (29 loc) · 884 Bytes
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
import strawberry
import uvicorn
from fastapi import FastAPI
from config import db
from Graphql.query import Query
from Graphql.mutation import Mutation
from strawberry.fastapi import GraphQLRouter
def init_app():
async def lifespan(app: FastAPI):
await db.create_all()
yield
await db.close()
apps = FastAPI(
title="Learning FastAPI with Strawberry GraphQL",
description="Fast API",
version="1.0.0",
lifespan=lifespan
)
@apps.get("/")
def home():
return "Welcome home!"
# add graphql endpoint
schema = strawberry.Schema(query=Query,mutation=Mutation)
graphql_app = GraphQLRouter(schema)
apps.include_router(graphql_app, prefix="/graphql")
return apps
app = init_app()
if __name__ == "__main__":
uvicorn.run("main:app",host="localhost",port=8888, reload=True)