create config file

This commit is contained in:
Ruidy 2020-10-30 12:54:13 +01:00
parent 22e377df36
commit 50351e8b36
2 changed files with 29 additions and 19 deletions

27
app/config/app.py Normal file
View file

@ -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

View file

@ -1,25 +1,8 @@
import graphene
import uvicorn 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.config.app import create_app
from app.schema.queries.todo import TodoQuery
origins = ["*"] app = create_app()
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))
)
if __name__ == "__main__": if __name__ == "__main__":