Skip to content

Commit f3a901b

Browse files
authored
Add CUD functionality for relationship definitions (#547)
1 parent edd0fb3 commit f3a901b

4 files changed

Lines changed: 91 additions & 3 deletions

File tree

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
kind: Feature
2+
body: Add client functions to create, update and delete "RelationshipDefinition"'s
3+
time: 2025-05-15T14:54:37.070312-05:00

input.go

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -987,9 +987,26 @@ type PropertyInput struct {
987987

988988
// RelationshipDefinition A source, target and relationship type specifying a relationship between two resources
989989
type RelationshipDefinition struct {
990-
Source IdentifierInput `json:"source" yaml:"source"` // The resource that is the source of the relationship. alias is ambiguous in this context and is not supported. Please supply an id (Required)
991-
Target IdentifierInput `json:"target" yaml:"target"` // The resource that is the target of the relationship. alias is ambiguous in this context and is not supported. Please supply an id (Required)
992-
Type RelationshipTypeEnum `json:"type" yaml:"type" example:"belongs_to"` // The type of the relationship between source and target (Required)
990+
RelationshipDefinition *IdentifierInput `json:"relationshipDefinition,omitempty" yaml:"relationshipDefinition,omitempty"` // A dynamic definition that specifies how the source and target are related (Optional)
991+
Source IdentifierInput `json:"source" yaml:"source"` // The resource that is the source of the relationship (Required)
992+
Target IdentifierInput `json:"target" yaml:"target"` // The resource that is the target of the relationship (Required)
993+
Type RelationshipTypeEnum `json:"type" yaml:"type" example:"belongs_to"` // The type of the relationship between source and target (Required)
994+
}
995+
996+
// RelationshipDefinitionInput The input for defining a relationship on a component type
997+
type RelationshipDefinitionInput struct {
998+
Alias *string `json:"alias,omitempty" yaml:"alias,omitempty" example:"example_value"` // The unique identifier of the relationship (Optional)
999+
ComponentType *IdentifierInput `json:"componentType,omitempty" yaml:"componentType,omitempty"` // The component type to create the relationship on (Optional)
1000+
Description *Nullable[string] `json:"description,omitempty" yaml:"description,omitempty" example:"example_value"` // The description of the relationship (Optional)
1001+
Metadata *RelationshipDefinitionMetadataInput `json:"metadata,omitempty" yaml:"metadata,omitempty"` // The metadata of the relationship (Optional)
1002+
Name *string `json:"name,omitempty" yaml:"name,omitempty" example:"example_value"` // The name of the relationship (Optional)
1003+
}
1004+
1005+
// RelationshipDefinitionMetadataInput The metadata of the relationship
1006+
type RelationshipDefinitionMetadataInput struct {
1007+
AllowedTypes []string `json:"allowedTypes,omitempty" yaml:"allowedTypes,omitempty" example:"LIST_TODO"` // The aliases of which types this relationship can target. Valid values include any component type alias on your account, or `team` (Optional)
1008+
MaxItems *int `json:"maxItems,omitempty" yaml:"maxItems,omitempty" example:"3"` // The maximum number of records this relationship can associate to the component type. Defaults to null (no maximum) (Optional)
1009+
MinItems *int `json:"minItems,omitempty" yaml:"minItems,omitempty" example:"3"` // The minimum number of records this relationship must associate to the component type. Defaults to 0 (optional) (Optional)
9931010
}
9941011

9951012
// RepositoryUpdateInput Specifies the input fields used to update a repository

object.go

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -338,6 +338,30 @@ type Predicate struct {
338338
Value string // The value of the condition (Optional)
339339
}
340340

341+
// RelationshipDefinitionMetadata The metadata of the relationship
342+
type RelationshipDefinitionMetadata struct {
343+
AllowedTypes []string // The aliases of which types this relationship can target. Valid values include any component type alias on your account, or `team` (Required)
344+
MaxItems int // The maximum number of records this relationship can associate to the component type. Defaults to null (no maximum) (Optional)
345+
MinItems int // The minimum number of records this relationship must associate to the component type. Defaults to 0 (optional) (Optional)
346+
}
347+
348+
// RelationshipDefinitionType A dynamic definition for a relationship between one catalog entity to another
349+
type RelationshipDefinitionType struct {
350+
Alias string // The programmatic alias that can be used to reference the relationship in OpsLevel tooling (Required)
351+
ComponentType ComponentTypeId // The component type that the relationship belongs to (Required)
352+
Description string // The long-form descripion of what the relationship represents (Optional)
353+
Id ID // The ID of the relationship definition (Required)
354+
Metadata RelationshipDefinitionMetadata // JSON data that defines rules for how the relationship should be validated internally (Required)
355+
Name string // The human-readable name for a relationship (Required)
356+
}
357+
358+
// RelationshipNode The relationship between two resources. A pair of source and destination resources
359+
type RelationshipNode struct {
360+
Destination RelationshipResource // The catalog item that a relationship points to (Required)
361+
Id ID // The ID of the relationship (Required)
362+
Source RelationshipResource // The catalog item that a relationship stems from (Required)
363+
}
364+
341365
// RepositoryPath The repository path used for this service
342366
type RepositoryPath struct {
343367
Href string // The deep link to the repository path where the linked service's code exists (Required)

relationship.go

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
package opslevel
2+
3+
type RelationshipDefinitionPayload struct {
4+
Definition RelationshipDefinitionType // The relationship that was defined.
5+
BasePayload
6+
}
7+
8+
func (client *Client) CreateRelationshipDefinition(input RelationshipDefinitionInput) (*RelationshipDefinitionType, error) {
9+
var m struct {
10+
Payload RelationshipDefinitionPayload `graphql:"relationshipDefinitionCreate(input: $input)"`
11+
}
12+
v := PayloadVariables{
13+
"input": input,
14+
}
15+
err := client.Mutate(&m, v, WithName("RelationshipDefinitionCreate"))
16+
return &m.Payload.Definition, HandleErrors(err, m.Payload.Errors)
17+
}
18+
19+
func (client *Client) UpdateRelationshipDefinition(identifier string, input RelationshipDefinitionInput) (*RelationshipDefinitionType, error) {
20+
var m struct {
21+
Payload RelationshipDefinitionPayload `graphql:"relationshipDefinitionUpdate(relationshipDefinition: $identifier, input: $input)"`
22+
}
23+
v := PayloadVariables{
24+
"identifier": NewIdentifier(identifier),
25+
"input": input,
26+
}
27+
err := client.Mutate(&m, v, WithName("RelationshipDefinitionUpdate"))
28+
return &m.Payload.Definition, HandleErrors(err, m.Payload.Errors)
29+
}
30+
31+
func (client *Client) DeleteRelationshipDefinition(identifier string) (*ID, error) {
32+
var m struct {
33+
Payload struct {
34+
DeletedId ID `graphql:"deletedId"`
35+
Errors []Error `graphql:"errors"`
36+
} `graphql:"relationshipDefinitionDelete(resource: $input)"`
37+
}
38+
input := *NewIdentifier(identifier)
39+
v := PayloadVariables{
40+
"input": input,
41+
}
42+
err := client.Mutate(&m, v, WithName("RelationshipDefinitionDelete"))
43+
return &m.Payload.DeletedId, HandleErrors(err, m.Payload.Errors)
44+
}

0 commit comments

Comments
 (0)