Thanks to visit codestin.com
Credit goes to github.com

Skip to content

feature: Generate Pydantic models per GraphQL query #545

@dgarros

Description

@dgarros

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)

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions