Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Codegen Payload Types #512

Merged
merged 2 commits into from
Jan 29, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 6 additions & 16 deletions actions.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All the "TODO" are there for future self's when we come back around. Unfortunately switching these inline structs to the generated payload stucts requires test changes that i'm not willing to take on right now. So i've just noted all the places where we need to fix for the future.

WebhookAction CustomActionsExternalAction
Errors []Error
} `graphql:"customActionsWebhookActionCreate(input: $input)"`
Expand Down Expand Up @@ -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)"`
Expand All @@ -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),
Expand All @@ -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
Expand Down Expand Up @@ -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,
Expand All @@ -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),
Expand Down
9 changes: 2 additions & 7 deletions alert_source.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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},
Expand Down
12 changes: 4 additions & 8 deletions aliases.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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{
Expand Down
16 changes: 5 additions & 11 deletions category.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand All @@ -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{
Expand Down
10 changes: 1 addition & 9 deletions check.go
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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)},
Expand Down
14 changes: 3 additions & 11 deletions component.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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),
Expand All @@ -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),
Expand Down
11 changes: 3 additions & 8 deletions dependencies.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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},
Expand Down
5 changes: 1 addition & 4 deletions document.go
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down
19 changes: 4 additions & 15 deletions domain.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)),
Expand All @@ -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,
Expand Down Expand Up @@ -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),
Expand All @@ -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),
Expand Down
12 changes: 3 additions & 9 deletions filters.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand All @@ -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)"`
Expand Down
18 changes: 5 additions & 13 deletions infra.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand Down Expand Up @@ -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),
Expand Down
Loading
Loading