diff --git a/swh/graphql/resolvers/base_node.py b/swh/graphql/resolvers/base_node.py index cc86f1d850ab601603369aaa0851ff70ccc60604..2d4a7c25b94d16b4839d6d29fe966e3082ad2b81 100644 --- a/swh/graphql/resolvers/base_node.py +++ b/swh/graphql/resolvers/base_node.py @@ -38,7 +38,9 @@ class BaseNode: """ if node_data is None: node_data = self._get_node_data() - return self._get_node_from_data(node_data) + if node_data is not None: + return self._get_node_from_data(node_data) + return None def _get_node_from_data(self, node_data: Any) -> Optional[Any]: """ diff --git a/swh/graphql/resolvers/directory.py b/swh/graphql/resolvers/directory.py index 48b381817fd87fc82dc62f20a54f73015c74733e..6581e73149a36f69155588eaf24829f0da62a605 100644 --- a/swh/graphql/resolvers/directory.py +++ b/swh/graphql/resolvers/directory.py @@ -5,7 +5,6 @@ from typing import TYPE_CHECKING, Optional, Union -from swh.graphql.errors import NullableObjectError from swh.model.model import Directory from .base_node import BaseSWHNode @@ -26,8 +25,9 @@ class DirectoryNode(BaseDirectoryNode): Node resolver for a directory requested directly with its SWHID """ - def _get_node_data(self): + def _get_node_data(self) -> Optional[Directory]: swhid = self.kwargs.get("swhid") + assert swhid is not None return self.archive.get_directory(directory_id=swhid.object_id, verify=True) @@ -42,14 +42,12 @@ class RevisionDirectoryNode(BaseDirectoryNode): _can_be_null = True obj: BaseRevisionNode - def _get_node_data(self) -> Directory: + def _get_node_data(self) -> Optional[Directory]: # self.obj.directory_hash is the requested directory Id directory_id = self.obj.directory_hash() if directory_id is None: - raise NullableObjectError() - directory = self.archive.get_directory(directory_id=directory_id, verify=False) - assert directory is not None - return directory + return None + return self.archive.get_directory(directory_id=directory_id, verify=False) class TargetDirectoryNode(BaseDirectoryNode): diff --git a/swh/graphql/resolvers/snapshot.py b/swh/graphql/resolvers/snapshot.py index c1b570c44e6e229f6d7bd8cb00f1cc098cd24447..dfb975909cf88778a5d992c0dd04e63d2be024f0 100644 --- a/swh/graphql/resolvers/snapshot.py +++ b/swh/graphql/resolvers/snapshot.py @@ -5,7 +5,6 @@ from typing import TYPE_CHECKING, Optional, Union -from swh.graphql.errors import NullableObjectError from swh.graphql.utils import utils from swh.model.model import CoreSWHID, Snapshot @@ -52,7 +51,7 @@ class VisitSnapshotNode(BaseSnapshotNode): def _get_node_data(self): snapshot_id = self.obj.snapshot_id() if snapshot_id is None: - raise NullableObjectError() + return None return self.archive.get_snapshot(snapshot_id=snapshot_id, verify=False) diff --git a/swh/graphql/resolvers/snapshot_branch.py b/swh/graphql/resolvers/snapshot_branch.py index 3b71704b4cb97a231c898ff93885693722561f8c..6dc3b1036b855b9d914611887463cf4ed45e96da 100644 --- a/swh/graphql/resolvers/snapshot_branch.py +++ b/swh/graphql/resolvers/snapshot_branch.py @@ -5,7 +5,6 @@ from typing import List, Optional, Tuple -from swh.graphql.errors import NullableObjectError from swh.model.model import CoreSWHID, SnapshotBranch from swh.storage.interface import PagedResult @@ -55,7 +54,7 @@ class SnapshotHeadBranchNode(BaseSnapshotBranchNode): _can_be_null = True - def _get_node_data(self) -> Tuple[bytes, Optional[SnapshotBranch]]: + def _get_node_data(self) -> Optional[Tuple[bytes, Optional[SnapshotBranch]]]: snapshot_id = self._get_snapshot_swhid().object_id name = b"HEAD" # Get just the branch without following the alias chain @@ -64,7 +63,7 @@ class SnapshotHeadBranchNode(BaseSnapshotBranchNode): snapshot_id=snapshot_id, branch_name=name, follow_chain=False ) if head_branch is None or head_branch.branch_found is False: - raise NullableObjectError() + return None return (name, head_branch.target) def _get_snapshot_swhid(self) -> CoreSWHID: