-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
61 lines (47 loc) · 1.7 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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
"""
Main module for the Clubs Microservice.
This module sets up the FastAPI application and integrates the Strawberry
GraphQL schema.
It includes the configuration for queries, mutations, and context.
Attributes:
GLOBAL_DEBUG (str): Environment variable that Enables or Disables debug
mode. Defaults to "False".
DEBUG (bool): Indicates whether the application is running in debug mode.
gql_app (GraphQLRouter): The GraphQL router for handling GraphQL requests.
app (FastAPI): The FastAPI application instance.
"""
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)
# Returns The custom context by overriding the 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 Clubs Microservice",
desciption="Handles Data of Clubs",
)
app.include_router(gql_app, prefix="/graphql")