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
Changes from 1 commit
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
Next Next commit
Codegen Payload Types
rocktavious committed Jan 29, 2025
commit fea417c932a103b04ac1ec37c5846304120c21ea
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
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)"`
@@ -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: 9 additions & 3 deletions enum.go
Original file line number Diff line number Diff line change
@@ -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{
@@ -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{
@@ -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{
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)"`
Loading