GraphQL children() select capabilities

I have the following GraphQL query, which i right now use to query drawings in my Revit project:

query ($stream_id: String!, $object_id: String!,  $myQuery: [JSONObject!]) {
  stream(id: $stream_id) {
    id
    name
    object(id: $object_id) {
      id
      children(query: $myQuery, limit:1) {
        cursor
        totalCount
        objects {
          data
        }
      }
    }
  }
}

and the following query variables:

{
  "stream_id":"some-id",
  "object_id":"some-id",
  "myQuery": [
    {
      "field": "category",
      "value": "Sheets",
      "operator": "="
    }
  ]
}

This gives me the following result:

{
  "data": {
    "stream": {
      "id": "some-id",
      "name": "Project name",
      "object": {
        "id": "some-id",
        "children": {
          "cursor": "eyJmaWVsZCI6ImlkIiwib3BlcmF0b3IiOiI+IiwidmFsdWUiOiIwMzc0Y2I0YjM1MzAwYTRjM2YwYzU1NGNiMmRkNWJiNSJ9",
          "totalCount": 92,
          "objects": [
            {
              "data": {
                "id": "0374cb4b35300a4c3f0c554cb2dd5bb5",
                "name": null,
                "units": "mm",
                "category": "Sheets",
                "elementId": "3251288",
                "worksetId": "19770",
                "parameters": {
                  "id": "570949903beedf362097150913b35731",
                  "EDITED_BY": {
                    "id": "306def54fbcd9c5dff9b81f269656c85",
                    "name": "Edited by",
                    "units": null,
                    "value": "",
                    "isShared": false,
                    "isReadOnly": true,
                    "speckle_type": "Objects.BuiltElements.Revit.Parameter",
                    "applicationId": null,
                    "applicationUnit": null,
                    "isTypeParameter": false,
                    "totalChildrenCount": 0,
                    "applicationUnitType": null,
                    "applicationInternalName": "EDITED_BY"
                  },
                  "VIEW_TYPE": {
                    "id": "b75ecdcb71cf0b31966041437dd9eeb0",
                    "name": "Family and Type",
                    "units": null,
                    "value": "Sheets",
                    "isShared": false,
                    "isReadOnly": true,
                    "speckle_type": "Objects.BuiltElements.Revit.Parameter",
                    "applicationId": null,
                    "applicationUnit": null,
                    "isTypeParameter": false,
                    "totalChildrenCount": 0,
                    "applicationUnitType": null,
                    "applicationInternalName": "VIEW_TYPE"
                  },
                  ...
                },
                "speckle_type": "Objects.BuiltElements.View",
                "applicationId": "7baecc91-890f-4376-bafd-4e4918105264-00317a7d",
                "renderMaterial": null,
                "builtInCategory": "OST_Sheets",
                "isRevitLinkedModel": false,
                "materialQuantities": [],
                "totalChildrenCount": 0,
                "revitLinkedModelPath": "some-link"
              }
            }
          ]
        }
      }
    }
  }
}

I am only interested in the value and name inside of each parameter, therefore i was hoping to be able to do this select statement in the children query, so that i can recieve all the parameters in the query, but only the value and name in each of them:

children(query: $myQuery, select:["parameters.*.value", "parameters.*.name"], limit:1) { ... }

This does not work… Is there a solution for this? And are the capabilities of the select statement documented somewhere?

Hey Olavur,

Did you try the querie only on the Sheets category? Can you testes if it works for another category?

I test quickly on other projects and it works on my side. Are you able to share your stream with me to have a look? You can pm directly. If not possible I will need to figure out another way to reproduce the problem.

here you can also find the documentation: GraphQL API | Speckle Docs

1 Like

Unfortunately, the * in the select field is a special case that morphs the query to return a flat list containing both the Sheet and all the Parameters objects.

You have already used the optimal querying solution to return the sheets using the query filter.

Because Revit parameters are not detached objects, there is no advantage to querying first to get the sheet IDs and then looping through these to make subsequent select queries.

If you add the select property filter to the objects’ data object, they will be in some reliable order.

A lot will depend on where / how you are processing the return, but each Sheet object will be followed by the 40 or so sheet parameter objects so that you can stitch them back together deterministically, It is not worth it not to make the single query and process that - this is already a very minimal return relative to a lot of Speckle data.

Firstly! I want to correct; the limit:1 is not supposed to be there, i ofcourse want to query all drawings, but only the name and value of the parameters of these drawings.

I though that select:["parameters.*.value", "parameters.*.name"] did not work, but it kinda does work, but not in my favour. I believe it works as you explained Jonathan, it returns a flat list of all the parameters, not grouped by drawing:

{
  "data": {
    "stream": {
      "id": "some-id",
      "name": "Project name",
      "object": {
        "id": "some-id",
        "children": {
          "cursor": "eyJmaWVsZCI6ImlkIiwib3BlcmF0b3IiOiI+IiwidmFsdWUiOm51bGx9",
          "totalCount": 4232,
          "objects": [

            ...

            {
              "data": {
                "parameters": {
                  "*": {
                    "value": "STA_K08.02_120_H1_E0_N102",
                    "name": "Sheet Number"
                  }
                },
                "id": null
              }
            },
            {
              "data": {
                "parameters": {
                  "*": {
                    "value": "SBR",
                    "name": "Drawn By"
                  }
                },
                "id": null
              }
            },

            ...

            {
              "data": {
                "parameters": {
                  "*": {
                    "value": "STA_K08.02_105_H1_E0_N100",
                    "name": "Sheet Number"
                  }
                },
                "id": null
              }
            },
            {
              "data": {
                "parameters": {
                  "*": {
                    "value": "ONO",
                    "name": "Drawn By"
                  }
                },
                "id": null
              }
            },

            ...

          ]
        }
      }
    }
  }
}

I was hoping to get a result that looks more like this:

{
  "data": {
    "parameters": [
      {
        "value": "STA_K08.02_120_H1_E0_N102",
        "name": "Sheet Number"
      },
      {
        "value": "SBR",
        "name": "Drawn By"
      }
    ],
  }
},
{
  "data": {
    "parameters": [
      {
        "value": "STA_K08.02_105_H1_E0_N100",
        "name": "Sheet Number"
      },
      {
        "value": "ONO",
        "name": "Drawn By"
      }
    ],
  }
},

But if this is not possible, then i’ll settle with querying all the properties of the parameters, or i’ll write a script where i automatically generate all the ["parameters.EDITED_BY.name", "parameters.EDITED_BY.value", "parameters.SHEET_NAME.name", ... ] keys for the select query. Otherwise, thank you for a quick answer!

1 Like

If you are writing a script, you will be better off just processing the data received into the shape you want.

Crafting a second query with the nominated hardcoded parameter names will be more expensive and from memory I think it doesn’t even work properly - I left it as an overnight note to myself to figure out why not.

1 Like