diff --git a/swh/graphql/resolvers/revision.py b/swh/graphql/resolvers/revision.py index 8094b6a..d3ad410 100644 --- a/swh/graphql/resolvers/revision.py +++ b/swh/graphql/resolvers/revision.py @@ -1,91 +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("Sha1")) 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 + # 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 + # 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 8189033..89ba314 100644 --- a/swh/graphql/resolvers/scalars.py +++ b/swh/graphql/resolvers/scalars.py @@ -1,41 +1,44 @@ 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 - date = value.to_datetime() - return utils.get_formatted_date(date) + if type(value) == TimestampWithTimezone: + date = value.to_datetime() + return utils.get_formatted_date(date) + return None