Skip to content

Handle GraphQL partial errors gracefully in Invoke-GitHubGraphQLQuery #557

@MariusStorhaug

Description

Request

Problem: Invoke-GitHubGraphQLQuery throws a terminating error whenever the GraphQL response contains an errors field, even when valid data is also returned. Per the GraphQL specification, a response can contain both data and errors (partial success), and clients should return the data while surfacing the errors as warnings.

Context

When querying fields that may be unavailable for some repositories (e.g., repositoryCustomPropertyValues on repos where the caller lacks permissions), the GraphQL API returns both valid data and errors. The current implementation discards all data and throws, causing unnecessary failures for callers that could use the partial data.

Acceptance criteria

  • When GraphQL returns both data and errors, the function emits Write-Warning for each error and returns data
  • When GraphQL returns only errors (no data), the function throws a terminating error as before
  • Warning messages include the error type, message, and path for debugging

Technical decisions

Approach: Check for $null -ne $graphQLResponse.data when errors are present. If data exists, treat as partial success; otherwise treat as full failure.

Warning format: Each partial error emits a separate Write-Warning with type, message, and path. Full failure errors include the full serialized error object for debugging.

Backward compatibility: Full-failure behavior is unchanged. Partial-success is new behavior — previously these would have thrown, so callers that relied on the error will now get data plus warnings instead. This is a net improvement.


Implementation plan

Core changes

  • Update Invoke-GitHubGraphQLQuery error handling block in src/functions/public/API/Invoke-GitHubGraphQLQuery.ps1
  • Add partial success branch: when $graphQLResponse.data is not null, emit Write-Warning for each error and continue
  • Keep full failure branch: when no data is returned, throw terminating error with detailed error messages

References

Metadata

Metadata

Labels

Type

No type

Projects

Status

Todo

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions