diff --git a/swh/graphql/schema/schema.graphql b/swh/graphql/schema/schema.graphql --- a/swh/graphql/schema/schema.graphql +++ b/swh/graphql/schema/schema.graphql @@ -88,10 +88,13 @@ Edge in origin connection """ type OriginEdge { - """ - Cursor to request the next page after the item - """ - cursor: String! + # Cursor in this edge is removed for the time being + # see https://forge.softwareheritage.org/D8911 for details + + # """ + # Cursor to request the next page after the item + # """ + # cursor: String! """ Origin object @@ -193,10 +196,13 @@ Edge in origin visit connection """ type VisitEdge { - """ - Cursor to request the next page after the item - """ - cursor: String! + # Cursor in this edge is removed for the time being + # see https://forge.softwareheritage.org/D8911 for details + + # """ + # Cursor to request the next page after the item + # """ + # cursor: String! """ Visit object @@ -300,10 +306,13 @@ Edge in visit status connection """ type VisitStatusEdge { - """ - Cursor to request the next page after the item - """ - cursor: String! + # Cursor in this edge is removed for the time being + # see https://forge.softwareheritage.org/D8911 for details + + # """ + # Cursor to request the next page after the item + # """ + # cursor: String! """ Visit status object @@ -450,10 +459,13 @@ Edge in snapshot branch connection """ type BranchConnectionEdge { - """ - Cursor to request the next page after the item - """ - cursor: String! + # Cursor in this edge is removed for the time being + # see https://forge.softwareheritage.org/D8911 for details + + # """ + # Cursor to request the next page after the item + # """ + # cursor: String! """ Branch object @@ -928,10 +940,13 @@ Edge in SearchResult connection """ type SearchResultEdge { - """ - Cursor to request the next page after the item - """ - cursor: String! + # Cursor in this edge is removed for the time being + # see https://forge.softwareheritage.org/D8911 for details + + # """ + # Cursor to request the next page after the item + # """ + # cursor: String! """ SearchResult object diff --git a/swh/graphql/tests/functional/test_branch_connection.py b/swh/graphql/tests/functional/test_branch_connection.py --- a/swh/graphql/tests/functional/test_branch_connection.py +++ b/swh/graphql/tests/functional/test_branch_connection.py @@ -18,9 +18,6 @@ pageInfo { endCursor } - edges { - cursor - } nodes { targetType name { @@ -147,6 +144,5 @@ second_data, _ = get_branches(client, swhid=swhid, first=3, after=end_cursor) branches = second_data["snapshot"]["branches"] assert len(branches["nodes"]) == 3 - assert branches["edges"][0]["cursor"] == end_cursor for node in branches["nodes"]: assert node["name"]["text"] > node_name diff --git a/swh/graphql/tests/functional/test_pagination.py b/swh/graphql/tests/functional/test_pagination.py --- a/swh/graphql/tests/functional/test_pagination.py +++ b/swh/graphql/tests/functional/test_pagination.py @@ -4,7 +4,7 @@ # See top-level LICENSE file for more information from . import utils -from ..data import get_origins +from ..data import get_directories, get_origins # Using Origin object to run functional tests for pagination @@ -78,26 +78,74 @@ def test_edge_cursor(client): - origins = get_origin_nodes(client, first=1)[0]["origins"] - # end cursor here must be the item cursor for the second item - end_cursor = origins["pageInfo"]["endCursor"] - + # Use DirectoryEntry connection to test connection edges + # The same code is used in all the other connections, hence a single test + directory = get_directories()[1] query_str = """ - query getOrigins($first: Int!, $after: String) { - origins(first: $first, after: $after) { - edges { - cursor - node { - id + query getDirectory($swhid: SWHID!, $entries_first: Int!, $entries_after: String) { + directory(swhid: $swhid) { + entries(first: $entries_first, after: $entries_after) { + edges { + cursor + node { + name { + text + } + } + } + pageInfo { + endCursor + hasNextPage + } + nodes { + name { + text + } } - } - nodes { - id } } } """ - data, _ = utils.get_query_response(client, query_str, first=1, after=end_cursor) - origins = data["origins"] - assert [edge["node"] for edge in origins["edges"]] == origins["nodes"] - assert origins["edges"][0]["cursor"] == end_cursor + data, _ = utils.get_query_response( + client, query_str, swhid=str(directory.swhid()), entries_first=1 + ) + entries = data["directory"]["entries"] + # Make sure the first node object in edges and nodes is the same + assert entries["edges"][0]["node"] == entries["nodes"][0] + assert entries["edges"][0]["node"] == { + "name": {"text": directory.entries[1].name.decode()} + } + assert entries["pageInfo"]["hasNextPage"] is True + # FIXME, Following behaviour is not in compliance with the relay spec. + # last-item-cursor and endcursor should be the same as per relay. + # This test will fail once the pagination becomes fully relay complaint. + assert entries["pageInfo"]["endCursor"] != entries["edges"][-1]["cursor"] + # Make another query with the after argument, after argument is the first item + # cursor here, result will be the same as the last one + new_data, _ = utils.get_query_response( + client, + query_str, + swhid=str(directory.swhid()), + entries_first=1, + entries_after=entries["edges"][0]["cursor"], + ) + assert new_data == data + # Make another query with the end cursor from the first query + final_data, _ = utils.get_query_response( + client, + query_str, + swhid=str(directory.swhid()), + entries_first=2, + entries_after=entries["pageInfo"]["endCursor"], + ) + final_result_entries = final_data["directory"]["entries"] + # endcursor from the first query will be the first item cursor here + # FIXME, this behaviour is not in compliance with the relay spec. + # With relay spec, items after the given cursor ($after) will be returned + assert ( + final_result_entries["edges"][0]["cursor"] == entries["pageInfo"]["endCursor"] + ) + assert final_result_entries["nodes"] == [ + {"name": {"text": directory.entries[0].name.decode()}}, + {"name": {"text": directory.entries[2].name.decode()}}, + ] diff --git a/swh/graphql/tests/functional/test_visit_status.py b/swh/graphql/tests/functional/test_visit_status.py --- a/swh/graphql/tests/functional/test_visit_status.py +++ b/swh/graphql/tests/functional/test_visit_status.py @@ -53,7 +53,6 @@ endCursor } edges { - cursor node { status } @@ -76,7 +75,6 @@ endCursor } edges { - cursor node { status } @@ -95,7 +93,6 @@ assert data["visit"]["statuses"] == { "edges": [ { - "cursor": "MjAxNC0wNS0wN1QwNDoyMDozOS40MzIyMjIrMDA6MDA=", "node": {"status": "ongoing"}, } ],