graphql_python_template/app/config/app.py
2020-10-30 12:54:13 +01:00

27 lines
643 B
Python

import graphene
from fastapi import FastAPI
from starlette.graphql import GraphQLApp
from starlette.middleware.cors import CORSMiddleware
from app.schema.mutations.mutations import Mutations
from app.schema.queries.todo import TodoQuery
origins = ["*"]
methods = ["*"]
headers = ["*"]
def create_app() -> FastAPI:
app = FastAPI()
app.add_middleware(
CORSMiddleware,
allow_origins=origins,
allow_credentials=True,
allow_methods=methods,
allow_headers=headers,
)
app.add_route(
"/", GraphQLApp(schema=graphene.Schema(query=TodoQuery, mutation=Mutations))
)
return app