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

add custom customer type and resolver to the graphql

parent 6689df7d
Branches
Tags
No related merge requests found
Pipeline #90996 failed
...@@ -17,6 +17,7 @@ import gso.workflows # noqa: F401 ...@@ -17,6 +17,7 @@ import gso.workflows # noqa: F401
from gso.api import router as api_router from gso.api import router as api_router
from gso.auth.oidc import oidc_instance from gso.auth.oidc import oidc_instance
from gso.auth.opa import graphql_opa_instance, opa_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.graphql_api.types import GSO_SCALAR_OVERRIDES
from gso.settings import load_oss_params from gso.settings import load_oss_params
...@@ -35,7 +36,7 @@ def init_gso_app() -> OrchestratorCore: ...@@ -35,7 +36,7 @@ def init_gso_app() -> OrchestratorCore:
app.register_authentication(oidc_instance) app.register_authentication(oidc_instance)
app.register_authorization(opa_instance) app.register_authorization(opa_instance)
app.register_graphql_authorization(graphql_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") app.include_router(api_router, prefix="/api")
if app_settings.EXECUTOR == ExecutorType.WORKER: 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"
override_class(ProcessType, [customer_field])
custom_subscription_interface = override_class(SubscriptionInterface, [customer_field])
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment