diff --git a/app/config/app.py b/app/config/app.py new file mode 100644 index 0000000..2c0d34d --- /dev/null +++ b/app/config/app.py @@ -0,0 +1,27 @@ +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 diff --git a/app/main.py b/app/main.py index d80c4eb..c72d243 100644 --- a/app/main.py +++ b/app/main.py @@ -1,25 +1,8 @@ -import graphene import uvicorn -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 +from app.config.app import create_app -origins = ["*"] - -app = FastAPI() -app.add_middleware( - CORSMiddleware, - allow_origins=origins, - allow_credentials=True, - allow_methods=["*"], - allow_headers=["*"], -) -app.add_route( - "/", GraphQLApp(schema=graphene.Schema(query=TodoQuery, mutation=Mutations)) -) +app = create_app() if __name__ == "__main__":