Changeset View
Changeset View
Standalone View
Standalone View
swh/graphql/resolvers/content.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 Union | from typing import Union | ||||
from swh.graphql.backends import archive | |||||
from .base_node import BaseSWHNode | from .base_node import BaseSWHNode | ||||
from .directory_entry import DirectoryEntryNode | from .directory_entry import DirectoryEntryNode | ||||
from .release import BaseReleaseNode | from .release import BaseReleaseNode | ||||
from .snapshot_branch import BaseSnapshotBranchNode | from .snapshot_branch import BaseSnapshotBranchNode | ||||
class BaseContentNode(BaseSWHNode): | class BaseContentNode(BaseSWHNode): | ||||
""" | """ | ||||
Base resolver for all the content nodes | Base resolver for all the content nodes | ||||
""" | """ | ||||
def _get_content_by_hash(self, checksums: dict): | def _get_content_by_hash(self, checksums: dict): | ||||
content = archive.Archive().get_contents(checksums) | content = self.archive.get_contents(checksums) | ||||
# in case of a conflict, return the first element | # in case of a conflict, return the first element | ||||
return content[0] if content else None | return content[0] if content else None | ||||
@property | @property | ||||
def checksum(self): | def checksum(self): | ||||
# FIXME, use a Node instead | # FIXME, use a Node instead | ||||
return {k: v.hex() for (k, v) in self._node.hashes().items()} | return {k: v.hex() for (k, v) in self._node.hashes().items()} | ||||
▲ Show 20 Lines • Show All 65 Lines • Show Last 20 Lines |