GraphQL query - getting subfields from referenced objects

Hi all,

Found this very useful post when I was trying to get a graphQL query to work, which has got me most of the way there, but I’m struggling with the last bit.

I’m querying a Civil3d model pushed from the new connectors to find objects with speckle_type=…CivilBaseline. From those objects, One bit of data I need is the alignment name, which I believe I should be able to select with “alignment.name” like this:

query($myQuery: [JSONObject!]) {
  project(id: "XXX") {
    object(id: "XXX") {
      id
      children(query: $myQuery select: ["alignment.name"]) {
        totalCount
        objects {
	      data
        }
      }
    }
  }
}

{
  "myQuery": [
    {
      "field": "speckle_type",
      "value": "Objects.BuiltElements.Civil.CivilBaseline",
      "operator": "="
    }
  ]
}

But these are always coming back as null. Is this because the alignment is a referenced object? If I just select “alignment” in the query above, the response is:

{
  "data": {
    "project": {
      "object": {
        "id": "XXX",
        "children": {
          "totalCount": 10,
          "objects": [
            {
              "data": {
                "alignment": {
                  "referencedId": "XXX",
                  "speckle_type": "reference"
                },
                "id": XXX"
              }
            },

If the referenced object is the problem - what’s the correct way to construct the query to get the alignment.name?

Hey @m.turner ,

You’re seeing references because those properties / objects are detached. You can read more about what that means here.

If you’re writing JS you can use our object-loader library that takes care of pulling all objects and reconstructing the tree (we have SDKs for C# and Python too). Otherwise you’ll need to make another GQL call to pull that specific object.

query Object($objectId: String!, $projectId: String!) {
  project(id: $projectId) {
    object(id: $objectId) {
      
    }
  }
}

Thanks @teocomi! I meant detached when said about a reference object. We were trying to avoid pulling the whole object because it’s very large, but we can make another series of GQL queries to get the specific data we need. Thanks again!

1 Like

@m.turner - I’m guessing this is on your own server. Is there a link to a model you can share?

It is indeed on our own server. Afraid I can’t share a specific model, but I can say that it was a civil3d corridor. Looking at the total object size in memory it was over 800mb, nearly all of which was the ‘baselines’ bit.

It’s no problem for us to go and fetch the bits of the detached objects that we need in separate calls, just wanted to check there wasn’t some trick I was missing to do it in a single shot.

There may be but I don’t have access to a suitable demonstration model right now to double check.