Skip to main content

使用 GraphQL API for Discussions

了解如何使用 GitHub Discussions GraphQL API。

GitHub Discussions GraphQL API 允许您获取、创建、编辑和删除讨论帖子。 有关 GitHub Discussions 的详细信息,请参阅“关于讨论”。

此 API 适用于经过身份验证的用户、OAuth apps 和 GitHub 应用。 对于专用存储库,访问令牌需要 repo 范围,对于公共存储库,则需要 public_repo 范围。 有关详细信息,请参阅“OAuth 应用的范围”。

字段

Repository.discussions

列出仓库中的讨论。 如果指定了 categoryId,则仅返回该类别中的结果。 如果未指定 answered,则将返回已回答和未回答的讨论。

签名:

discussions( after: String, before: String, first: Int, last: Int, categoryId: ID = null, answered: Boolean = null, orderBy: DiscussionOrder = {field: UPDATED_AT, direction: DESC} ) : Discussion 

DiscussionOrder

""" Ways in which discussions can be ordered. """ input DiscussionOrder { """ The field by which to order discussions. """ field: DiscussionOrderField! """ The direction in which to order discussions by the specified field. """ direction: OrderDirection! } 
""" Properties by which discussion connections can be ordered. """ enum DiscussionOrderField { """ Order discussions by creation time. """ CREATED_AT """ Order discussions by most recent modification time. """ UPDATED_AT } 

Repository.discussionCategories

返回此仓库中定义的可用讨论类别。 每个存储库最多可以有 25 个类别。 有关讨论类别的详细信息,请参阅“关于讨论”。

签名:

discussionCategories( after: String, before: String, first: Int, last: Int, ) : DiscussionCategoryConnection! 

Repository.discussion

获取讨论. 如果使用指定 ID 的讨论不存在则返回 null

签名:

discussion(number: Int!) : Discussion 

Repository.pinnedDiscussions

返回固定到此仓库的讨论,按固定位置排序。

签名:

pinnedDiscussions( after: String, before: String, first: Int, last: Int, ) : PinnedDiscussionConnection! 

对象

注意:为简洁起见,此处不会扩展连接类型。 架构中提到的每个连接类型都遵循与 GraphQL API 中其他连接相同的模式。 有关详细信息,请参阅“GraphQL 简介”。

query { repository(owner: "github", name: "some-repo") { discussions(first: 10) { # type: DiscussionConnection totalCount # Int! pageInfo { # type: PageInfo (from the public schema) startCursor endCursor hasNextPage hasPreviousPage } edges { # type: DiscussionEdge cursor node { # type: Discussion id } } nodes { # type: Discussion id } } } } 

讨论 (Discussion)

字段:
""" A discussion in a repository. """ type Discussion implements Comment & Deletable & Lockable & Node & Reactable & RepositoryNode & Subscribable & Updatable { """ Reason that the conversation was locked. """ activeLockReason: LockReason """ Check if this discussion has been answered """ isAnswered: Boolean! """ The comment chosen as this discussion's answer, if any. """ answer: DiscussionComment """ The time when a user chose this discussion's answer, if answered. """ answerChosenAt: DateTime """ The user who chose this discussion's answer, if answered. """ answerChosenBy: Actor """ The actor who authored the comment. """ author: Actor """ Author's association with the subject of the comment. """ authorAssociation: CommentAuthorAssociation! """ The main text of the discussion post. """ body: String! """ The body rendered to HTML. """ bodyHTML: HTML! """ The body rendered to text. """ bodyText: String! """ The category for this discussion. """ category: DiscussionCategory! """ The replies to the discussion. """ comments( """ Returns the elements in the list that come after the specified cursor. """ after: String """ Returns the elements in the list that come before the specified cursor. """ before: String """ Returns the first _n_ elements from the list. """ first: Int """ Returns the last _n_ elements from the list. """ last: Int ): DiscussionCommentConnection! """ Identifies the date and time when the object was created. """ createdAt: DateTime! """ Check if this comment was created via an email reply. """ createdViaEmail: Boolean! """ Identifies the primary key from the database. """ databaseId: Int """ The actor who edited the comment. """ editor: Actor id: ID! """ Check if this comment was edited and includes an edit with the creation data """ includesCreatedEdit: Boolean! """ The moment the editor made the last edit """ lastEditedAt: DateTime """ `true` if the object is locked """ locked: Boolean! """ The number identifying this discussion within the repository. """ number: Int! """ Identifies when the comment was published at. """ publishedAt: DateTime """ A list of reactions grouped by content left on the subject. """ reactionGroups: [ReactionGroup!] """ A list of Reactions left on the Issue. """ reactions( """ Returns the elements in the list that come after the specified cursor. """ after: String """ Returns the elements in the list that come before the specified cursor. """ before: String """ Allows filtering Reactions by emoji. """ content: ReactionContent """ Returns the first _n_ elements from the list. """ first: Int """ Returns the last _n_ elements from the list. """ last: Int """ Allows specifying the order in which reactions are returned. """ orderBy: ReactionOrder ): ReactionConnection! """ The repository associated with this node. """ repository: Repository! """ The path for this discussion. """ resourcePath: URI! """ The title of this discussion. """ title: String! """ Identifies the date and time when the object was last updated. """ updatedAt: DateTime! """ The URL for this discussion. """ url: URI! """ A list of edits to this content. """ userContentEdits( """ Returns the elements in the list that come after the specified cursor. """ after: String """ Returns the elements in the list that come before the specified cursor. """ before: String """ Returns the first _n_ elements from the list. """ first: Int """ Returns the last _n_ elements from the list. """ last: Int ): UserContentEditConnection """ Check if the current viewer can delete this object. """ viewerCanDelete: Boolean! """ Can user react to this subject """ viewerCanReact: Boolean! """ Check if the viewer is able to change their subscription status for the repository. """ viewerCanSubscribe: Boolean! """ Check if the current viewer can update this object. """ viewerCanUpdate: Boolean! """ Did the viewer author this comment. """ viewerDidAuthor: Boolean! """ Identifies if the viewer is watching, not watching, or ignoring the subscribable entity. """ viewerSubscription: SubscriptionState } 

DiscussionComment

字段
""" A comment on a discussion. """ type DiscussionComment implements Comment & Deletable & Minimizable & Node & Reactable & Updatable & UpdatableComment { """ The actor who authored the comment. """ author: Actor """ Author's association with the subject of the comment. """ authorAssociation: CommentAuthorAssociation! """ The body as Markdown. """ body: String! """ The body rendered to HTML. """ bodyHTML: HTML! """ The body rendered to text. """ bodyText: String! """ Identifies the date and time when the object was created. """ createdAt: DateTime! """ Check if this comment was created via an email reply. """ createdViaEmail: Boolean! """ Identifies the primary key from the database. """ databaseId: Int """ The time when this replied-to comment was deleted """ deletedAt: DateTime """ The discussion this comment was created in """ discussion: Discussion """ The actor who edited the comment. """ editor: Actor id: ID! """ Check if this comment was edited and includes an edit with the creation data """ includesCreatedEdit: Boolean! """ Has this comment been chosen as the answer of its discussion? """ isAnswer: Boolean! """ Returns whether or not a comment has been minimized. """ isMinimized: Boolean! """ The moment the editor made the last edit """ lastEditedAt: DateTime """ Returns why the comment was minimized. """ minimizedReason: String """ Identifies when the comment was published at. """ publishedAt: DateTime """ A list of reactions grouped by content left on the subject. """ reactionGroups: [ReactionGroup!] """ A list of Reactions left on the Issue. """ reactions( """ Returns the elements in the list that come after the specified cursor. """ after: String """ Returns the elements in the list that come before the specified cursor. """ before: String """ Allows filtering Reactions by emoji. """ content: ReactionContent """ Returns the first _n_ elements from the list. """ first: Int """ Returns the last _n_ elements from the list. """ last: Int """ Allows specifying the order in which reactions are returned. """ orderBy: ReactionOrder ): ReactionConnection! """ The threaded replies to this comment. """ replies( """ Returns the elements in the list that come after the specified cursor. """ after: String """ Returns the elements in the list that come before the specified cursor. """ before: String """ Returns the first _n_ elements from the list. """ first: Int """ Returns the last _n_ elements from the list. """ last: Int ): DiscussionCommentConnection! """ The discussion comment this comment is a reply to """ replyTo: DiscussionComment """ The path for this discussion comment. """ resourcePath: URI! """ Identifies the date and time when the object was last updated. """ updatedAt: DateTime! """ The URL for this discussion comment. """ url: URI! """ A list of edits to this content. """ userContentEdits( """ Returns the elements in the list that come after the specified cursor. """ after: String """ Returns the elements in the list that come before the specified cursor. """ before: String """ Returns the first _n_ elements from the list. """ first: Int """ Returns the last _n_ elements from the list. """ last: Int ): UserContentEditConnection """ Check if the current viewer can delete this object. """ viewerCanDelete: Boolean! """ Can the current user mark this comment as an answer? """ viewerCanMarkAsAnswer: Boolean! """ Check if the current viewer can minimize this object. """ viewerCanMinimize: Boolean! """ Can user react to this subject """ viewerCanReact: Boolean! """ Can the current user unmark this comment as an answer? """ viewerCanUnmarkAsAnswer: Boolean! """ Check if the current viewer can update this object. """ viewerCanUpdate: Boolean! """ Reasons why the current viewer can not update this comment. """ viewerCannotUpdateReasons: [CommentCannotUpdateReason!]! """ Did the viewer author this comment. """ viewerDidAuthor: Boolean! } 

DiscussionCategory

字段
""" A category for discussions in a repository. """ type DiscussionCategory implements Node & RepositoryNode { """ Identifies the date and time when the object was created. """ createdAt: DateTime! """ A description of this category. """ description: String """ An emoji representing this category. """ emoji: String! """ This category's emoji rendered as HTML. """ emojiHTML: HTML! id: ID! """ Whether or not discussions in this category support choosing an answer with the markDiscussionCommentAsAnswer mutation. """ isAnswerable: Boolean! """ The name of this category. """ name: String! """ The repository associated with this node. """ repository: Repository! """ Identifies the date and time when the object was last updated. """ updatedAt: DateTime! } 

PinnedDiscussion

字段:
""" A Pinned discussion is a discussion pinned to a repository's index page. """ type PinnedDiscussion implements Node & RepositoryNode { """ Identifies the date and time when the object was created. """ createdAt: DateTime! """ Identifies the primary key from the database. """ databaseId: Int """ The discussion that was pinned. """ discussion: Discussion! """ Color stops of the chosen gradient """ gradientStopColors: [String!]! id: ID! """ Background texture pattern """ pattern: PinnedDiscussionPattern! """ The actor that pinned this discussion. """ pinnedBy: Actor! """ Preconfigured background gradient option """ preconfiguredGradient: PinnedDiscussionGradient """ The repository associated with this node. """ repository: Repository! """ Identifies the date and time when the object was last updated. """ updatedAt: DateTime! } 

PinnedDiscussionPattern

""" Preconfigured background patterns that may be used to style discussions pinned within a repository. """ enum PinnedDiscussionPattern { """ An upward-facing chevron pattern """ CHEVRON_UP """ A hollow dot pattern """ DOT """ A solid dot pattern """ DOT_FILL """ A heart pattern """ HEART_FILL """ A friendly octocat face pattern """ OCTOFACE """ A plus sign pattern """ PLUS } 

PinnedDiscussionGradient

""" Preconfigured gradients that may be used to style discussions pinned within a repository. """ enum PinnedDiscussionGradient { """ A gradient of blue to mint """ BLUE_MINT """ A gradient of blue to purple """ BLUE_PURPLE """ A gradient of pink to blue """ PINK_BLUE """ A gradient of purple to coral """ PURPLE_CORAL """ A gradient of red to orange """ RED_ORANGE } 

接口

RepositoryDiscussionAuthor

UserOrganization 类型实现。 注意:只有从 User 转换来的 Organization 才会有与之关联的讨论。

字段
""" Represents an author of discussions in repositories. """ interface RepositoryDiscussionAuthor { """ Discussions this user has started. """ repositoryDiscussions( """ Returns the elements in the list that come after the specified cursor. """ after: String """ Filter discussions to only those that have been answered or not. Defaults to including both answered and unanswered discussions. """ answered: Boolean = null """ Returns the elements in the list that come before the specified cursor. """ before: String """ Returns the first _n_ elements from the list. """ first: Int """ Returns the last _n_ elements from the list. """ last: Int """ Ordering options for discussions returned from the connection. """ orderBy: DiscussionOrder = {field: CREATED_AT, direction: DESC} """ Filter discussions to only those in a specific repository. """ repositoryId: ID ): DiscussionConnection! } 

RepositoryDiscussionCommentAuthor

还由 UserOrganization 类型实现。

字段
""" Represents an author of discussion comments in repositories. """ interface RepositoryDiscussionCommentAuthor { """ Discussion comments this user has authored. """ repositoryDiscussionComments( """ Returns the elements in the list that come after the specified cursor. """ after: String """ Returns the elements in the list that come before the specified cursor. """ before: String """ Returns the first _n_ elements from the list. """ first: Int """ Returns the last _n_ elements from the list. """ last: Int """ Filter discussion comments to only those that were marked as the answer """ onlyAnswers: Boolean = false """ Filter discussion comments to only those in a specific repository. """ repositoryId: ID ): DiscussionCommentConnection! } 

突变

这些突变遵循与 GraphQL API 中其他突变相同的实现模式。 每个突变都接受以突变命名的 Input 类型的单个参数,并返回包含指定字段的 Payload 类型。

例如,这是一个基本 createDiscussion 突变,将会创建一个新的讨论:

mutation { # input type: CreateDiscussionInput createDiscussion(input: {repositoryId: "1234", categoryId: "5678", body: "The body", title: "The title"}) { # response type: CreateDiscussionPayload discussion { id } } } 

createDiscussion

输入字段:

  • body: String! 新讨论的正文。
  • title: String! 新讨论的标题。
  • repositoryId: ID! 在其中创建讨论的存储库的 ID。
  • categoryId: ID! 此存储库中的 DiscussionCategory 的 ID。
  • clientMutationId: String 进行突变的客户端的唯一标识符。

返回类型字段:

  • clientMutationId: String 作为输入提供的唯一标识符。
  • discussion: Discussion 已创建的讨论。

updateDiscussion

输入字段:

  • discussionId: ID! 要更新的讨论的节点 ID。
  • body: String 讨论正文的新内容。
  • title: String 新的讨论标题。
  • categoryId: ID 要此讨论将更改为的同一存储库中的 DiscussionCategory 的节点 ID。
  • clientMutationId: String 进行突变的客户端的唯一标识符。

返回类型字段:

  • clientMutationId: String 作为输入提供的唯一标识符。
  • discussion: Discussion 已修改的讨论。

deleteDiscussion

输入字段:

  • id: ID! 要删除的讨论的节点 ID。
  • clientMutationId: String 进行突变的客户端的唯一标识符。

返回类型字段:

  • clientMutationId: String 作为输入提供的唯一标识符。
  • discussion: Discussion 已删除的讨论。

addDiscussionComment

输入字段:

  • body: String! 注释的内容。
  • discussionId: ID! 要注释的讨论的节点 ID。
  • replyToId: ID 要答复的讨论注释的节点 ID。 如果不存在,创建的评论将是顶层评论。
  • clientMutationId: String 进行突变的客户端的唯一标识符。

返回类型字段:

  • clientMutationId: String 作为输入提供的唯一标识符。
  • comment: DiscussionComment 已创建的讨论注释。

updateDiscussionComment

输入字段:

  • body: String! 注释正文的新内容。
  • commentId: ID! 要更新的讨论注释的节点 ID。
  • clientMutationId: String 进行突变的客户端的唯一标识符。

返回类型字段:

  • clientMutationId: String 作为输入提供的唯一标识符。
  • comment: DiscussionComment 已更新的讨论注释。

deleteDiscussionComment

输入字段:

  • id: ID! 要删除的讨论注释的节点 ID。
  • clientMutationId: String 进行突变的客户端的唯一标识符。

返回类型字段:

  • clientMutationId: String 作为输入提供的唯一标识符。
  • comment: DiscussionComment 已删除的讨论注释。

markDiscussionCommentAsAnswer

输入字段:

  • id: ID! 要标记为答案的讨论注释的节点 ID。
  • clientMutationId: String 进行突变的客户端的唯一标识符。

返回类型字段:

  • clientMutationId: String 作为输入提供的唯一标识符。
  • discussion: Discussion 包含所选注释的讨论。

unmarkDiscussionCommentAsAnswer

输入字段:

  • id: ID! 要取消标记为答案的讨论注释的节点 ID。
  • clientMutationId: String 进行突变的客户端的唯一标识符。

返回类型字段:

  • clientMutationId: String 作为输入提供的唯一标识符。
  • discussion: Discussion 包含未标记注释的讨论。

可以从顶层 search 字段返回讨论。 若要搜索讨论,请指定 typeDISCUSSIONSearchResultItemConnection 类型有一个 discussionCount 字段来报告返回的讨论数,并且 Discussion 类型已添加到 SearchResultItem 并集。 有关详细信息,请参阅 查询搜索讨论