Skip to content

Commit

Permalink
Codegen Payload Types
Browse files Browse the repository at this point in the history
  • Loading branch information
rocktavious committed Jan 29, 2025
1 parent 98ae6c4 commit fea417c
Show file tree
Hide file tree
Showing 25 changed files with 475 additions and 314 deletions.
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
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: 9 additions & 3 deletions enum.go
Original file line number Diff line number Diff line change
Expand Up @@ -570,7 +570,9 @@ var AllFrequencyTimeScale = []string{
// HasDocumentationSubtypeEnum The subtype of the document
type HasDocumentationSubtypeEnum string

var HasDocumentationSubtypeEnumOpenapi HasDocumentationSubtypeEnum = "openapi" // Document is an OpenAPI document
var (
HasDocumentationSubtypeEnumOpenapi HasDocumentationSubtypeEnum = "openapi" // Document is an OpenAPI document
)

// All HasDocumentationSubtypeEnum as []string
var AllHasDocumentationSubtypeEnum = []string{
Expand Down Expand Up @@ -684,7 +686,9 @@ var AllPackageManagerEnum = []string{
// PayloadFilterEnum Fields that can be used as part of filters for payloads
type PayloadFilterEnum string

var PayloadFilterEnumIntegrationID PayloadFilterEnum = "integration_id" // Filter by `integration` field. Note that this is an internal id, ex. "123"
var (
PayloadFilterEnumIntegrationID PayloadFilterEnum = "integration_id" // Filter by `integration` field. Note that this is an internal id, ex. "123"
)

// All PayloadFilterEnum as []string
var AllPayloadFilterEnum = []string{
Expand Down Expand Up @@ -1186,7 +1190,9 @@ var AllUsersFilterEnum = []string{
// UsersInviteScopeEnum A classification of users to invite
type UsersInviteScopeEnum string

var UsersInviteScopeEnumPending UsersInviteScopeEnum = "pending" // All users who have yet to log in to OpsLevel for the first time
var (
UsersInviteScopeEnumPending UsersInviteScopeEnum = "pending" // All users who have yet to log in to OpsLevel for the first time
)

// All UsersInviteScopeEnum as []string
var AllUsersInviteScopeEnum = []string{
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
Loading

0 comments on commit fea417c

Please sign in to comment.