-
Notifications
You must be signed in to change notification settings - Fork 6
Description
Component
infrahubctl CLI
Describe the Feature Request
Implement a way to generate typed models (e.g. using Pydantic) from arbitrary GraphQL queries, so responses can be checked / used as strongly typed objects rather than raw dicts.
infrahubctl graphql generate-return-types myquery.qgl
Describe the Use Case
Currently GraphQL query results are returned as raw dictionaries which makes it difficult to catch bugs if the query changes but not the code processing the query.
Ideally each query should have its own Pydantic models that will match exactly what the query is returning the user experience for the developer would be much better and it would be easier to catch errors in the IDE, overall it would make the code more maintainable and testable.
This would be especially useful for Python Transform, Checks and Generators that are heavily relying on a GraphQL query
Additional Information
Ideally the methods that are currently returning the data from GraphQL should be updated to support this new approach and be able to return the model directly instead of returning a current dictionary when provided to them.
- Python transform
- Check
- Generator
client.execute_graphql
data = await client.execute_graphql(query=query, return_type=MyQueryModel)