-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
46 lines (35 loc) · 1.13 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
from os import getenv
import strawberry
from fastapi import FastAPI
from strawberry.fastapi import GraphQLRouter
from strawberry.tools import create_type
# override PyObjectId and Context scalars
from models import PyObjectId
from mutations import mutations
from otypes import Context, PyObjectIdType
# import all queries and mutations
from queries import queries
# create query types
Query = create_type("Query", queries)
# create mutation types
Mutation = create_type("Mutation", mutations)
# override context getter
async def get_context() -> Context:
return Context()
# initialize federated schema
schema = strawberry.federation.Schema(
query=Query,
mutation=Mutation,
enable_federation_2=True,
scalar_overrides={PyObjectId: PyObjectIdType},
)
# check whether running in debug mode
DEBUG = getenv("GLOBAL_DEBUG", "False").lower() in ("true", "1", "t")
# serve API with FastAPI router
gql_app = GraphQLRouter(schema, graphiql=True, context_getter=get_context)
app = FastAPI(
debug=DEBUG,
title="CC Members Microservice",
desciption="Handles Data of Members",
)
app.include_router(gql_app, prefix="/graphql")