GraphQL
The GraphQL interface is the main interface to interact with Infrahub. The GraphQL schema is automatically generated based on the core models and the user-defined schema models.
The endpoint to interact with the main branch is accessible at https://<host>/graphql.
To interact with a branch the URL must include the name of the branch, such as https://<host>/graphql/<branch_name>.
If you need to extract the current GraphQL schema in your environment you can issue an HTTP get request to:
https://<host>/schema.graphqlhttps://<host>/schema.graphql?branch=some-other-branch
GraphQL sandbox​
The GraphQL sandbox provides an interactive editor for exploring your schema and running operations against the selected branch. Open your account menu in the web interface and select GraphQL Sandbox.
The sandbox uses GraphiQL 6 and includes these tools:
- Query Builder: Select fields from the schema to build a query. This replaces the Explorer pane from earlier versions.
- Collections: Save operations for reuse in your browser. To store queries in Infrahub for use by Transformations or API clients, create stored queries.
- JSON, Tree, and Table response views: Choose how to inspect the returned data. For a query sent as a single request, the response header also shows its HTTP status, duration, and size.
- Settings: Adjust the editor's display settings.
For query syntax and mutation formats, see Queries and mutations.
Request headers and authentication​
The sandbox uses your signed-in session by default. If a request using the session token returns HTTP 401, the sandbox refreshes the token and retries the request. If the refresh fails, Infrahub redirects you to the login page.
Enter custom request headers in the Headers tab. An Authorization header entered there replaces the session token. For a bearer token, set its value to Bearer <token>.
The sandbox does not refresh a token supplied in an Authorization header. If that token expires or is rejected, update or remove the header before retrying.
Introduction to GraphQL videos​
This short demo shows how to use the GraphQL query interface to explore and read data from Infrahub. It walks through how to open the built-in GraphQL interface and run your first queries.
This video demonstrates how to use filters and relationships in GraphQL to find specific information, such as IP addresses for a particular device, using the Infrahub query interface.