Skip to main content
Solved

cant call query method from grapghql dataclass


karanrajagopalan1
Active

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?

Best answer by karanrajagopalan1

@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.

View original
Did this topic help you find an answer to your question?

4 replies

karanrajagopalan1
Active

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'})]

 


karanrajagopalan1
Active

-- fixed--


Dilini Fernando
Seasoned Practitioner
Forum|alt.badge.img+2
  • Seasoned Practitioner
  • 671 replies
  • December 21, 2023

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 


karanrajagopalan1
Active

@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


Cookie Policy

We use cookies to enhance and personalize your experience. If you accept you agree to our full cookie policy. Learn more about our cookies.

 
Cookie Settings