-
Notifications
You must be signed in to change notification settings - Fork 17
Expand file tree
/
Copy pathrelationship.go
More file actions
141 lines (131 loc) · 4.57 KB
/
relationship.go
File metadata and controls
141 lines (131 loc) · 4.57 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
package opslevel
import "fmt"
type RelationshipDefinitionPayload struct {
Definition RelationshipDefinitionType // The relationship that was defined.
BasePayload
}
func (client *Client) CreateRelationshipDefinition(input RelationshipDefinitionInput) (*RelationshipDefinitionType, error) {
var m struct {
Payload RelationshipDefinitionPayload `graphql:"relationshipDefinitionCreate(input: $input)"`
}
v := PayloadVariables{
"input": input,
}
err := client.Mutate(&m, v, WithName("RelationshipDefinitionCreate"))
return &m.Payload.Definition, HandleErrors(err, m.Payload.Errors)
}
func (client *Client) CreateRelationship(input RelationshipDefinition) (*RelationshipType, error) {
var m struct {
Payload struct {
Relationship RelationshipType
Errors []Error
} `graphql:"relationshipCreate(relationshipDefinition: $input)"`
}
v := PayloadVariables{
"input": input,
}
err := client.Mutate(&m, v, WithName("RelationshipCreate"))
return &m.Payload.Relationship, HandleErrors(err, m.Payload.Errors)
}
func (client *Client) GetRelationshipDefinition(identifier string) (*RelationshipDefinitionType, error) {
var q struct {
Account struct {
Resource RelationshipDefinitionType `graphql:"relationshipDefinition(input: $input)"`
}
}
v := PayloadVariables{
"input": *NewIdentifier(identifier),
}
err := client.Query(&q, v, WithName("RelationshipDefinitionGet"))
return &q.Account.Resource, HandleErrors(err, nil)
}
func (client *Client) GetRelationship(identifier string) (*RelationshipType, error) {
if !IsID(identifier) {
return nil, fmt.Errorf("identifier '%s' is not a valid ID", identifier)
}
var q struct {
Account struct {
Resource RelationshipType `graphql:"relationship(id: $input)"`
}
}
v := PayloadVariables{
"input": *NewID(identifier),
}
err := client.Query(&q, v, WithName("RelationshipGet"))
return &q.Account.Resource, HandleErrors(err, nil)
}
func (client *Client) ListRelationshipDefinitions(variables *PayloadVariables) (*RelationshipDefinitionConnection, error) {
var q struct {
Account struct {
Resources RelationshipDefinitionConnection `graphql:"relationshipDefinitions(after: $after, first: $first, componentType: $componentType, resource: $resource)"`
}
}
if variables == nil {
variables = client.InitialPageVariablesPointer()
} else {
if (*variables)["first"] == nil {
(*variables)["first"] = 100
}
if (*variables)["after"] == nil {
(*variables)["after"] = ""
}
}
if (*variables)["componentType"] == nil {
(*variables)["componentType"] = &IdentifierInput{}
}
if (*variables)["resource"] == nil {
(*variables)["resource"] = NewID("")
}
if err := client.Query(&q, *variables, WithName("RelationshipDefinitionList")); err != nil {
return nil, err
}
if q.Account.Resources.PageInfo.HasNextPage {
(*variables)["after"] = q.Account.Resources.PageInfo.End
resp, err := client.ListRelationshipDefinitions(variables)
if err != nil {
return nil, err
}
q.Account.Resources.Nodes = append(q.Account.Resources.Nodes, resp.Nodes...)
q.Account.Resources.PageInfo = resp.PageInfo
}
q.Account.Resources.TotalCount = len(q.Account.Resources.Nodes)
return &q.Account.Resources, nil
}
func (client *Client) UpdateRelationshipDefinition(identifier string, input RelationshipDefinitionInput) (*RelationshipDefinitionType, error) {
var m struct {
Payload RelationshipDefinitionPayload `graphql:"relationshipDefinitionUpdate(relationshipDefinition: $identifier, input: $input)"`
}
v := PayloadVariables{
"identifier": *NewIdentifier(identifier),
"input": input,
}
err := client.Mutate(&m, v, WithName("RelationshipDefinitionUpdate"))
return &m.Payload.Definition, HandleErrors(err, m.Payload.Errors)
}
func (client *Client) DeleteRelationshipDefinition(identifier string) (*ID, error) {
var m struct {
Payload struct {
DeletedId ID `graphql:"deletedId"`
Errors []Error `graphql:"errors"`
} `graphql:"relationshipDefinitionDelete(resource: $input)"`
}
input := *NewIdentifier(identifier)
v := PayloadVariables{
"input": input,
}
err := client.Mutate(&m, v, WithName("RelationshipDefinitionDelete"))
return &m.Payload.DeletedId, HandleErrors(err, m.Payload.Errors)
}
func (client *Client) DeleteRelationship(identifier string) (*ID, error) {
var m struct {
Payload struct {
DeletedId ID `graphql:"deletedId"`
Errors []Error `graphql:"errors"`
} `graphql:"relationshipDelete(input: $input)"`
}
v := PayloadVariables{
"input": DeleteInput{Id: ID(identifier)},
}
err := client.Mutate(&m, v, WithName("RelationshipDelete"))
return &m.Payload.DeletedId, HandleErrors(err, m.Payload.Errors)
}