Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Codegen Payload Types (#512)
Browse files Browse the repository at this point in the history
* Codegen Payload Types

* lint fixes
rocktavious authored Jan 29, 2025
1 parent 98ae6c4 commit 0f21817
Showing 24 changed files with 466 additions and 311 deletions.
22 changes: 6 additions & 16 deletions actions.go
Original file line number Diff line number Diff line change
@@ -56,7 +56,7 @@ type CustomActionsTriggerDefinitionsConnection struct {

func (client *Client) CreateWebhookAction(input CustomActionsWebhookActionCreateInput) (*CustomActionsExternalAction, error) {
var m struct {
Payload struct {
Payload struct { // TODO: fix this
WebhookAction CustomActionsExternalAction
Errors []Error
} `graphql:"customActionsWebhookActionCreate(input: $input)"`
@@ -110,7 +110,7 @@ func (client *Client) ListCustomActions(variables *PayloadVariables) (*CustomAct

func (client *Client) UpdateWebhookAction(input CustomActionsWebhookActionUpdateInput) (*CustomActionsExternalAction, error) {
var m struct {
Payload struct {
Payload struct { // TODO: fix this
WebhookAction CustomActionsExternalAction
Errors []Error
} `graphql:"customActionsWebhookActionUpdate(input: $input)"`
@@ -124,9 +124,7 @@ func (client *Client) UpdateWebhookAction(input CustomActionsWebhookActionUpdate

func (client *Client) DeleteWebhookAction(input string) error {
var m struct {
Payload struct {
Errors []Error `graphql:"errors"`
} `graphql:"customActionsWebhookActionDelete(resource: $input)"`
Payload BasePayload `graphql:"customActionsWebhookActionDelete(resource: $input)"`
}
v := PayloadVariables{
"input": *NewIdentifier(input),
@@ -137,10 +135,7 @@ func (client *Client) DeleteWebhookAction(input string) error {

func (client *Client) CreateTriggerDefinition(input CustomActionsTriggerDefinitionCreateInput) (*CustomActionsTriggerDefinition, error) {
var m struct {
Payload struct {
TriggerDefinition CustomActionsTriggerDefinition
Errors []Error
} `graphql:"customActionsTriggerDefinitionCreate(input: $input)"`
Payload CustomActionsTriggerDefinitionCreatePayload `graphql:"customActionsTriggerDefinitionCreate(input: $input)"`
}
if input.AccessControl == nil {
input.AccessControl = &CustomActionsTriggerDefinitionAccessControlEnumEveryone
@@ -198,10 +193,7 @@ func (client *Client) ListTriggerDefinitions(variables *PayloadVariables) (*Cust

func (client *Client) UpdateTriggerDefinition(input CustomActionsTriggerDefinitionUpdateInput) (*CustomActionsTriggerDefinition, error) {
var m struct {
Payload struct {
TriggerDefinition CustomActionsTriggerDefinition
Errors []Error
} `graphql:"customActionsTriggerDefinitionUpdate(input: $input)"`
Payload CustomActionsTriggerDefinitionUpdatePayload `graphql:"customActionsTriggerDefinitionUpdate(input: $input)"`
}
v := PayloadVariables{
"input": input,
@@ -212,9 +204,7 @@ func (client *Client) UpdateTriggerDefinition(input CustomActionsTriggerDefiniti

func (client *Client) DeleteTriggerDefinition(input string) error {
var m struct {
Payload struct {
Errors []Error `graphql:"errors"`
} `graphql:"customActionsTriggerDefinitionDelete(resource: $input)"`
Payload BasePayload `graphql:"customActionsTriggerDefinitionDelete(resource: $input)"`
}
v := PayloadVariables{
"input": *NewIdentifier(input),
9 changes: 2 additions & 7 deletions alert_source.go
Original file line number Diff line number Diff line change
@@ -14,10 +14,7 @@ func NewAlertSource(kind AlertSourceTypeEnum, id string) *AlertSourceExternalIde

func (client *Client) CreateAlertSourceService(input AlertSourceServiceCreateInput) (*AlertSourceService, error) {
var m struct {
Payload struct {
AlertSourceService AlertSourceService
Errors []Error
} `graphql:"alertSourceServiceCreate(input: $input)"`
Payload AlertSourceServiceCreatePayload `graphql:"alertSourceServiceCreate(input: $input)"`
}
v := PayloadVariables{
"input": input,
@@ -56,9 +53,7 @@ func (client *Client) GetAlertSource(id ID) (*AlertSource, error) {

func (client *Client) DeleteAlertSourceService(id ID) error {
var m struct {
Payload struct {
Errors []Error
} `graphql:"alertSourceServiceDelete(input: $input)"`
Payload BasePayload `graphql:"alertSourceServiceDelete(input: $input)"`
}
v := PayloadVariables{
"input": AlertSourceDeleteInput{Id: id},
12 changes: 4 additions & 8 deletions aliases.go
Original file line number Diff line number Diff line change
@@ -61,11 +61,7 @@ func (client *Client) CreateAliases(ownerId ID, aliases []string) ([]string, err

func (client *Client) CreateAlias(input AliasCreateInput) ([]string, error) {
var m struct {
Payload struct {
Aliases []string
OwnerId string
Errors []Error
} `graphql:"aliasCreate(input: $input)"`
Payload AliasCreatePayload `graphql:"aliasCreate(input: $input)"`
}
v := PayloadVariables{
"input": input,
@@ -116,9 +112,9 @@ func (client *Client) DeleteAliases(aliasOwnerType AliasOwnerTypeEnum, aliases [

func (client *Client) DeleteAlias(input AliasDeleteInput) error {
var m struct {
Payload struct {
Alias string `graphql:"deletedAlias"`
Errors []Error
Payload struct { // TODO: we don't need this but removing it breaks alot of tests
Alias string `graphql:"deletedAlias"`
BasePayload
} `graphql:"aliasDelete(input: $input)"`
}
v := PayloadVariables{
16 changes: 5 additions & 11 deletions category.go
Original file line number Diff line number Diff line change
@@ -19,10 +19,7 @@ func (category *Category) Alias() string {

func (client *Client) CreateCategory(input CategoryCreateInput) (*Category, error) {
var m struct {
Payload struct {
Category Category
Errors []Error
} `graphql:"categoryCreate(input: $input)"`
Payload CategoryCreatePayload `graphql:"categoryCreate(input: $input)"`
}
v := PayloadVariables{
"input": input,
@@ -79,10 +76,7 @@ func (client *Client) ListCategories(variables *PayloadVariables) (*CategoryConn

func (client *Client) UpdateCategory(input CategoryUpdateInput) (*Category, error) {
var m struct {
Payload struct {
Category Category
Errors []Error
} `graphql:"categoryUpdate(input: $input)"`
Payload CategoryUpdatePayload `graphql:"categoryUpdate(input: $input)"`
}
v := PayloadVariables{
"input": input,
@@ -93,9 +87,9 @@ func (client *Client) UpdateCategory(input CategoryUpdateInput) (*Category, erro

func (client *Client) DeleteCategory(id ID) error {
var m struct {
Payload struct {
Id ID `graphql:"deletedCategoryId"`
Errors []Error
Payload struct { // TODO: we don't need this but removing it breaks alot of tests
Id ID `graphql:"deletedCategoryId"`
BasePayload
} `graphql:"categoryDelete(input: $input)"`
}
v := PayloadVariables{
10 changes: 1 addition & 9 deletions check.go
Original file line number Diff line number Diff line change
@@ -127,12 +127,6 @@ func NewCheckUpdateInputTypeOf[T any](checkUpdateInput CheckUpdateInput) *T {
return newCheck
}

// CheckResponsePayload encompasses CheckCreatePayload and CheckUpdatePayload into 1 struct
type CheckResponsePayload struct {
Check Check
Errors []Error
}

func (client *Client) CreateCheck(input any) (*Check, error) {
switch v := input.(type) {
case *CheckAlertSourceUsageCreateInput:
@@ -265,9 +259,7 @@ func (client *Client) UpdateCheck(input any) (*Check, error) {

func (client *Client) DeleteCheck(id ID) error {
var m struct {
Payload struct {
Errors []Error
} `graphql:"checkDelete(input: $input)"`
Payload BasePayload `graphql:"checkDelete(input: $input)"`
}
v := PayloadVariables{
"input": CheckDeleteInput{Id: RefOf(id)},
14 changes: 3 additions & 11 deletions component.go
Original file line number Diff line number Diff line change
@@ -16,10 +16,7 @@ type ComponentTypeConnection struct {

func (client *Client) CreateComponentType(input ComponentTypeInput) (*ComponentType, error) {
var m struct {
Payload struct {
ComponentType ComponentType
Errors []Error
} `graphql:"componentTypeCreate(input:$input)"`
Payload ComponentTypePayload `graphql:"componentTypeCreate(input:$input)"`
}
v := PayloadVariables{
"input": input,
@@ -83,10 +80,7 @@ func (client *Client) ListComponents(variables *PayloadVariables) (*ComponentCon

func (client *Client) UpdateComponentType(identifier string, input ComponentTypeInput) (*ComponentType, error) {
var m struct {
Payload struct {
ComponentType ComponentType
Errors []Error
} `graphql:"componentTypeUpdate(componentType:$target,input:$input)"`
Payload ComponentTypePayload `graphql:"componentTypeUpdate(componentType:$target,input:$input)"`
}
v := PayloadVariables{
"target": *NewIdentifier(identifier),
@@ -103,9 +97,7 @@ func (client *Client) UpdateComponent(input ComponentUpdateInput) (*Component, e

func (client *Client) DeleteComponentType(identifier string) error {
var d struct {
Payload struct {
Errors []Error `graphql:"errors"`
} `graphql:"componentTypeDelete(resource:$target)"`
Payload BasePayload `graphql:"componentTypeDelete(resource:$target)"`
}
v := PayloadVariables{
"target": *NewIdentifier(identifier),
11 changes: 3 additions & 8 deletions dependencies.go
Original file line number Diff line number Diff line change
@@ -35,16 +35,13 @@ type ServiceDependentsConnection struct {

func (client *Client) CreateServiceDependency(input ServiceDependencyCreateInput) (*ServiceDependency, error) {
var m struct {
Payload struct {
ServiceDependency *ServiceDependency
Errors []Error
} `graphql:"serviceDependencyCreate(inputV2: $input)"`
Payload ServiceDependencyPayload `graphql:"serviceDependencyCreate(inputV2: $input)"`
}
v := PayloadVariables{
"input": input,
}
err := client.Mutate(&m, v, WithName("ServiceDependencyCreate"))
return m.Payload.ServiceDependency, HandleErrors(err, m.Payload.Errors)
return &m.Payload.ServiceDependency, HandleErrors(err, m.Payload.Errors)
}

func (service *Service) GetDependencies(client *Client, variables *PayloadVariables) (*ServiceDependenciesConnection, error) {
@@ -115,9 +112,7 @@ func (service *Service) GetDependents(client *Client, variables *PayloadVariable

func (client *Client) DeleteServiceDependency(id ID) error {
var m struct {
Payload struct {
Errors []Error
} `graphql:"serviceDependencyDelete(input: $input)"`
Payload BasePayload `graphql:"serviceDependencyDelete(input: $input)"`
}
v := PayloadVariables{
"input": DeleteInput{Id: id},
5 changes: 1 addition & 4 deletions document.go
Original file line number Diff line number Diff line change
@@ -14,10 +14,7 @@ type ServiceDocumentContent struct {

func (client *Client) ServiceApiDocSettingsUpdate(service string, docPath string, docSource *ApiDocumentSourceEnum) (*Service, error) {
var m struct {
Payload struct {
Service Service
Errors []Error
} `graphql:"serviceApiDocSettingsUpdate(service: $service, apiDocumentPath: $docPath, preferredApiDocumentSource: $docSource)"`
Payload ServiceUpdatePayload `graphql:"serviceApiDocSettingsUpdate(service: $service, apiDocumentPath: $docPath, preferredApiDocumentSource: $docSource)"`
}
v := PayloadVariables{
"service": *NewIdentifier(service),
19 changes: 4 additions & 15 deletions domain.go
Original file line number Diff line number Diff line change
@@ -129,10 +129,7 @@ func (domainId *DomainId) ChildSystems(client *Client, variables *PayloadVariabl

func (domainId *DomainId) AssignSystem(client *Client, systems ...string) error {
var m struct {
Payload struct {
Domain Domain
Errors []Error
} `graphql:"domainChildAssign(domain:$domain, childSystems:$childSystems)"`
Payload DomainPayload `graphql:"domainChildAssign(domain:$domain, childSystems:$childSystems)"`
}
v := PayloadVariables{
"domain": *NewIdentifier(string(domainId.Id)),
@@ -144,10 +141,7 @@ func (domainId *DomainId) AssignSystem(client *Client, systems ...string) error

func (client *Client) CreateDomain(input DomainInput) (*Domain, error) {
var m struct {
Payload struct {
Domain Domain
Errors []Error
} `graphql:"domainCreate(input:$input)"`
Payload DomainPayload `graphql:"domainCreate(input:$input)"`
}
v := PayloadVariables{
"input": input,
@@ -196,10 +190,7 @@ func (client *Client) ListDomains(variables *PayloadVariables) (*DomainConnectio

func (client *Client) UpdateDomain(identifier string, input DomainInput) (*Domain, error) {
var m struct {
Payload struct {
Domain Domain
Errors []Error
} `graphql:"domainUpdate(domain:$domain,input:$input)"`
Payload DomainPayload `graphql:"domainUpdate(domain:$domain,input:$input)"`
}
v := PayloadVariables{
"domain": *NewIdentifier(identifier),
@@ -211,9 +202,7 @@ func (client *Client) UpdateDomain(identifier string, input DomainInput) (*Domai

func (client *Client) DeleteDomain(identifier string) error {
var d struct {
Payload struct {
Errors []Error `graphql:"errors"`
} `graphql:"domainDelete(resource: $input)"`
Payload BasePayload `graphql:"domainDelete(resource: $input)"`
}
v := PayloadVariables{
"input": *NewIdentifier(identifier),
12 changes: 3 additions & 9 deletions filters.go
Original file line number Diff line number Diff line change
@@ -191,10 +191,7 @@ func (filter *Filter) Alias() string {

func (client *Client) CreateFilter(input FilterCreateInput) (*Filter, error) {
var m struct {
Payload struct {
Filter Filter
Errors []Error
} `graphql:"filterCreate(input: $input)"`
Payload FilterCreatePayload `graphql:"filterCreate(input: $input)"`
}
v := PayloadVariables{
"input": input,
@@ -246,10 +243,7 @@ func (client *Client) ListFilters(variables *PayloadVariables) (*FilterConnectio

func (client *Client) UpdateFilter(input FilterUpdateInput) (*Filter, error) {
var m struct {
Payload struct {
Filter Filter
Errors []Error
} `graphql:"filterUpdate(input: $input)"`
Payload FilterUpdatePayload `graphql:"filterUpdate(input: $input)"`
}
v := PayloadVariables{
"input": input,
@@ -260,7 +254,7 @@ func (client *Client) UpdateFilter(input FilterUpdateInput) (*Filter, error) {

func (client *Client) DeleteFilter(id ID) error {
var m struct {
Payload struct {
Payload struct { // TODO: fix this
Id ID `graphql:"deletedId"`
Errors []Error
} `graphql:"filterDelete(input: $input)"`
18 changes: 5 additions & 13 deletions infra.go
Original file line number Diff line number Diff line change
@@ -142,17 +142,14 @@ func (client *Client) CreateInfrastructure(input InfraInput) (*InfrastructureRes
}
}
var m struct {
Payload struct {
InfrastructureResource InfrastructureResource
Warnings []Warning // TODO: handle warnings somehow
Errors []Error
} `graphql:"infrastructureResourceCreate(input: $input)"`
Payload InfrastructureResourcePayload `graphql:"infrastructureResourceCreate(input: $input)"`
}
v := PayloadVariables{
"input": i,
"all": true,
}
err := client.Mutate(&m, v, WithName("InfrastructureResourceCreate"))
// TODO: handle m.Payload.Warnings somehow
return &m.Payload.InfrastructureResource, HandleErrors(err, m.Payload.Errors)
}

@@ -241,26 +238,21 @@ func (client *Client) UpdateInfrastructure(identifier string, input InfraInput)
}
}
var m struct {
Payload struct {
InfrastructureResource InfrastructureResource
Warnings []Warning // TODO: handle warnings somehow
Errors []Error
} `graphql:"infrastructureResourceUpdate(infrastructureResource: $identifier, input: $input)"`
Payload InfrastructureResourcePayload `graphql:"infrastructureResourceUpdate(infrastructureResource: $identifier, input: $input)"`
}
v := PayloadVariables{
"identifier": *NewIdentifier(identifier),
"input": i,
"all": true,
}
err := client.Mutate(&m, v, WithName("InfrastructureResourceUpdate"))
// TODO: handle m.Payload.Warnings somehow
return &m.Payload.InfrastructureResource, HandleErrors(err, m.Payload.Errors)
}

func (client *Client) DeleteInfrastructure(identifier string) error {
var m struct {
Payload struct {
Errors []Error `graphql:"errors"`
} `graphql:"infrastructureResourceDelete(resource: $input)"`
Payload BasePayload `graphql:"infrastructureResourceDelete(resource: $input)"`
}
v := PayloadVariables{
"input": *NewIdentifier(identifier),
Loading

0 comments on commit 0f21817

Please sign in to comment.