GraphQL get attachment from comment

Is there a query to get an attachment in a comment?

I have this comment in a stream with a photo attached.
The URL to the photo is: blob:https://speckle.xyz/31e1cd73-9d88-4339-b77b-0ae59061db07

I tried to retrieve the attached photo in the comment with the GraphQL explorer, but without success. Am I missing something?

EDIT: interesting project context

A project team is conducting on site inspections. They walk on site with an iPad with the Speckle viewer on it and add comments with photo’s as they go. They are exploring how to pull these comments and photo’s out of Speckle and process it further.

The query in the explorer:

query{
  comments(streamId:"bfeaba6bc7"){
    totalCount
    items {
      id
      #screenshot
      authorId
      archived
      resources{
        resourceId
        resourceType
      }
      text
      {
        doc
        attachments {
          id
          streamId
          userId
          fileName
          fileType
          fileHash
          fileSize
          uploadStatus
          uploadError
          createdAt
          __typename
        }
      }
    }
  }
}

The result:

{
  "data": {
    "comments": {
      "totalCount": 1,
      "items": [
        {
          "id": "2d1c4b5912",
          "authorId": "6ceeb10e3e",
          "archived": false,
          "resources": [
            {
              "resourceId": "7ebf79f270",
              "resourceType": "commit"
            }
          ],
          "text": {
            "doc": {
              "type": "doc",
              "content": [
                {
                  "type": "paragraph",
                  "content": [
                    {
                      "type": "text",
                      "text": "wow! what a hole"
                    }
                  ]
                }
              ]
            },
            "attachments": [
              {
                "id": "ddb62b90c7",
                "streamId": "bfeaba6bc7",
                "userId": "6ceeb10e3e",
                "fileName": "site inspection 04.jpg",
                "fileType": "jpg",
                "fileHash": "a42ff989ec4f1f702cc61381254a87ab",
                "fileSize": 82506,
                "uploadStatus": 1,
                "uploadError": null,
                "createdAt": "2022-11-04T11:31:08.036Z",
                "__typename": "BlobMetadata"
              }
            ]
          }
        }
      ]
    }
  }
}
1 Like

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

Thank you Jonathon for your clear and detailed reply! As always :slight_smile:
This should get the project team going.

2 Likes