diff --git a/swh/graphql/resolvers/content.py b/swh/graphql/resolvers/content.py index aa3f28e..0aa1faa 100644 --- a/swh/graphql/resolvers/content.py +++ b/swh/graphql/resolvers/content.py @@ -1,52 +1,52 @@ from swh.graphql.backends import archive from .base_node import BaseNode class BaseContentNode(BaseNode): """ """ def _get_content_by_id(self, content_id): content = archive.Archive().get_content(content_id) return content[0] if content else None @property def id(self): return self._node.unique_key() @property def swhId(self): # To support the schema naming convention return self._node.swhid() @property def checksum(self): # FIXME, return a Node object return self._node.hashes() @property def data(self): return def is_type_of(self): return "Content" class ContentNode(BaseContentNode): def _get_node_data(self): """ When a content is requested directly with an id """ - return self._get_content_by_id(self.kwargs.get("SWHID")) + return self._get_content_by_id(self.kwargs.get("SWHID").object_id) class TargetContentNode(BaseContentNode): def _get_node_data(self): """ When a content is requested from a directory entry or from a release target content id is obj.target here """ content_id = self.obj.target return self._get_content_by_id(content_id) diff --git a/swh/graphql/resolvers/directory.py b/swh/graphql/resolvers/directory.py index 9e6757e..1e00257 100644 --- a/swh/graphql/resolvers/directory.py +++ b/swh/graphql/resolvers/directory.py @@ -1,48 +1,48 @@ from .base_node import BaseNode class BaseDirectoryNode(BaseNode): def _get_directory_by_id(self, directory_id): # Now not fetching any data (schema is exposing just id) # same pattern is used in snapshot resolver # FIXME, use the right API to fetch metadata like name, path return { "id": directory_id, } def is_type_of(self): return "Directory" class DirectoryNode(BaseDirectoryNode): def _get_node_data(self): """ When a directory is requested directly with an id """ # FXIME, query to make sure directory exists - directory_id = self.kwargs.get("SWHID") + directory_id = self.kwargs.get("SWHID").object_id # path = "" return self._get_directory_by_id(directory_id) class RevisionDirectoryNode(BaseDirectoryNode): def _get_node_data(self): """ When a directory is requested from a revision self.obj is revision here self.obj.directoryId is the required dir id (set from resolvers.revision.py:BaseRevisionNode) """ directory_id = self.obj.directoryId return self._get_directory_by_id(directory_id) class TargetDirectoryNode(BaseDirectoryNode): def _get_node_data(self): """ When a directory is requested as a target self.obj can be a Release or a DirectoryEntry obj.target is the requested directory id here """ return self._get_directory_by_id(self.obj.target) diff --git a/swh/graphql/resolvers/release.py b/swh/graphql/resolvers/release.py index 887acd4..5ef3ce7 100644 --- a/swh/graphql/resolvers/release.py +++ b/swh/graphql/resolvers/release.py @@ -1,45 +1,45 @@ from swh.graphql.backends import archive from .base_node import BaseNode class BaseReleaseNode(BaseNode): def _get_release_by_id(self, release_id): return (archive.Archive().get_releases([release_id]) or None)[0] @property def targetId(self): # To support the schema naming convention return self._node.target @property def targetType(self): # To support the schema naming convention return self._node.target_type.value def is_type_of(self): """ is_type_of is required only when resolving a UNION type This is for ariadne to return the right type """ return "Release" class ReleaseNode(BaseReleaseNode): """ When the release is requested directly with an id """ def _get_node_data(self): - return self._get_release_by_id(self.kwargs.get("SWHID")) + return self._get_release_by_id(self.kwargs.get("SWHID").object_id) class TargetReleaseNode(BaseReleaseNode): """ When a release is requested as a target self.obj could be a snapshotbranch or a release self.obj.target is the requested release id here """ def _get_node_data(self): return self._get_release_by_id(self.obj.target) diff --git a/swh/graphql/resolvers/revision.py b/swh/graphql/resolvers/revision.py index affbac6..7d85ab6 100644 --- a/swh/graphql/resolvers/revision.py +++ b/swh/graphql/resolvers/revision.py @@ -1,92 +1,92 @@ from swh.graphql.backends import archive from swh.graphql.utils import utils from .base_connection import BaseConnection from .base_node import BaseNode class BaseRevisionNode(BaseNode): def _get_revision_by_id(self, revision_id): return (archive.Archive().get_revisions([revision_id]) or None)[0] @property def parentIds(self): # To support the schema naming convention return self._node.parents @property def directoryId(self): # To support the schema naming convention """ """ return self._node.directory @property def type(self): return self._node.type.value def is_type_of(self): """ is_type_of is required only when resolving a UNION type This is for ariadne to return the right type """ return "Revision" class RevisionNode(BaseRevisionNode): """ When the revision is requested directly with its id (hash) """ def _get_node_data(self): - return self._get_revision_by_id(self.kwargs.get("SWHID")) + return self._get_revision_by_id(self.kwargs.get("SWHID").object_id) class TargetRevisionNode(BaseRevisionNode): """ When a revision is requested as a target self.obj could be a snapshotbranch or a release self.obj.target is the requested revision id here """ def _get_node_data(self): """ self.obj.target is the Revision id """ return self._get_revision_by_id(self.obj.target) class ParentRevisionConnection(BaseConnection): """ When parent revisions requested from a revision self.obj is the current(child) revision self.obj.parentIds is the list of requested revisions """ _node_class = BaseRevisionNode def _get_paged_result(self): # FIXME, using dummy(local) pagination, move pagination to backend # To remove localpagination, just drop the paginated call # STORAGE-TODO (pagination) parents = archive.Archive().get_revisions(self.obj.parentIds) return utils.paginated(parents, self._get_first_arg(), self._get_after_arg()) class LogRevisionConnection(BaseConnection): """ When revisionslog is requested from a revision self.obj is the current revision id """ _node_class = BaseRevisionNode def _get_paged_result(self): # STORAGE-TODO (date in revisionlog is a dict) log = archive.Archive().get_revision_log([self.obj.id]) # FIXME, using dummy(local) pagination, move pagination to backend # To remove localpagination, just drop the paginated call # STORAGE-TODO (pagination) return utils.paginated(log, self._get_first_arg(), self._get_after_arg()) diff --git a/swh/graphql/resolvers/scalars.py b/swh/graphql/resolvers/scalars.py index 23ef947..9f599ba 100644 --- a/swh/graphql/resolvers/scalars.py +++ b/swh/graphql/resolvers/scalars.py @@ -1,49 +1,48 @@ from ariadne import ScalarType from swh.graphql.utils import utils from swh.model.fields.hashes import validate_sha1_git from swh.model.model import TimestampWithTimezone from swh.model.swhids import QualifiedSWHID datetime_scalar = ScalarType("DateTime") swhid_scalar = ScalarType("SWHID") sha1_scalar = ScalarType("Sha1") binary_text_scalar = ScalarType("BinaryText") datetimezone_scalar = ScalarType("DateTimeZone") @datetime_scalar.serializer def serialize_datetime(value): return utils.get_formatted_date(value) @sha1_scalar.serializer def serialize_sha1(value): return value.hex() @sha1_scalar.value_parser def validate_and_get_sha1_git(value): # FIXME, handle the error and raise a Graphql one validate_sha1_git(value) return bytearray.fromhex(value) @binary_text_scalar.serializer def serialize_binary_text(value): return value.decode("utf-8") @datetimezone_scalar.serializer def serialize_datetimezone(value): # FIXME, handle error and return None if type(value) == TimestampWithTimezone: date = value.to_datetime() return utils.get_formatted_date(date) return None @swhid_scalar.value_parser def validate_swhid(value): - swhid = QualifiedSWHID.from_string(value) - return swhid.object_id + return QualifiedSWHID.from_string(value) diff --git a/swh/graphql/resolvers/snapshot.py b/swh/graphql/resolvers/snapshot.py index 07dd72e..4258786 100644 --- a/swh/graphql/resolvers/snapshot.py +++ b/swh/graphql/resolvers/snapshot.py @@ -1,51 +1,51 @@ from swh.graphql.backends import archive from swh.graphql.utils import utils from .base_connection import BaseConnection from .base_node import BaseNode class BaseSnapshotNode(BaseNode): def _get_snapshot_by_id(self, snapshot_id): # Now not fetching any data (schema is exposing just id) # same pattern is used in directory resolver return { "id": snapshot_id, } class SnapshotNode(BaseSnapshotNode): """ For directly accessing a snapshot with an Id """ def _get_node_data(self): """ """ # FXIME, query to make sure snapshot exists - return self._get_snapshot_by_id(self.kwargs.get("SWHID")) + return self._get_snapshot_by_id(self.kwargs.get("SWHID").object_id) class VisitSnapshotNode(BaseSnapshotNode): """ For accessing a snapshot from a visitstatus type """ def _get_node_data(self): """ self.obj is visitstatus here self.obj.snapshot is the requested snapshot id """ return self._get_snapshot_by_id(self.obj.snapshot) class OriginSnapshotConnection(BaseConnection): _node_class = BaseSnapshotNode def _get_paged_result(self): """ """ results = archive.Archive().get_origin_snapshots(self.obj.url) snapshots = [{"id": snapshot} for snapshot in results] # FIXME, using dummy(local) pagination, move pagination to backend # To remove localpagination, just drop the paginated call # STORAGE-TODO return utils.paginated(snapshots, self._get_first_arg(), self._get_after_arg())