mirror of
https://github.com/rjNemo/graphql_python_template
synced 2026-06-06 02:26:47 +00:00
create config file
This commit is contained in:
parent
22e377df36
commit
50351e8b36
2 changed files with 29 additions and 19 deletions
27
app/config/app.py
Normal file
27
app/config/app.py
Normal 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
|
||||
21
app/main.py
21
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__":
|
||||
|
|
|
|||
Loading…
Reference in a new issue