diff --git a/swh/graphql/resolvers/directory.py b/swh/graphql/resolvers/directory.py index 5b9a601..a6153a9 100644 --- a/swh/graphql/resolvers/directory.py +++ b/swh/graphql/resolvers/directory.py @@ -1,33 +1,42 @@ from swh.graphql.backends import archive from swh.graphql.utils import utils from .base_node import BaseNode class BaseDirectoryNode(BaseNode): def _get_directory_by_id(self, directory_id): return archive.Archive().get_directory(directory_id) @property def entries(self): # FIXME, return a paginated list of # directory or contnet node object return self._node[0]["name"] @property def name(self): return b"test-name" @property def id(self): return b"test-id" class DirectoryNode(BaseDirectoryNode): def _get_node_data(self): """ When a directory is requested directly (not from a connection) with an id """ directory_id = utils.str_to_swid(self.kwargs.get("SWHId")) return self._get_directory_by_id(directory_id) + + +class RevisionDirectoryNode(BaseDirectoryNode): + def _get_node_data(self): + """ + When a directory is requested from a revision + """ + directory_id = self.kwargs.get("sha1") + return self._get_directory_by_id(directory_id) diff --git a/swh/graphql/resolvers/revision.py b/swh/graphql/resolvers/revision.py index af54d0c..9910a48 100644 --- a/swh/graphql/resolvers/revision.py +++ b/swh/graphql/resolvers/revision.py @@ -1,82 +1,98 @@ from swh.graphql.backends import archive from swh.graphql.utils import utils from .base_node import BaseNode +from .directory import RevisionDirectoryNode class BaseRevisionNode(BaseNode): def _get_revision_by_id(self, revision_id): # FIXME, make this call async return (archive.Archive().get_revision(revision_id) or None)[0] @property def author(self): # return a PersoneNode object return self._node.author @property def committer(self): # return a PersoneNode object return self._node.committer @property def parentIds(self): # To support the schema naming convention return self._node.parents # @paginatedlist @property def parents(self): """ Return a list of parent revisions """ # FIXME, change this to a paginated list # Storage fix or use paginatedlist decorator + # change to node factory return [ ParentRevisionNode(obj=self, info=self.info, sha1=revision_id) for revision_id in self.parentIds ] + @property + def directoryId(self): # To support the schema naming convention + """ + """ + return self._node.directory + + @property + def directory(self): + """ + Return the + """ + # FIXME change to node factory + return RevisionDirectoryNode(obj=self, info=self.info, sha1=self.directoryId) + def is_type_of(self): """ is_type_of is required only when requesting from a connection This is for ariadne to return the correct type in schema """ return "Revision" class RevisionNode(BaseRevisionNode): """ When the revision is requested directly (not from a connection) with an id """ def _get_node_data(self): revision_id = utils.str_to_swid(self.kwargs.get("SWHId")) return self._get_revision_by_id(revision_id) class ParentRevisionNode(BaseRevisionNode): """ When a parent revision is requested """ def _get_node_data(self): revision_id = self.kwargs.get("sha1") return self._get_revision_by_id(revision_id) class BranchRevisionNode(BaseRevisionNode): """ When the revision is requested from a snapshot branch self.obj is a branch object self.obj.target is the revision id """ def _get_node_data(self): """ self.obj.target is the Revision id """ return self._get_revision_by_id(self.obj.target) diff --git a/swh/graphql/schema/schema.graphql b/swh/graphql/schema/schema.graphql index f9869ed..c20a37c 100644 --- a/swh/graphql/schema/schema.graphql +++ b/swh/graphql/schema/schema.graphql @@ -1,253 +1,254 @@ scalar SWHId scalar DateTime scalar DateTimeZone scalar BinaryText interface Node { id: ID! } interface SWHNode { id: 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 SWHNode { id: SWHId! # FIXME, this is not swhid 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 implements Node { id: ID! status: String! date: DateTime! snapshot: Snapshot type: String } # FIXME, add OriginSnapshotConnection type Snapshot implements SWHNode { id: SWHId! 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] } # FIXME, this could be alias or Directory as well union BranchTarget = Revision | Release type Branch implements Node { id: ID! name: BinaryText type: String # FIXME, change to an enum target: BranchTarget } # type RevisionConnection { # } # type RevisionEdge { # } type Person { email: BinaryText name: BinaryText fullname: BinaryText } type Revision implements SWHNode { id: SWHId! message: BinaryText author: Person committer: Person date: DateTimeZone type: String - directory: SWHId + directoryId: SWHId + directory: Directory parentIds: [SWHId] parents: [Revision] } # type ReleaseConnection { # } # type ReleasEdge { # } type Release implements SWHNode { id: SWHId! name: BinaryText message: BinaryText author: Person date: DateTimeZone } type Directory implements SWHNode { id: SWHId! name: BinaryText entries: BinaryText # FIXME, change to Union type } type Content implements SWHNode { id: SWHId! status: String } 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( SWHId: 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( SWHId: String! ): Revision """ Get the release with the given swhid """ release( SWHId: String! ): Release """ Get the directory with the given swhid """ directory( SWHId: String! ): Directory """ Get the content with the given swhid """ content( SWHId: String! ): Content # """ # Search with the given swhid # """ # searchWithSwhid }