diff --git a/gso/__init__.py b/gso/__init__.py index ccbb2d0df7993b2fb35a88781f053de344ed2143..56c9c7d4615be7e6964c95025dab3fc078af40e9 100644 --- a/gso/__init__.py +++ b/gso/__init__.py @@ -17,6 +17,7 @@ import gso.workflows # noqa: F401 from gso.api import router as api_router from gso.auth.oidc import oidc_instance from gso.auth.opa import graphql_opa_instance, opa_instance +from gso.graphql_api.resolvers.customer import custom_subscription_interface from gso.graphql_api.types import GSO_SCALAR_OVERRIDES from gso.settings import load_oss_params @@ -35,7 +36,7 @@ def init_gso_app() -> OrchestratorCore: app.register_authentication(oidc_instance) app.register_authorization(opa_instance) app.register_graphql_authorization(graphql_opa_instance) - app.register_graphql() + app.register_graphql(subscription_interface=custom_subscription_interface) app.include_router(api_router, prefix="/api") if app_settings.EXECUTOR == ExecutorType.WORKER: diff --git a/gso/graphql_api/resolvers/__init__.py b/gso/graphql_api/resolvers/__init__.py new file mode 100644 index 0000000000000000000000000000000000000000..decfd8226c967a94bf2560b00cb3f62be8a00f10 --- /dev/null +++ b/gso/graphql_api/resolvers/__init__.py @@ -0,0 +1 @@ +"""resolvers module.""" diff --git a/gso/graphql_api/resolvers/customer.py b/gso/graphql_api/resolvers/customer.py new file mode 100644 index 0000000000000000000000000000000000000000..b8187a69ca00f4941ebaa104eab2a98880b74055 --- /dev/null +++ b/gso/graphql_api/resolvers/customer.py @@ -0,0 +1,30 @@ +"""This module contains the resolver for the customer field in the subscription and process types.""" + +import strawberry +from orchestrator.graphql.schemas.customer import CustomerType +from orchestrator.graphql.schemas.process import ProcessType +from orchestrator.graphql.schemas.subscription import SubscriptionInterface +from orchestrator.graphql.utils.override_class import override_class + +from gso.services.partners import get_partner_by_id + + +async def resolve_customer(root: CustomerType) -> CustomerType: + """Resolve the customer field for a subscription or process.""" + partner = get_partner_by_id(root.customer_id) + + return CustomerType( + customer_id=partner.partner_id, + fullname=partner.name, + shortcode=partner.email, + ) + + +customer_field = strawberry.field( + resolver=resolve_customer, + description="Returns customer of a subscription", +) +customer_field.name = "customer" # type: ignore[attr-defined] + +override_class(ProcessType, [customer_field]) # type: ignore[list-item] +custom_subscription_interface = override_class(SubscriptionInterface, [customer_field]) # type: ignore[list-item] diff --git a/requirements.txt b/requirements.txt index 97fd1fedbe08dc83073afba7953b608a5fd2a189..fb4a7c01dd12d683a9a88f6b77189930df83229d 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,11 +1,11 @@ orchestrator-core==2.8.0 -requests==2.31.0 +requests==2.32.0 infoblox-client~=0.6.0 pycountry==23.12.11 pynetbox==7.3.3 celery-redbeat==2.2.0 celery==5.3.6 -azure-identity==1.16.0 +azure-identity==1.16.1 msgraph-sdk==1.2.0 ping3==4.0.8 unidecode==1.3.8