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 @@ -77,3 +77,6 @@ def get_content(self, content_id): # FIXME, only for tests return self.storage.content_find({"sha1_git": content_id}) + + def get_content_data(self, content_sha1): + return self.storage.content_get_data(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 @@ -31,6 +31,12 @@ def id(self): return self._node.sha1_git + @property + def data(self): + # FIXME, return a Node object + content_sha1 = self._node.hashes()["sha1"] + return {"raw": archive.Archive().get_content_data(content_sha1)} + def is_type_of(self): # is_type_of is required only when resolving a UNION type # This is for ariadne to return the right type 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 @@ -775,6 +775,42 @@ sha256: String } +""" +Object with different content data representations +""" +type ContentData { + """ + Content as a base64 string + """ + raw: BinaryString +} + +type ContentFileType { + """ + Detected content encoding + """ + encoding: String + + """ + Detected MIME type of the content + """ + mimetype: String +} + +type ContentLanguage { + """ + Detected programming language if any + """ + lang: String +} + +type ContentLicense { + """ + Array of strings containing the detected license names + """ + licenses: [String] +} + """ A content object """ @@ -803,6 +839,26 @@ Content status, visible or hidden """ status: String + + """ + File content + """ + data: ContentData + + """ + Information about the content MIME type + """ + fileType: ContentFileType + + """ + Information about the programming language used in the content + """ + language: ContentLanguage + + """ + Information about the license of the content + """ + license: ContentLicense } """