GraphQL : How to view data per Commit

Hi,

using the following query in GraphQL I can view only high level data

query{
  user {
      name,
      streams {
         totalCount, 
         items {
               id
               name
               commits { 
                  cursor, 
                  totalCount, 
                  items  {
                         id, 
                         message,
                         totalChildrenCount,
                         referencedObject
                         }
                      }
                  
                }
             }
      }

such as

{
  "data": {
    "user": {
      "name": "Dimitrios Ververidis",
      "streams": {
        "totalCount": 4,
        "items": [
          {
            "id": "93e286e781",
            "name": "PrismArch X",
            "commits": {
              "cursor": "2021-04-12T07:10:36.740Z",
              "totalCount": 2,
              "items": [
                {
                  "id": "918f262155",
                  "message": "2nd commit",
                  "totalChildrenCount": 13
                },
                {
                  "id": "f5b043a967",
                  "message": "wpoden box",
                  "totalChildrenCount": 13
                }
              ]
            }
          },
          {
            "id": "2ed9644a7c",
            "name": "Speckle test",
            "commits": {
              "cursor": "2021-04-09T10:35:04.885Z",
              .....

How do I view the “Children” per commit “Item” ? Now I only see the number of children

Best,
Dimitrios

Good question! Commits per se just point at a given object. Their id is stored under the referencedObject field:

Once you have that object’s id, you can retrieve it using the object route that’s straight from under a stream.

less relevant info We've disallowed getting the object straight from there to avoid n+1 problems. I'm thinking of even moving the object node from under the stream itself later down the line.

Here’s how to do it now:

Under an object’s data field you have its raw json representation. Under it’s children field, you actually get its children, and a cursor, which you can pass in the next query to get the next set of elements.

The children node accepts extra query parameters which you can use to filter out and select what you get out too. I need to document this properly, but the tests in the server will give you an idea for now in which way to go.


A good example of how this queries are used is the object explorer component in the frontend.

Basically, you don’t retrieve the first object, but you keep digging into it on user interaction.

Nevertheless, if you don’t care, and want the whole object together with all its sub children, you can just stream it from a REST endpoint exposed by the server for this purpose. It’s formatted like this: serverUrl/objects/streamId/objectId; for example: https://speckle.xyz/objects/50778617a4/01b0d9061d12cafcc31f5b619b244bb3 (take care, it’s a big response).

2 Likes

I confirm that everything above works fine !!! Thanks.

1 Like