Repository navigation
Expand file tree
/
Copy pathUpdate-FabricGraphQLApi.ps1
More file actions
102 lines (83 loc) · 3.65 KB
/
Copy pathUpdate-FabricGraphQLApi.ps1
File metadata and controls
102 lines (83 loc) · 3.65 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
<#
.SYNOPSIS
Updates an existing GraphQL API in a specified Microsoft Fabric workspace.
.DESCRIPTION
Sends a PATCH request to the Microsoft Fabric API to update the specified GraphQL API's name and optionally its description within a workspace.
.PARAMETER WorkspaceId
The unique identifier of the workspace containing the GraphQL API.
.PARAMETER GraphQLApiId
The unique identifier of the GraphQL API to update.
.PARAMETER GraphQLApiName
The new display name for the GraphQL API.
.PARAMETER GraphQLApiDescription
An optional new description for the GraphQL API.
.EXAMPLE
Update-FabricGraphQLApi -WorkspaceId "workspace-12345" -GraphQLApiId "graphqlapi-67890" -GraphQLApiName "Updated API" -GraphQLApiDescription "Updated description"
Updates the GraphQL API with the specified ID in the given workspace with a new name and description.
.NOTES
- Requires `$FabricConfig` global configuration, including `BaseUrl` and `FabricHeaders`.
- Calls `Test-TokenExpired` to ensure token validity before making the API request.
Author: Tiago Balabuch
#>
function Update-FabricGraphQLApi {
[CmdletBinding(SupportsShouldProcess = $true, ConfirmImpact = 'Medium')]
param (
[Parameter(Mandatory = $true, ValueFromPipelineByPropertyName = $true)]
[ValidateNotNullOrEmpty()]
[string]$WorkspaceId,
[Parameter(Mandatory = $true, ValueFromPipelineByPropertyName = $true)]
[ValidateNotNullOrEmpty()]
[Alias('id')]
[string]$GraphQLApiId,
[Parameter(Mandatory = $false, ValueFromPipelineByPropertyName = $true)]
[ValidateNotNullOrEmpty()]
[ValidatePattern('^[a-zA-Z0-9_ ]*$')]
[Alias('DisplayName')]
[string]$GraphQLApiName,
[Parameter(Mandatory = $false, ValueFromPipelineByPropertyName = $true)]
[ValidateNotNullOrEmpty()]
[Alias('Description')]
[string]$GraphQLApiDescription
)
process {
try {
# Validate that at least one update parameter is provided
if (-not $GraphQLApiName -and -not $GraphQLApiDescription) {
Write-FabricLog -Message "At least one of GraphQLApiName or GraphQLApiDescription must be specified" -Level Error
return
}
# Validate authentication
Invoke-FabricAuthCheck -ThrowOnFailure
# Construct the API endpoint URI
$apiEndpointURI = New-FabricAPIUri -Resource 'workspaces' -WorkspaceId $WorkspaceId -Subresource 'GraphQLApis' -ItemId $GraphQLApiId
# Construct the request body
$body = @{}
if ($GraphQLApiName) {
$body.displayName = $GraphQLApiName
}
if ($GraphQLApiDescription) {
$body.description = $GraphQLApiDescription
}
# Convert the body to JSON
$bodyJson = Convert-FabricRequestBody -InputObject $body
if ($PSCmdlet.ShouldProcess("GraphQL API '$GraphQLApiId' in workspace '$WorkspaceId'", "Update")) {
# Make the API request
$apiParams = @{
BaseURI = $apiEndpointURI
Headers = $script:FabricAuthContext.FabricHeaders
Method = 'Patch'
Body = $bodyJson
}
$response = Invoke-FabricAPIRequest @apiParams
# Return the API response
Write-FabricLog -Message "GraphQL API '$GraphQLApiName' updated successfully!" -Level Host
$response
}
}
catch {
# Capture and log error details
$errorDetails = $_.Exception.Message
Write-FabricLog -Message "Failed to update GraphQL API. Error: $errorDetails" -Level Error
}
}
}