fix: sanitize git GraphQL query import errors

Closed
TI
4mo ago
+276-4

Problem

Git repository imports can fail while creating CoreGraphQLQuery nodes. When that happens, the SDK GraphQLError currently surfaces the full generated mutation, variables, location reprs, and traceback-heavy text in task logs. That makes a user/configuration error hard to scan and can expose implementation details that are not useful to operators.

Change

  • catch infrahub_sdk.exceptions.GraphQLError around GraphQL query creation during Git import
  • convert SDK validation output into a concise RepositoryConfigurationError that keeps the repository name, query name, and server validation message
  • strip raw GraphQL mutation text, variables, and SourceLocation reprs from the operator-facing error/log message
  • add regression coverage proving the sanitized error keeps the useful context without leaking the raw payload

Before / After

Before, the worker/task output could include the full CoreGraphQLQueryCreate mutation and SDK exception payload.

After, the task reports a focused message like:

Unable to import GraphQL query 'backbone_service' from repository 'opsmill-demo-edge-clean-message': Query is not valid: Cannot query field 'InfraBackBoneService' on type 'Query'.

Screenshot

Filtered task log showing the sanitized RepositoryConfigurationError after reproducing the Git import failure locally:

InfraHub task log showing sanitized RepositoryConfigurationError

Scope

This targets the Git integration path from #7498. It is related to the broader user-error logging cleanup in #4589, but intentionally does not attempt to change general API/GraphQL resolver logging in this PR.

Testing

  • uv run ruff check backend/infrahub/git/integrator.py backend/tests/component/git/test_graphql_query_import.py
  • uv run pytest backend/tests/component/git/test_graphql_query_import.py -q
  • local Docker verification against the InfraHub task UI with a failing Git GraphQL import

Addresses #7498. Related to #4589.