diff --git a/swh/graphql/resolvers/resolvers.py b/swh/graphql/resolvers/resolvers.py --- a/swh/graphql/resolvers/resolvers.py +++ b/swh/graphql/resolvers/resolvers.py @@ -245,10 +245,10 @@ return resolver(obj, info, **kw) -# @revision.field("revisionLog") -# def revision_log_resolver(obj, info, **kw): -# resolver = get_connection_resolver("revision-log") -# return resolver(obj, info, **kw) +@revision.field("revisionLog") +def revision_log_resolver(obj, info, **kw): + resolver = get_connection_resolver("revision-log") + return resolver(obj, info, **kw) @directory.field("entries") diff --git a/swh/graphql/resolvers/revision.py b/swh/graphql/resolvers/revision.py --- a/swh/graphql/resolvers/revision.py +++ b/swh/graphql/resolvers/revision.py @@ -7,6 +7,7 @@ from swh.graphql.backends import archive from swh.graphql.utils import utils +from swh.model.model import Revision from swh.model.swhids import CoreSWHID, ObjectType from swh.storage.interface import PagedResult @@ -98,8 +99,11 @@ _node_class = BaseRevisionNode def _get_paged_result(self) -> PagedResult: - # STORAGE-TODO (date in revisionlog is a dict) log = archive.Archive().get_revision_log([self.obj.swhid.object_id]) + # Storage is returning a list of dicts instead of model objects + # Following loop is to reverse that operation + # STORAGE-TODO; remove to_dict from storage.revison_log + log = [Revision.from_dict(rev) for rev in log] # FIXME, using dummy(local) pagination, move pagination to backend # To remove localpagination, just drop the paginated call # STORAGE-TODO (pagination) diff --git a/swh/graphql/tests/data.py b/swh/graphql/tests/data.py --- a/swh/graphql/tests/data.py +++ b/swh/graphql/tests/data.py @@ -4,7 +4,7 @@ # See top-level LICENSE file for more information from swh.model.hashutil import hash_to_bytes -from swh.model.model import ObjectType, Release +from swh.model.model import ObjectType, Release, Revision, RevisionType from swh.model.tests import swh_model_data @@ -78,7 +78,30 @@ return [with_revision, with_release, with_directory, with_content] -GRAPHQL_EXTRA_TEST_OBJECTS = {"release": get_releases_with_target()} +def get_revisions_with_parents(): + """ + Revisions with real revisions as parents + """ + return [ + Revision( + id=hash_to_bytes("37580d63b8dcc0ec73e74994e66896858542844c"), + message=b"hello", + date=swh_model_data.DATES[0], + committer=swh_model_data.COMMITTERS[0], + author=swh_model_data.COMMITTERS[0], + committer_date=swh_model_data.DATES[0], + type=RevisionType.GIT, + directory=b"\x01" * 20, + synthetic=False, + parents=(get_revisions()[0].id, get_revisions()[1].id), + ) + ] + + +GRAPHQL_EXTRA_TEST_OBJECTS = { + "release": get_releases_with_target(), + "revision": get_revisions_with_parents(), +} def populate_dummy_data(storage): diff --git a/swh/graphql/tests/functional/test_revision.py b/swh/graphql/tests/functional/test_revision.py --- a/swh/graphql/tests/functional/test_revision.py +++ b/swh/graphql/tests/functional/test_revision.py @@ -110,3 +110,50 @@ assert revision_obj == { "swhid": "swh:1:rev:66c7c1cd9673275037140f2abff7b7b11fc9439c" } + + +def test_get_revision_log(client): + revision_swhid = "swh:1:rev:37580d63b8dcc0ec73e74994e66896858542844c" + query_str = """ + { + revision(swhid: "%s") { + swhid + revisionLog(first: 3) { + nodes { + swhid + } + } + } + } + """ + data, _ = utils.get_query_response(client, query_str % revision_swhid) + assert data["revision"]["revisionLog"] == { + "nodes": [ + {"swhid": "swh:1:rev:37580d63b8dcc0ec73e74994e66896858542844c"}, + {"swhid": "swh:1:rev:66c7c1cd9673275037140f2abff7b7b11fc9439c"}, + {"swhid": "swh:1:rev:c7f96242d73c267adc77c2908e64e0c1cb6a4431"}, + ] + } + + +def test_get_revision_parents(client): + revision_swhid = "swh:1:rev:37580d63b8dcc0ec73e74994e66896858542844c" + query_str = """ + { + revision(swhid: "%s") { + swhid + parents { + nodes { + swhid + } + } + } + } + """ + data, _ = utils.get_query_response(client, query_str % revision_swhid) + assert data["revision"]["parents"] == { + "nodes": [ + {"swhid": "swh:1:rev:66c7c1cd9673275037140f2abff7b7b11fc9439c"}, + {"swhid": "swh:1:rev:c7f96242d73c267adc77c2908e64e0c1cb6a4431"}, + ] + }