Skip to content

Commit

Permalink
Improve error handling for graphql
Browse files Browse the repository at this point in the history
  • Loading branch information
chris-peterson committed Sep 18, 2024
1 parent 2ce7574 commit 338a06c
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 11 deletions.
5 changes: 2 additions & 3 deletions src/GitlabCli/GitlabCli.psd1
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
@{
ModuleVersion = '1.118.1'
ModuleVersion = '1.118.2'

RequiredModules = @('powershell-yaml')

Expand Down Expand Up @@ -27,8 +27,7 @@
ExternalModuleDependencies = @('powershell-yaml')
ReleaseNotes =
@'
* bugfix for missing pipeline bridges
* add pagination for Get-GitlabJob
* improve handling of graphql errors
'@
}
}
Expand Down
19 changes: 11 additions & 8 deletions src/GitlabCli/GraphQL.psm1
Original file line number Diff line number Diff line change
@@ -1,22 +1,25 @@
# https://docs.gitlab.com/ee/api/graphql/
function Invoke-GitlabGraphQL {
[CmdletBinding(SupportsShouldProcess)]
param(
[Parameter(Position=0, Mandatory=$true)]
[Parameter(Position=0, Mandatory)]
[string]
$Query,

[Parameter()]
[string]
$SiteUrl,

[Parameter()]
[switch]
$WhatIf
$SiteUrl
)

$Body = @{
query = $Query
}

Invoke-GitlabApi POST 'graphql' -Api '' -Body $Body -SiteUrl $SiteUrl -WhatIf:$WhatIf | Select-Object -ExpandProperty data | New-WrapperObject
if ($PSCmdlet.ShouldProcess("graphql query", "$($Body | ConvertTo-Json -Depth 100)")) {
$Result = Invoke-GitlabApi POST 'graphql' -Api '' -Body $Body -SiteUrl $SiteUrl
if ($Result.data) {
$Result.data | New-WrapperObject
} else {
throw "GraphQL query ($Query) failed, result: $($Result | ConvertTo-Json -Depth 100)"
}
}
}

0 comments on commit 338a06c

Please sign in to comment.