Skip to content

Commit

Permalink
Fixes for terraform component types
Browse files Browse the repository at this point in the history
  • Loading branch information
rocktavious committed Jan 31, 2025
1 parent 250d418 commit be3fa39
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 7 deletions.
36 changes: 36 additions & 0 deletions component.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package opslevel

import "fmt"

type Component Service

type ComponentCreateInput ServiceCreateInput
Expand All @@ -14,6 +16,40 @@ type ComponentTypeConnection struct {
TotalCount int `json:"totalCount" graphql:"-"`
}

func (s *ComponentType) GetProperties(client *Client, v *PayloadVariables) (*PropertyDefinitionConnection, error) {
var q struct {
Account struct {
ComponentType struct {
Properties *PropertyDefinitionConnection `graphql:"properties(after: $after, first: $first)"`
} `graphql:"componentType(input: $input)"`
}
}
if s.Id == "" {
return nil, fmt.Errorf("unable to get properties, invalid id: '%s'", s.Id)
}
if v == nil {
v = client.InitialPageVariablesPointer()
}
(*v)["input"] = *NewIdentifier(string(s.Id))
if err := client.Query(&q, *v, WithName("ComponentTypePropertyList")); err != nil {
return nil, err
}
if s.Properties == nil {
s.Properties = &PropertyDefinitionConnection{}
}
s.Properties.Nodes = append(s.Properties.Nodes, q.Account.ComponentType.Properties.Nodes...)
s.Properties.PageInfo = q.Account.ComponentType.Properties.PageInfo
s.Properties.TotalCount += q.Account.ComponentType.Properties.TotalCount
for s.Properties.PageInfo.HasNextPage {
(*v)["after"] = s.Properties.PageInfo.End
_, err := s.GetProperties(client, v)
if err != nil {
return nil, err
}
}
return s.Properties, nil
}

func (client *Client) CreateComponentType(input ComponentTypeInput) (*ComponentType, error) {
var m struct {
Payload ComponentTypePayload `graphql:"componentTypeCreate(input:$input)"`
Expand Down
13 changes: 7 additions & 6 deletions object.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,12 +80,13 @@ type ComponentTypeId struct {
// ComponentType Information about a particular component type
type ComponentType struct {
ComponentTypeId
Description string // The description of the component type (Optional)
Href string // The relative path to link to the component type (Required)
Icon ComponentTypeIcon // The icon associated with the component type (Required)
IsDefault bool // Whether or not the component type is the default (Required)
Name string // The name of the component type (Required)
Timestamps Timestamps // When the component type was created and updated (Required)
Description string // The description of the component type (Optional)
Href string // The relative path to link to the component type (Required)
Icon ComponentTypeIcon // The icon associated with the component type (Required)
IsDefault bool // Whether or not the component type is the default (Required)
Name string // The name of the component type (Required)
Timestamps Timestamps // When the component type was created and updated (Required)
Properties *PropertyDefinitionConnection `graphql:"-"`
}

// ComponentTypeIcon The icon for a component type
Expand Down
2 changes: 1 addition & 1 deletion property.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ type PropertyDefinition struct {
DisplayType PropertyDefinitionDisplayTypeEnum `graphql:"displayType" json:"displayType"`
PropertyDisplayStatus PropertyDisplayStatusEnum `graphql:"propertyDisplayStatus" json:"propertyDisplayStatus"`
LockedStatus PropertyLockedStatusEnum `graphql:"lockedStatus" json:"lockedStatus"`
Schema JSON `json:"schema" scalar:"true"`
Schema JSONSchema `json:"schema" scalar:"true"`
}

type PropertyDefinitionConnection struct {
Expand Down

0 comments on commit be3fa39

Please sign in to comment.