Skip to main content

Hi Everyone,
I need to create query like it is creating on cognite UI’s  like 
 


 

{
"listEntity": {
"with": {
"0": {
"limit": 50,
"nodes": {
"filter": {
"and": a
{
"matchAll": {}
},
{
"hasData": a
{
"type": "view",
"space": "slb-pdm-dm-governed",
"externalId": "Entity",
"version": "1_7"
}
]
},
{
"or": "
{
"and": a
{
"nested": {
"scope": o
"slb-pdm-dm-governed",
"Entity/1_7",
"parent"
],
"filter": {
"in": {
"property": r
"node",
"externalId"
],
"values": u
"1234"

]
}
}
}
},

}
]
}
]
}
]
}
}
},
"0_2": {
"limit": 10000,
"nodes": {
"from": "0",
"through": {
"source": {
"type": "view",
"space": "slb-pdm-dm-governed",
"externalId": "Entity",
"version": "1_7"
},
"identifier": "parent"
},
"direction": "outwards",
"filter": {
"and": a
{
"matchAll": {}
},
{
"hasData": a
{
"type": "view",
"space": "slb-pdm-dm-governed",
"externalId": "Entity",
"version": "1_7"
}
]
}
]
}
}
}
},
"select": {
"0": {
"sources": c
{
"source": {
"type": "view",
"space": "slb-pdm-dm-governed",
"externalId": "Entity",
"version": "1_7"
},
"properties": i
"location",
"entityType",
"parent"
]
}
]
},
"0_2": {
"sources": c
{
"source": {
"type": "view",
"space": "slb-pdm-dm-governed",
"externalId": "Entity",
"version": "1_7"
},
"properties": i
"location",
"entityType",
"parent"
]
}
]
}
},
"includeTyping": true
}
}
}
}

The same we need to create it from SDK method but we couldn’t find any method to create same query rather we have created query like below using sdk which fetched first all data of entity then there nested veiw, not like above query which fetches only required data.
Query from sdk

{
"with": {
"Entity": {
"nodes": {
"filter": {
"hasData": a
{
"type": "view",
"space": "slb-pdm-dm-governed",
"externalId": "Entity",
"version": "1_7"
}
]
},
"chain_to": "destination",
"direction": "outwards"
},
"limit": 10000
},
"parent.Entity": {
"nodes": {
"from": "Entity",
"filter": {
"and":
{
"hasData": a
{
"type": "view",
"space": "slb-pdm-dm-governed",
"externalId": "Entity",
"version": "1_7"
}
]
},
{
"in": {
"property": o
"node",
"externalId"
],
"values": v
"1234"
]
}
}
]
},
"through": {
"source": {
"space": "slb-pdm-dm-governed",
"external_id": "Entity",
"version": "1_7",
"type": "view"
},
"identifier": "parent"
},
"chain_to": "destination",
"direction": "outwards"
},
"limit": 10000
}
},
"select": {
"Entity": {
"sources": o
{
"source": {
"space": "slb-pdm-dm-governed",
"external_id": "Entity",
"version": "1_7",
"type": "view"
},
"properties": e
"name",
"parent"
]
}
]
},
"parent.Entity": {
"sources": o
{
"source": {
"space": "slb-pdm-dm-governed",
"external_id": "Entity",
"version": "1_7",
"type": "view"
},
"properties": e
"name"
]
}
]
}
},
"cursors": {
"Entity": "Z0FBQUFBQm5VVWJadTBGeTlGdVN4MXlRa0N4b3BEaGhJMTdEMmhmTzVQbjU5YVFMWUFtUUhncjlVTFBOOGxpQnYyS3BYMlZRcGR1SVk0TjJLWkc5eVVSdGVFYlB2NF9lU3FqdWZiUkxUYUtDZXhxYUF4N0Nac3d6d2g3SkhOeDhXcE1ZM3BsRUd4cG1fd01SalFPbEk0dGtjZ1dMdHJVVEQ2dGpvVzY3ZTdFQ0pxSlhxRFVFbVlldk51SktOMEhFM3FGdm1YQ2hIY293TTQ2eXRIUkxSckpCbTZfTWJOaXFIemYwRGZINzlLQV9vdk1PMGZlc1FidzR2aXlVWk5TenFhXzEwSVRsSXg0MA==",
"parent.Entity": "Z0FBQUFBQm5VVWJaYjgzTjBLNFhhckNIZmFEREJIakR3bXp3eDJmNnBVY2NiWkFDS0xBR3JlbTNiQkpfVk5XY2ltSFl2Z2UyRWtBQVpGdDZQdUczOXRkdzdsN0tXLTBsdlRnMnhldXpFdGxLNzVENFVicUM3NVlxeVpUX0RLYk9ubUJwejJ6dDFtZXZDT0tMOVhTSW05blBQZ2JSR25lX1hHamxpUmFJWXdwUTdHU3d6SnA5ZGRneVdtYzZWVHhUVzVQTS1FTS1sdGwtSlZhR29QSW1xcHNlblFPeU5aRzhQeHdTOXNXLTlWaWZkUEZzYm5nU0hDd0N1OGJvWTB4amg3ZnZVTE5hYWM5Nw=="
}
}


Please suggest a way to create query like Cognite.

@Shweta I will check on this with the engineering team and get back to you.


@Mithila Jayalath  Okay sure, thank you. Please let me know.


One clarifying question from me, you specifically want to use client.data_modeling.instances.query(...)? Or can you adapt the GraphQL and use client.data_modeling.graphql.query(...) instead?


Thank you ​@Håkon V. Treider for question, 
@Neerajkumar Bhatewara if you can suggest what will be the suitable option.


Hello ​@Håkon V. Treider ,
We were recommended by Cognite earlier to use the instances query for the performance reasons. As a result, we are using the same as against graphql.query or graphql endpoint.

So to answer your query we want to use the instances.query as of now.

On the sides, what is recommended option in general out of the two and the differences?

 

Regards,
Neeraj B


I agree with that recommendation. Using the GQL endpoints are fine for UIs and similar, where a small-ish subset is used or shown to the user, while instances/query should be used when dealing with larger amounts of data, e.g. like a background worker.

By looking at your GraphQL query, is it correct to assume that Entity extends CogniteAsset? And that you are trying to list out sub-assets (or sub-entities) below a list of certain parents (given by the in-filter)?


If the answer to the above question is yes, I think a simpler way than following edges is to just filter nodes using the “equals” filter on parent - or in your case, using the “in” filter


Reply