Skip to content
Snippets Groups Projects
Commit 94577e40 authored by Mohammad Torkashvand's avatar Mohammad Torkashvand
Browse files

add custom customer type and resolver to the graphql

parent aab39165
No related branches found
No related tags found
1 merge request!332Feature/add customer graphql type
Pipeline #91008 passed
......@@ -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:
......
"""resolvers module."""
"""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]
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment