Skip to main content
Solved

Is there any library available for graphQL validation in python?

  • 1 July 2024
  • 5 replies
  • 34 views

type Relationship @edge @view(space: "space-name", version: "1_1"){
    relationName: String!,
    relationType: RelationType,
    startTime: Timestamp,
    endTime: Timestamp
}

 

is there any library developed by cognite which will validate above kind of graphQL syntax also is it possible to check the values provided in graphQL ?

5 replies

Userlevel 3
Badge

Hi @Lnemade 

 

Thanks for reaching out!

When your are editing your data model in the Fusion UI the editor is validating that your input is valid GraphQL. Only when the definition is valid the data model can be published. When hitting the publish button the schema is applied this step will either go through successfully or be aborted with an error message explaining why the schema could not be applied.

 

There is no ongoing development of a library that will run validation externally, altough there have discussions around offering a form of dry-run functionality to have a non-comitting validation.

 

You might already have explored the option of building the schema through the rest api directly, allowing you to handle containers and views more explicitly. Depending on use-case this might be an option as well.

 

Regards,

 

Arild Eide

 

Hii @Arild Eide  , thanks for the quick response.

Actually we are not populating the model using cognite UI. We have written python script (using cognite sdk) to publish the model. Hence, we are looking for the library using which we can validate our graphQlL .

@Aditya Kotiyal @Arild Eide  Do we have any future plan for external library for validation of graphQL request,

If yes, then please let us know.

Regards,

Lokesh Nemade

Userlevel 2

Hi Lokesh,

Have you had a look at https://github.com/graphql-python/gql - specifically its validation functionality (documented at https://gql.readthedocs.io/en/latest/usage/validation.html ) which can be performed by using introspection of the  schema from the CDF GraphQL endpoint.

Note that even if this library performs validation against the GraphQL schema there may be other issues with the schema that prevent its deployment, such as limits on schema complexity or conflicts with reserved names (https://docs.cognite.com/cdf/dm/dm_reference/dm_limits_and_restrictions/) or more subtle issues that are discovered by the data modelling service such as indexes being incompatible with the data type they are applied to.

Hope this helps, best regards,

-AndersM

Userlevel 4
Badge +2

Hi @Lnemade,

We are following up to see whether you're satisfied with the responses you've received?

Userlevel 4
Badge +2

Hi @Lnemade,

I hope the issue has been resolved. I'm closing this topic for now. Please feel free to start a new post if you have any questions. 

Reply