Skip to main content

Overview

The Collaboration API provides real-time collaboration features for AFFiNE, including comments, mentions, notifications, and workspace sharing capabilities.

Comments

Get Comments

Retrieve comments for a specific document with pagination.
query GetComments($workspaceId: String!, $docId: String!, $pagination: PaginationInput!) {
  workspace(id: $workspaceId) {
    comments(docId: $docId, pagination: $pagination) {
      edges {
        cursor
        node {
          id
          content
          resolved
          createdAt
          updatedAt
          user {
            id
            name
            avatarUrl
          }
          replies {
            id
            content
            createdAt
            updatedAt
            user {
              id
              name
              avatarUrl
            }
          }
        }
      }
      pageInfo {
        hasNextPage
        hasPreviousPage
        startCursor
        endCursor
      }
      totalCount
    }
  }
}
docId
String!
required
The document ID to retrieve comments for
pagination
PaginationInput!
required
Pagination parameters for the comment list

Get Comment Changes

Retrieve recent comment changes (updates, deletions) for a document.
query GetCommentChanges($workspaceId: String!, $docId: String!, $pagination: PaginationInput!) {
  workspace(id: $workspaceId) {
    commentChanges(docId: $docId, pagination: $pagination) {
      edges {
        cursor
        node {
          id
          commentId
          action
          item
        }
      }
      pageInfo {
        hasNextPage
        endCursor
      }
      totalCount
    }
  }
}
action
CommentChangeAction!
The type of change: update or delete

Create Comment

Add a new comment to a document.
mutation CreateComment($input: CommentCreateInput!) {
  createComment(input: $input) {
    id
    content
    resolved
    createdAt
    user {
      id
      name
      avatarUrl
    }
  }
}
input
CommentCreateInput!
required

Update Comment

Edit an existing comment’s content.
mutation UpdateComment($input: CommentUpdateInput!) {
  updateComment(input: $input)
}

Resolve Comment

Mark a comment as resolved or unresolved.
mutation ResolveComment($input: CommentResolveInput!) {
  resolveComment(input: $input)
}

Delete Comment

Remove a comment from a document.
mutation DeleteComment($id: String!) {
  deleteComment(id: $id)
}

Replies

Create Reply

Add a reply to an existing comment.
mutation CreateReply($input: ReplyCreateInput!) {
  createReply(input: $input) {
    id
    commentId
    content
    createdAt
    user {
      id
      name
      avatarUrl
    }
  }
}

Update Reply

Edit a reply’s content.
mutation UpdateReply($input: ReplyUpdateInput!) {
  updateReply(input: $input)
}

Delete Reply

Remove a reply from a comment.
mutation DeleteReply($id: String!) {
  deleteReply(id: $id)
}

Mentions

Mention User

Mention a user in a document to send them a notification.
mutation MentionUser($input: MentionInput!) {
  mentionUser(input: $input)
}
input
MentionInput!
required
Users can only mention other members who have access to the workspace.

Notifications

Get Notifications

Retrieve notifications for the current user.
query GetNotifications($pagination: PaginationInput!) {
  currentUser {
    notifications(pagination: $pagination) {
      edges {
        cursor
        node {
          id
          type
          level
          read
          createdAt
          updatedAt
          body
        }
      }
      pageInfo {
        hasNextPage
        endCursor
      }
      totalCount
    }
  }
}

Get Notification Count

Get the count of unread notifications.
query GetNotificationCount {
  currentUser {
    notificationCount
  }
}

Mark Notification as Read

Mark a specific notification as read.
mutation ReadNotification($id: String!) {
  readNotification(id: $id)
}

Mark All Notifications as Read

Mark all notifications as read for the current user.
mutation ReadAllNotifications {
  readAllNotifications
}

Type Definitions

CommentObjectType

id
ID!
Unique comment identifier
content
JSONObject!
Comment content in ProseMirror JSON format
resolved
Boolean!
Whether the comment is marked as resolved
createdAt
DateTime!
Comment creation timestamp
updatedAt
DateTime!
Last update timestamp
user
PublicUserType!
The user who created the comment
replies
[ReplyObjectType!]!
Array of replies to this comment

ReplyObjectType

id
ID!
Unique reply identifier
commentId
ID!
Parent comment ID
content
JSONObject!
Reply content in ProseMirror JSON format
createdAt
DateTime!
Reply creation timestamp
updatedAt
DateTime!
Last update timestamp
user
PublicUserType!
The user who created the reply

NotificationType Enum

Types of notifications:
  • Mention - User was mentioned in a document
  • Comment - New comment on a document
  • CommentMention - User was mentioned in a comment
  • Invitation - Workspace invitation received
  • InvitationAccepted - Invitation was accepted
  • InvitationBlocked - Invitation was blocked
  • InvitationRejected - Invitation was rejected
  • InvitationReviewRequest - Review request for invitation
  • InvitationReviewApproved - Invitation review approved
  • InvitationReviewDeclined - Invitation review declined

NotificationLevel Enum

Notification priority levels:
  • None - No notification
  • Min - Minimal priority
  • Low - Low priority
  • Default - Normal priority
  • High - High priority

Error Handling

{
  "errors": [{
    "message": "COMMENT_NOT_FOUND",
    "extensions": {
      "code": "COMMENT_NOT_FOUND"
    }
  }]
}
The requested comment does not exist.