Source code for metaspace.projects_client

from typing import Optional, List
from metaspace.sm_annotation_utils import GraphQLClient

try:
    from typing import TypedDict  # Requires Python 3.8
except ImportError:
    TypedDict = dict





[docs]class ProjectDict(TypedDict): id: str name: str isPublic: bool urlSlug: Optional[str] currentUserRole: Optional[str] numDatasets: int publicationStatus: str externalLinks: List[ExternalLink]
[docs]class ProjectsClient: PROJECT_FIELDS = ( "id name isPublic urlSlug currentUserRole numDatasets publicationStatus" " externalLinks { provider link }" ) def __init__(self, gql: GraphQLClient): self._gql = gql
[docs] def get_project(self, project_id: str): result = self._gql.query( """query get_all_projects($projectId: ID!) { project(projectId: $projectId) { """ + self.PROJECT_FIELDS + """ } }""", {"projectId": project_id}, ) return result['project']
[docs] def get_all_projects(self, query: Optional[str] = None): result = self._gql.query( """query get_all_projects($query: String) { allProjects(query: $query, offset: 0, limit: 10000) { """ + self.PROJECT_FIELDS + """ } }""", {"query": query}, ) return result['allProjects']
[docs] def get_my_projects(self): assert self._gql.logged_in, 'Not logged in' result = self._gql.query( """query get_my_projects { currentUser { projects { project { """ + self.PROJECT_FIELDS + """ } } } }""" ) return [p['project'] for p in result.get('currentUser', {}).get('projects', [])]
# Specify __all__ so that Sphinx documents everything in order from most to least interesting __all__ = [ 'ProjectsClient', 'ProjectDict', 'ExternalLink', ]