Stored queries
Infrahub can store GraphQL queries in the database to simplify execution and associate them with other internal objects such as Transformations.
Stored GraphQL queries in the database​
The GraphQLQuery model has been designed to store a GraphQL query in order to simplify its execution and to associate it with other internal objects like Transformation.
A GraphQLQuery object can be created via the web interface, the API or it can be imported from a Git repository.
Every time a GraphQLQuery is created or updated, the content of the query will be analyzed to:
- Ensure the query is valid and compatible with the schema.
- Extract some information about the query itself (see below).
Information extracted from the query​
- Type of operations present in the Query [Query, Mutation, Subscription]
- Variables accepted by the query
- Depth, number of nested levels in the query
- Height, total number of fields requested in the query
- List of Infrahub models referenced in the query
Import from a Git repository​
GraphQL queries could be defined in file(s) with a .gql extension in a remote repository. Then queries must also be explicitly identified in the .infrahub.yml file under queries.
More details on the .infrahub.yml file format can be found in .infrahub.yml topic.
Executing stored GraphQL queries​
Stored GraphQL queries can be executed by using the /api/query/{query_id} REST API endpoint. The {query_id} can be the name or the id of the GraphQLQuery node in the database. More information can be found in the Swagger documentation.