GraphQL get attachment from comment

Amazing use-case. (as ever).

Essentially you aren’t missing anything. You need to make use of the attachment id that is returned in a follow on query. I am editing it here for focus; a template query for a particular Commit.

Query

query ($streamId: String!, $resources: [ResourceIdentifierInput]!) {
  comments(streamId: $streamId, resources: $resources, limit: 1000) {
    items {
      ...CommentFullInfo
    }
  }
}

fragment CommentFullInfo on Comment {
  id
  text {
    doc
    attachments {
      id
      fileName
      fileType
      fileSize
    }
  }
  data // for viewer position etc.
}

Variables

{
  "streamId": "{{ STREAM_ID }}",
  "resources": [
    {
      "resourceType": "commit",
      "resourceId": "{{ COMMIT_ID }}"
    }
  ]
}

Response

This returns something like:

{
  "data": {
    "comments": {
      "items": [
        {
          "id": "{{ COMMENT_ID }}",
          "text": {
            "doc": // comment stuff
            "attachments": [
              {
                "id": "{{ ATTACHMENT_ID }}",
                "fileName": "{{ FILE_NAME }} ",
                "fileType": "{{ FILE_TYPE }}",
                "fileSize": {{ BYTES }}
              }
            ]
          },
          "data": { // viewer stuff
          }
        }
      ]
    }
  }
}

With that and your own magical trickery you can then formulate into REST call(s) to the blob endpoint

GET: https://speckle.xyz/api/stream/{{ STREAM_ID }}/blob/{{ ATTACHMENT_ID }}

Obviously you get the comment content and the relative camera position and transform all of this to meaningful data for your reporting, database, app whatever.

4 Likes