graphql_python_template/app/config/app.py
2020-11-07 22:42:57 +01:00

27 lines
635 B
Python

import graphene
from fastapi import FastAPI
from starlette.graphql import GraphQLApp
from starlette.middleware.cors import CORSMiddleware
from app.schema.mutations.mutation import Mutation
from app.schema.queries.queries import Query
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=Query, mutation=Mutation))
)
return app