-
Notifications
You must be signed in to change notification settings - Fork 16
Expand file tree
/
Copy pathcomponent.go
More file actions
141 lines (125 loc) · 4.55 KB
/
component.go
File metadata and controls
141 lines (125 loc) · 4.55 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 Component Service
type ComponentCreateInput ServiceCreateInput
type ComponentUpdateInput ServiceUpdateInput
type ComponentConnection ConnectionBase[Service]
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
if 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)"`
}
v := PayloadVariables{
"input": input,
}
err := client.Mutate(&m, v, WithName("ComponentTypeCreate"))
return &m.Payload.ComponentType, HandleErrors(err, m.Payload.Errors)
}
func (client *Client) CreateComponent(input ComponentCreateInput) (*Component, error) {
resource, err := client.CreateService(ServiceCreateInput(input))
return any(resource).(*Component), err
}
func (client *Client) GetComponentType(identifier string) (*ComponentType, error) {
var q struct {
Account struct {
ComponentType ComponentType `graphql:"componentType(input: $input)"`
}
}
v := PayloadVariables{
"input": *NewIdentifier(identifier),
}
err := client.Query(&q, v, WithName("ComponentTypeGet"))
return &q.Account.ComponentType, HandleErrors(err, nil)
}
func (client *Client) GetComponent(identifier string) (*Component, error) {
resource, err := client.GetService(identifier)
return any(resource).(*Component), err
}
func (client *Client) ListComponentTypes(variables *PayloadVariables) (*ComponentTypeConnection, error) {
var q struct {
Account struct {
ComponentTypes ComponentTypeConnection `graphql:"componentTypes(after: $after, first: $first)"`
}
}
if variables == nil {
variables = client.InitialPageVariablesPointer()
}
if err := client.Query(&q, *variables, WithName("ComponentTypeList")); err != nil {
return nil, err
}
if q.Account.ComponentTypes.PageInfo.HasNextPage {
(*variables)["after"] = q.Account.ComponentTypes.PageInfo.End
resp, err := client.ListComponentTypes(variables)
if err != nil {
return nil, err
}
q.Account.ComponentTypes.Nodes = append(q.Account.ComponentTypes.Nodes, resp.Nodes...)
q.Account.ComponentTypes.PageInfo = resp.PageInfo
}
q.Account.ComponentTypes.TotalCount = len(q.Account.ComponentTypes.Nodes)
return &q.Account.ComponentTypes, nil
}
func (client *Client) ListComponents(variables *PayloadVariables) (*ComponentConnection, error) {
resource, err := client.ListServices(variables)
return any(resource).(*ComponentConnection), err
}
func (client *Client) UpdateComponentType(identifier string, input ComponentTypeInput) (*ComponentType, error) {
var m struct {
Payload ComponentTypePayload `graphql:"componentTypeUpdate(componentType:$target,input:$input)"`
}
v := PayloadVariables{
"target": *NewIdentifier(identifier),
"input": input,
}
err := client.Mutate(&m, v, WithName("ComponentTypeUpdate"))
return &m.Payload.ComponentType, HandleErrors(err, m.Payload.Errors)
}
func (client *Client) UpdateComponent(input ComponentUpdateInput) (*Component, error) {
resource, err := client.UpdateService(ServiceUpdateInput(input))
return any(resource).(*Component), err
}
func (client *Client) DeleteComponentType(identifier string) error {
var d struct {
Payload BasePayload `graphql:"componentTypeDelete(resource:$target)"`
}
v := PayloadVariables{
"target": *NewIdentifier(identifier),
}
err := client.Mutate(&d, v, WithName("ComponentTypeDelete"))
return HandleErrors(err, d.Payload.Errors)
}
func (client *Client) DeleteComponent(identifier string) error {
return client.DeleteService(identifier)
}