Changeset View
Changeset View
Standalone View
Standalone View
swh/graphql/resolvers/person.py
# Copyright (C) 2022 The Software Heritage developers | # Copyright (C) 2022 The Software Heritage developers | ||||
# See the AUTHORS file at the top-level directory of this distribution | # See the AUTHORS file at the top-level directory of this distribution | ||||
# License: GNU General Public License version 3, or any later version | # License: GNU General Public License version 3, or any later version | ||||
# See top-level LICENSE file for more information | # See top-level LICENSE file for more information | ||||
from typing import List | from typing import List, Optional | ||||
from swh.model.model import Person as StoragePerson | |||||
from .base_connection import BaseList | from .base_connection import BaseList | ||||
from .base_node import BaseNode | from .base_node import BaseNode | ||||
from .release import BaseReleaseNode | from .release import BaseReleaseNode | ||||
from .revision import BaseRevisionNode | from .revision import BaseRevisionNode | ||||
class Person(BaseNode): | class Person(BaseNode): | ||||
pass | pass | ||||
def get_person_list(person) -> List[Person]: | def get_person_list(person: Optional[StoragePerson]) -> List[StoragePerson]: | ||||
return [person] if person else [] | return [person] if person else [] | ||||
class RevisionAuthorList(BaseList): | class RevisionAuthorList(BaseList): | ||||
""" | """ | ||||
List of revision authors | List of revision authors | ||||
""" | """ | ||||
obj: BaseRevisionNode | obj: BaseRevisionNode | ||||
_node_class = Person | _node_class = Person | ||||
def _get_results(self) -> List[Person]: | def _get_results(self) -> List[StoragePerson]: | ||||
""" | """ | ||||
Author is a single object in the current data model, | Author is a single object in the current data model, | ||||
return it as a list to support future evolutions | return it as a list to support future evolutions | ||||
No backend fetching required as the data exists in | No backend fetching required as the data exists in | ||||
the parent object (revision) | the parent object (revision) | ||||
""" | """ | ||||
return get_person_list(self.obj.author) | return get_person_list(self.obj.author) | ||||
class RevisionCommitterList(BaseList): | class RevisionCommitterList(BaseList): | ||||
obj: BaseRevisionNode | obj: BaseRevisionNode | ||||
_node_class = Person | _node_class = Person | ||||
def _get_results(self) -> List[Person]: | def _get_results(self) -> List[StoragePerson]: | ||||
""" | """ | ||||
Committer is a single object in the current data model, | Committer is a single object in the current data model, | ||||
return it as a list to support future evolutions | return it as a list to support future evolutions | ||||
No backend fetching required as the data exists in | No backend fetching required as the data exists in | ||||
the parent object (revision) | the parent object (revision) | ||||
""" | """ | ||||
return get_person_list(self.obj.committer) | return get_person_list(self.obj.committer) | ||||
class ReleaseAuthorList(BaseList): | class ReleaseAuthorList(BaseList): | ||||
obj: BaseReleaseNode | obj: BaseReleaseNode | ||||
_node_class = Person | _node_class = Person | ||||
def _get_results(self) -> List[Person]: | def _get_results(self) -> List[StoragePerson]: | ||||
""" | """ | ||||
Author is a single object in the current data model, | Author is a single object in the current data model, | ||||
return it as a list to support future evolutions | return it as a list to support future evolutions | ||||
No backend fetching required as the data exists in | No backend fetching required as the data exists in | ||||
the parent object (release) | the parent object (release) | ||||
""" | """ | ||||
return get_person_list(self.obj.author) | return get_person_list(self.obj.author) |