diff --git a/swh/graphql/resolvers/content.py b/swh/graphql/resolvers/content.py index b04f45a..74d80a8 100644 --- a/swh/graphql/resolvers/content.py +++ b/swh/graphql/resolvers/content.py @@ -1,38 +1,55 @@ from swh.graphql.backends import archive from swh.graphql.utils import utils from .base_node import BaseNode class BaseContentNode(BaseNode): + """ + """ + def _get_content_by_id(self, content_id): - return archive.Archive().get_content(content_id) + content = archive.Archive().get_content(content_id) + return content[0] if content else None @property def id(self): - return b"test" + return self._node.unique_key() + + @property + def swhid(self): + return self._node.swhid() + + @property + def checksum(self): + # FIXME, return a Node object + return self._node.hashes() + + @property + def data(self): + return def is_type_of(self): return "Content" class ContentNode(BaseContentNode): def _get_node_data(self): """ When a content is requested directly with an id """ content_id = utils.str_to_swid(self.kwargs.get("SWHID")) - return self._get_content_by_id(content_id)[0] + return self._get_content_by_id(content_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.target here """ content_id = self.obj.target return self._get_content_by_id(content_id) diff --git a/swh/graphql/schema/schema.graphql b/swh/graphql/schema/schema.graphql index 4969dec..c659918 100644 --- a/swh/graphql/schema/schema.graphql +++ b/swh/graphql/schema/schema.graphql @@ -1,319 +1,324 @@ scalar SWHID scalar Sha1 scalar DateTime scalar DateTimeZone scalar BinaryText interface Node { id: ID! } # interface SWHIDNode { # id: SWHID! # } interface SWHNode { id: Sha1! } 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 SWHNode { id: Sha1! url: String! visits( first: Int after: String ): VisitConnection! } type VisitConnection { edges: [VisitEdge] nodes: [Visit] pageInfo: PageInfo! totalCount: Int } type VisitEdge { cursor: String! node: Visit } type Visit implements Node { id: ID! date: DateTime! type: String status( first: Int after: String ): VisitStatusConnection # origin: Origin # FIXME, this can be added later } type VisitStatusConnection { edges: [VisitStatusEdge] nodes: [VisitStatus] pageInfo: PageInfo! totalCount: Int } type VisitStatusEdge { cursor: String! node: VisitStatus } type VisitStatus { status: String! date: DateTime! snapshot: Snapshot type: String } # FIXME, add OriginSnapshotConnection type Snapshot implements SWHNode { id: Sha1! branches( first: Int after: String ): BranchConnection # releases( # first: Int # after: String # ): ReleaseConnection # FIXME, add alias type as well } type BranchConnection { edges: [BranchConnectionEdge] nodes: [Branch] pageInfo: PageInfo! totalCount: Int } type BranchConnectionEdge { cursor: String! node: Branch } type Person { email: BinaryText name: BinaryText fullname: BinaryText } # FIXME, this can be Content, Directory, Snapshot, or Alias as well union BranchTarget = Revision | Release type Branch { name: BinaryText type: String # FIXME, change to an enum targetId: Sha1 target: BranchTarget } type RevisionConnection { edges: [RevisionEdge] nodes: [Revision] pageInfo: PageInfo! totalCount: Int } type RevisionEdge { cursor: String! node: Revision } type Revision implements SWHNode { id: Sha1! message: BinaryText author: Person committer: Person date: DateTimeZone type: String # Revision type: FIXME, change to an enum directoryId: Sha1 directory: Directory parentIds: [Sha1] parents( first: Int after: String ): RevisionConnection # log } # type ReleaseConnection { # } # type ReleasEdge { # } union ReleaseTarget = Release | Revision | Directory | Content type Release implements SWHNode { id: Sha1! name: BinaryText message: BinaryText author: Person date: DateTimeZone targetId: Sha1 type: String # target type: FIXME, change to an enum target: ReleaseTarget } type DirectoryEntryConnection { edges: [DirectoryEntryEdge] nodes: [DirectoryEntry] pageInfo: PageInfo! totalCount: Int } type DirectoryEntryEdge { cursor: String! node: DirectoryEntry } union DirectoryEntryTarget = Directory | Content type DirectoryEntry { name: BinaryText type: String # FIXME, replace with enum targetId: Sha1 target: DirectoryEntryTarget } type Directory implements SWHNode { id: Sha1! entries( first: Int after: String ): DirectoryEntryConnection } -type ContentChecksum { - test: String +type ContentChecksum { # FIXME, temp types + blake2s256: Sha1 + sha1: Sha1 + sha1_git: Sha1 + sha256: Sha1 } -type ContentType { - test: String -} +# type ContentType { +# test: String +# } -type ContentLanguage { - test: String -} +# type ContentLanguage { +# test: String +# } -type ContentLicense { - test: String -} +# type ContentLicense { +# test: String +# } type Content implements SWHNode { id: Sha1! + swhid: String checksum: ContentChecksum # data: - filetype: ContentType - language: ContentLanguage + # filetype: ContentType + # language: ContentLanguage + # license: ContentLicense length: Int - license: ContentLicense status: String + data: BinaryText } type Query { """ Get an origin with its url """ # FIXME, find some unique id to help cache # maybe base64 encode the 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 ): OriginConnection """ Get a visit object with its id and/or origin and visit id """ # FIXME, find some unique id to help cache visit( originUrl: String! id: String! ): Visit """ Get a snapshot with SWHID """ snapshot( Sha1: String! ): Snapshot # """ # Get all the snapshot for the given origin # """ # originSnapshot( # originUrl: String! # first: Int # after: String # ): SnapshotConnection """ Get the revision with the given swhid """ revision( Sha1: String! ): Revision """ Get the release with the given swhid """ release( Sha1: String! ): Release """ Get the directory with the given swhid """ directory( Sha1: String! ): Directory """ Get the content with the given swhid """ content( SWHID: String! ): Content # """ # Search with the given swhid # """ # searchWithSwhid }