from uuid import UUID from delivery_metadata.api.app import app from delivery_metadata.models import Model class GlobalParticipant(Model): id: UUID class LabelParticipant(Model): uuid: UUID name: str appleMusicId: str | None spotifyId: str | None spotifyArtistKey: str | None globalParticipant: GlobalParticipant | None class Participation(Model): participant: LabelParticipant class Role(Model): name: str class LabelSoundRecordingParticipation(Model): role: Role participant: LabelParticipant class LabelSoundRecording(Model): participations: list[LabelSoundRecordingParticipation] class _Track(Model): isrc: str tuid: str participations: list[Participation] labelSoundRecording: LabelSoundRecording class GraphQlProduct(Model): participations: list[Participation] tracks: list[_Track] _PRODUCT_QUERY = """ query getReleaseGraphQLData($productId: String!) { product(productId: $productId, cached: false) { participations: labelParticipations { participant: labelParticipant { ...labelParticipantFragment } } tracks { isrc tuid participations { participant { ...labelParticipantFragment } } labelSoundRecording { participations { role { name } participant { ...labelParticipantFragment } } } } } } fragment labelParticipantFragment on LabelParticipant { uuid name appleMusicId spotifyId spotifyArtistKey globalParticipant { id } } """ async def get_product(product_id: int) -> GraphQlProduct: result = await app.state.graphql_connector.make_request( query=_PRODUCT_QUERY, params={"productId": str(product_id)}, ) # filter out participants with empty names result["product"]["participations"] = [ x for x in result["product"]["participations"] if x["participant"]["name"] != "" ] for track in result["product"]["tracks"]: track["participations"] = [ x for x in track["participations"] if x["participant"]["name"] != "" ] return GraphQlProduct(**result["product"])