diff --git a/swh/graphql/backends/archive.py b/swh/graphql/backends/archive.py --- a/swh/graphql/backends/archive.py +++ b/swh/graphql/backends/archive.py @@ -139,8 +139,8 @@ } return not list(mapping[object_type]([object_id])) - def get_contents(self, checksums: Dict[str, Any]) -> List[Content]: - return self.storage.content_find(content=checksums) + def get_contents(self, hashes: Dict[str, Any]) -> List[Content]: + return self.storage.content_find(content=hashes) # def get_content_data(self, content_sha1: Sha1) -> Optional[bytes]: # return self.storage.content_get_data(content=content_sha1) diff --git a/swh/graphql/resolvers/content.py b/swh/graphql/resolvers/content.py --- a/swh/graphql/resolvers/content.py +++ b/swh/graphql/resolvers/content.py @@ -17,13 +17,13 @@ Base resolver for all the content nodes """ - def _get_content_by_hash(self, checksums: dict): - content = self.archive.get_contents(checksums) + def _get_content_by_hashes(self, hashes: dict): + content = self.archive.get_contents(hashes) # in case of a conflict, return the first element return content[0] if content else None @property - def checksum(self): + def hashes(self): # FIXME, use a Node instead return {k: v.hex() for (k, v) in self._node.hashes().items()} @@ -68,18 +68,18 @@ """ def _get_node_data(self): - checksums = {"sha1_git": self.kwargs.get("swhid").object_id} - return self._get_content_by_hash(checksums) + hashes = {"sha1_git": self.kwargs.get("swhid").object_id} + return self._get_content_by_hashes(hashes) class HashContentNode(BaseContentNode): """ - Node resolver for a content requested with one or more checksums + Node resolver for a content requested with one or more hashes """ def _get_node_data(self): - checksums = dict(self.kwargs.get("checksums")) - return self._get_content_by_hash(checksums) + hashes = dict(self.kwargs.get("hashes")) + return self._get_content_by_hashes(hashes) class TargetContentNode(BaseContentNode): @@ -96,4 +96,4 @@ ] def _get_node_data(self): - return self._get_content_by_hash(checksums={"sha1_git": self.obj.target_hash}) + return self._get_content_by_hashes(hashes={"sha1_git": self.obj.target_hash}) 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 @@ -195,7 +195,7 @@ return NodeObjectFactory.create(f"search-result-{obj.targetType}", obj, info, **kw) -@query.field("contentByHash") +@query.field("contentByHashes") def content_by_hash_resolver( obj: None, info: GraphQLResolveInfo, **kw ) -> rs.content.ContentNode: diff --git a/swh/graphql/resolvers/scalars.py b/swh/graphql/resolvers/scalars.py --- a/swh/graphql/resolvers/scalars.py +++ b/swh/graphql/resolvers/scalars.py @@ -57,7 +57,7 @@ hash_type, hash_string = value.split(":") hash_value = hashutil.hash_to_bytes(hash_string) except ValueError as e: - raise InvalidInputError("Invalid content checksum", e) + raise InvalidInputError("Invalid content hash", e) if hash_type not in hashutil.ALGORITHMS: raise InvalidInputError("Invalid hash algorithm") return hash_type, hash_value 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 @@ -809,9 +809,9 @@ } """ -An object with different content checksums +An object with different content hashes """ -type ContentChecksum { +type ContentHashes { blake2s256: String sha1: String sha1_git: String @@ -869,9 +869,9 @@ swhid: SWHID! """ - Checksums for the content + Hashes for the content """ - checksum: ContentChecksum + hashes: ContentHashes """ Length of the content in bytes @@ -1088,11 +1088,11 @@ Get the content by one or more hashes Use multiple hashes for an accurate result """ - contentByHash( + contentByHashes( """ List of hashType:hashValue strings """ - checksums: [ContentHash]! + hashes: [ContentHash]! ): Content """ diff --git a/swh/graphql/tests/functional/test_content.py b/swh/graphql/tests/functional/test_content.py --- a/swh/graphql/tests/functional/test_content.py +++ b/swh/graphql/tests/functional/test_content.py @@ -16,7 +16,7 @@ content(swhid: $swhid) { swhid id - checksum { + hashes { blake2s256 sha1 sha1_git @@ -44,7 +44,7 @@ response = { "swhid": str(content.swhid()), "id": content.sha1_git.hex(), - "checksum": { + "hashes": { "blake2s256": content.blake2s256.hex(), "sha1": content.sha1.hex(), "sha1_git": content.sha1_git.hex(), @@ -65,8 +65,8 @@ @pytest.mark.parametrize("content", get_contents()) def test_get_content_with_hash(client, content): query_str = """ - query getContent($checksums: [ContentHash]!) { - contentByHash(checksums: $checksums) { + query getContent($hashes: [ContentHash]!) { + contentByHashes(hashes: $hashes) { swhid } } @@ -74,14 +74,14 @@ data, _ = utils.get_query_response( client, query_str, - checksums=[ + hashes=[ f"blake2s256:{content.blake2s256.hex()}", f"sha1:{content.sha1.hex()}", f"sha1_git:{content.sha1_git.hex()}", f"sha256:{content.sha256.hex()}", ], ) - assert data["contentByHash"] == {"swhid": str(content.swhid())} + assert data["contentByHashes"] == {"swhid": str(content.swhid())} def test_get_content_with_invalid_swhid(client): @@ -101,8 +101,8 @@ def test_get_content_with_invalid_hashes(client): content = get_contents()[0] query_str = """ - query getContent($checksums: [ContentHash]!) { - contentByHash(checksums: $checksums) { + query getContent($hashes: [ContentHash]!) { + contentByHashes(hashes: $hashes) { swhid } } @@ -110,7 +110,7 @@ errors = utils.get_error_response( client, query_str, - checksums=[ + hashes=[ "invalid", # Only one hash is invalid f"sha1:{content.sha1.hex()}", f"sha1_git:{content.sha1_git.hex()}", @@ -119,20 +119,20 @@ ) # API will throw an error in case of an invalid content hash assert len(errors) == 1 - assert "Input error: Invalid content checksum" in errors[0]["message"] + assert "Input error: Invalid content hash" in errors[0]["message"] def test_get_content_with_invalid_hash_algorithm(client): content = get_contents()[0] query_str = """ - query getContent($checksums: [ContentHash]!) { - contentByHash(checksums: $checksums) { + query getContent($hashes: [ContentHash]!) { + contentByHashes(hashes: $hashes) { swhid } } """ data, errors = utils.get_query_response( - client, query_str, checksums=[f"test:{content.sha1.hex()}"] + client, query_str, hashes=[f"test:{content.sha1.hex()}"] ) assert data is None assert len(errors) == 1 diff --git a/swh/graphql/tests/unit/resolvers/test_scalars.py b/swh/graphql/tests/unit/resolvers/test_scalars.py --- a/swh/graphql/tests/unit/resolvers/test_scalars.py +++ b/swh/graphql/tests/unit/resolvers/test_scalars.py @@ -38,7 +38,7 @@ def test_validate_content_hash_invalid_value(content_hash): with pytest.raises(InvalidInputError) as e: scalars.validate_content_hash(content_hash) - assert "Invalid content checksum" in str(e.value) + assert "Invalid content hash" in str(e.value) def test_validate_content_hash_invalid_hash_algo():