introduce graphql
This commit is contained in:
+25
-4
@@ -1,10 +1,31 @@
|
||||
from fastapi import FastAPI
|
||||
from app.auth import router as auth_router
|
||||
from app.models import Base
|
||||
from app.db import engine
|
||||
from strawberry import Schema
|
||||
from strawberry.fastapi import GraphQLRouter
|
||||
|
||||
from app.auth import router as auth_router
|
||||
from app.db import engine
|
||||
from app.models import Base
|
||||
|
||||
# 导入 GraphQL 组件
|
||||
from app.graphql.queries import Query
|
||||
from app.graphql.mutations import Mutation
|
||||
from app.graphql.context import get_context
|
||||
|
||||
# 自动建表
|
||||
Base.metadata.create_all(bind=engine)
|
||||
|
||||
# 创建 FastAPI 实例
|
||||
app = FastAPI()
|
||||
|
||||
app.include_router(auth_router)
|
||||
# 组装 GraphQL Schema
|
||||
schema = Schema(query=Query, mutation=Mutation)
|
||||
|
||||
# 创建 GraphQL 路由并注入上下文
|
||||
graphql_router = GraphQLRouter(schema, context_getter=get_context)
|
||||
|
||||
# 挂载路由
|
||||
# 保留现有的 auth 路由供 Google OAuth 回调使用
|
||||
app.include_router(auth_router)
|
||||
|
||||
# 挂载 GraphQL 终点,前端以后只需要请求 /graphql
|
||||
app.include_router(graphql_router, prefix="/graphql")
|
||||
Reference in New Issue
Block a user