Solved

cant call query method from grapghql dataclass

  • 19 December 2023
  • 4 replies
  • 59 views

I'm trying to use a graphql query in my python notebook. And I'm using this code snippet given in the sdk docs.

 

from cognite.client import CogniteClient
>>> c = CogniteClient()
>>> res = c.data_modeling.graphql.query(
... id=("mySpace", "myDataModel", "v1"),
... query="listThings { items { thingProperty } }",
... )

 

I dont see data_modeling.graphql.query() method available. I see the below error message.

 

AttributeError: 'DataModelingGraphQLAPI' object has no attribute 'query'

 

I'm using sdk version 7.5.1. How do I run my grapghql query?

icon

Best answer by karanrajagopalan1 21 December 2023, 12:06

View original

4 replies

Looks like recently this got fixed, from this PR- https://github.com/cognitedata/cognite-sdk-python/pull/1548. I have updated my SDK to the latest but still no go with fetching the data from the data model. my query looks like this
 

query MyQuery {
listCapacity {
items {
plant {
latitude
longitude
name
plantLocation {
name
}
}
timeSeries {
dataPoints(start: 1698793200000) {
value
timestamp
}
unit
metadata
}
}
}
}

Using the query as such returns the below result.

{'listCapacity': {'items': []}}

If i use the query like how it is mentioned in the sdk docs by trimming the initial part of the query `query MyQuery {`

I get the below error
 

cognite.client.exceptions.CogniteGraphQLError: [GraphQLErrorSpec(message=Invalid syntax with offending token 'listCapacity' at line 1 column 1, locations=[{'line': 1, 'column': 1}], extensions={'classification': 'InvalidSyntax'})]

 

-- fixed--

Userlevel 4
Badge +2

Hi @karanrajagopalan1,

We are glad to hear that you were able to resolve the issue. Could you please share the solution with us? It will help our community in the future if they face a similar problem.

Best regards
Dilini 

@Dilini Fernando  The primary issue was the sdk version. The version 7.5.1 didn’t have the method query() implemented. I guess it was included in the recent release (7.6) which i learnt from that pull request mentioned. Why I mentioned it didn’t work even after updating the sdk is kind of mystery, I suspect it could be a query formatting issue.

Reply