diff --git a/swh/graphql/app.py b/swh/graphql/app.py index e52374f..f438767 100644 --- a/swh/graphql/app.py +++ b/swh/graphql/app.py @@ -1,36 +1,35 @@ # import pkg_resources import os from pathlib import Path from ariadne import gql, load_schema_from_path, make_executable_schema from .resolvers import resolvers, scalars type_defs = gql( # pkg_resources.resource_string("swh.graphql", "schem/schema.graphql").decode() load_schema_from_path( os.path.join(Path(__file__).parent.resolve(), "schema", "schema.graphql") ) ) schema = make_executable_schema( type_defs, resolvers.query, resolvers.origin, resolvers.visit, resolvers.visit_status, resolvers.snapshot, resolvers.snapshot_branch, resolvers.revision, resolvers.release, resolvers.directory, resolvers.directory_entry, resolvers.branch_target, resolvers.release_target, resolvers.directory_entry_target, scalars.id_scalar, scalars.string_scalar, scalars.datetime_scalar, scalars.swhid_scalar, - scalars.hash_value_scalar, ) diff --git a/swh/graphql/resolvers/content.py b/swh/graphql/resolvers/content.py index d123371..68d71e0 100644 --- a/swh/graphql/resolvers/content.py +++ b/swh/graphql/resolvers/content.py @@ -1,44 +1,44 @@ from swh.graphql.backends import archive from .base_node import BaseSWHNode class BaseContentNode(BaseSWHNode): """ """ def _get_content_by_id(self, content_id): content = archive.Archive().get_content(content_id) return content[0] if content else None @property def checksum(self): # FIXME, return a Node object - return self._node.hashes() + return {k: v.hex() for (k, v) in self._node.hashes().items()} @property def id(self): return self._node.sha1_git def is_type_of(self): return "Content" class ContentNode(BaseContentNode): def _get_node_data(self): """ When a content is requested directly with its 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.targetHash here """ content_id = self.obj.targetHash return self._get_content_by_id(content_id) diff --git a/swh/graphql/resolvers/scalars.py b/swh/graphql/resolvers/scalars.py index b615900..e21ffec 100644 --- a/swh/graphql/resolvers/scalars.py +++ b/swh/graphql/resolvers/scalars.py @@ -1,52 +1,46 @@ from datetime import datetime from ariadne import ScalarType from swh.graphql.utils import utils from swh.model.model import TimestampWithTimezone from swh.model.swhids import CoreSWHID datetime_scalar = ScalarType("DateTime") swhid_scalar = ScalarType("SWHID") -hash_value_scalar = ScalarType("HashValue") id_scalar = ScalarType("ID") string_scalar = ScalarType("String") @id_scalar.serializer def serialize_id(value): if type(value) is bytes: return value.hex() return value @string_scalar.serializer def serialize_string(value): if type(value) is bytes: return value.decode("utf-8") return value -@hash_value_scalar.serializer -def serialize_hash_value(value): - return value.hex() - - @datetime_scalar.serializer def serialize_datetime(value): # FIXME, handle error and return None if type(value) == TimestampWithTimezone: value = value.to_datetime() if type(value) == datetime: return utils.get_formatted_date(value) return None @swhid_scalar.value_parser def validate_swhid(value): return CoreSWHID.from_string(value) @swhid_scalar.serializer def serialize_swhid(value): return str(value) diff --git a/swh/graphql/schema/schema.graphql b/swh/graphql/schema/schema.graphql index 3127474..4f901d3 100644 --- a/swh/graphql/schema/schema.graphql +++ b/swh/graphql/schema/schema.graphql @@ -1,338 +1,336 @@ scalar SWHID -scalar HashValue - scalar DateTime interface Node { id: ID! } interface MerkleNode { SWHID: SWHID! } type PageInfo { endCursor: String hasNextPage: Boolean! } type OriginConnection { edges: [OriginEdge] nodes: [Origin] pageInfo: PageInfo! totalCount: Int } type OriginEdge { cursor: String! node: Origin } type Origin implements Node { id: ID! url: String! visits( first: Int! after: String ): VisitConnection! latestVisit: Visit snapshots( first: Int! after: String ): SnapshotConnection } type VisitConnection { edges: [VisitEdge] nodes: [Visit] pageInfo: PageInfo! totalCount: Int } type VisitEdge { cursor: String! node: Visit } type Visit implements Node { id: ID! visitId: Int date: DateTime! type: String status( first: Int after: String ): VisitStatusConnection latestStatus: VisitStatus } type VisitStatusConnection { edges: [VisitStatusEdge] nodes: [VisitStatus] pageInfo: PageInfo! totalCount: Int } type VisitStatusEdge { cursor: String! node: VisitStatus } type VisitStatus { status: String! date: DateTime! snapshotSWHID: SWHID snapshot: Snapshot type: String } type SnapshotConnection { edges: [SnapshotEdge] nodes: [Snapshot] pageInfo: PageInfo! totalCount: Int } type SnapshotEdge { cursor: String! node: Snapshot } type Snapshot implements MerkleNode & Node { id: ID! SWHID: SWHID! branches( first: Int! after: String types: [BranchTypes] nameInclude: String ): BranchConnection } type BranchConnection { edges: [BranchConnectionEdge] nodes: [Branch] pageInfo: PageInfo! totalCount: Int } type BranchConnectionEdge { cursor: String! node: Branch } type Person { email: String name: String fullname: String } union BranchTarget = Revision | Release | Branch | Content | Directory | Snapshot enum BranchTypes { revision release alias content directory snapshot } type Branch { name: String type: BranchTypes target: BranchTarget } type RevisionConnection { edges: [RevisionEdge] nodes: [Revision] pageInfo: PageInfo! totalCount: Int } type RevisionEdge { cursor: String! node: Revision } type Revision implements MerkleNode & Node { id: ID! SWHID: SWHID! message: String author: Person committer: Person date: DateTime type: String # Revision type: FIXME, change to an enum # directorySWHID: SWHID directory: Directory parentSWHIDs: [SWHID] parents( first: Int after: String ): RevisionConnection revisionLog( first: Int! after: String ): RevisionConnection } union ReleaseTarget = Release | Revision | Directory | Content enum ReleaseTargetType { release revision content directory } type Release implements MerkleNode & Node { id: ID! SWHID: SWHID! name: String message: String author: Person date: DateTime targetType: ReleaseTargetType target: ReleaseTarget } type DirectoryEntryConnection { edges: [DirectoryEntryEdge] nodes: [DirectoryEntry] pageInfo: PageInfo! totalCount: Int } type DirectoryEntryEdge { cursor: String! node: DirectoryEntry } union DirectoryEntryTarget = Directory | Content enum DirectoryEntryType { dir file rev } type DirectoryEntry { name: String type: DirectoryEntryType target: DirectoryEntryTarget } type Directory implements MerkleNode & Node { id: ID! SWHID: SWHID! entries( first: Int after: String ): DirectoryEntryConnection } type ContentChecksum { - blake2s256: HashValue - sha1: HashValue - sha1_git: HashValue - sha256: HashValue + blake2s256: String + sha1: String + sha1_git: String + sha256: String } # type ContentType { # test: String # } # type ContentLanguage { # test: String # } # type ContentLicense { # test: String # } type Content implements MerkleNode & Node { id: ID! SWHID: SWHID! checksum: ContentChecksum # data: # filetype: ContentType # language: ContentLanguage # license: ContentLicense length: Int status: String data: String } type Query { """ Get an origin with its url """ origin( url: String! ): Origin """ Get a list of origins matching the given filters Can also be used to search for an origin """ # FIMXE, use Input types to make this cleaner origins( first: Int! after: String urlPattern: String ): OriginConnection """ Get a visit object with its id and/or origin and visit id """ visit( originUrl: String! visitId: Int! ): Visit """ Get a snapshot with Sha1 """ snapshot( SWHID: SWHID! ): Snapshot """ Get the revision with the given Sha1 """ revision( SWHID: SWHID! ): Revision """ Get the release with the given Sha1 """ release( SWHID: SWHID! ): Release """ Get the directory with the given Sha1 """ directory( SWHID: SWHID! ): Directory """ Get the content with the given Sha1 """ content( SWHID: SWHID! ): Content # """ # Search with the given swhid # """ # searchWithSwhid }