-
Notifications
You must be signed in to change notification settings - Fork 13
Expand file tree
/
Copy pathdocument.go
More file actions
77 lines (66 loc) · 2.35 KB
/
document.go
File metadata and controls
77 lines (66 loc) · 2.35 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
package opslevel
type ServiceDocument struct {
Id ID `graphql:"id" json:"id"`
HtmlURL string `graphql:"htmlUrl" json:"htmlUrl,omitempty"`
Source ServiceDocumentSource `graphql:"source" json:"source"`
Timestamps Timestamps `graphql:"timestamps" json:"timestamps"`
}
type ServiceDocumentContent struct {
ServiceDocument
Content string `graphql:"content" json:"content,omitempty"`
}
func (client *Client) ServiceApiDocSettingsUpdate(service string, docPath string, docSource *ApiDocumentSourceEnum) (*Service, error) {
var m struct {
Payload ServiceUpdatePayload `graphql:"serviceApiDocSettingsUpdate(service: $service, apiDocumentPath: $docPath, preferredApiDocumentSource: $docSource)"`
}
v := PayloadVariables{
"service": *NewIdentifier(service),
"docPath": (*string)(nil),
"docSource": docSource,
}
if docPath != "" {
v["docPath"] = &docPath
}
err := client.Mutate(&m, v, WithName("ServiceApiDocSettingsUpdate"))
return &m.Payload.Service, HandleErrors(err, m.Payload.Errors)
}
func (client *Client) ListDocuments(variables *PayloadVariables) (*ServiceDocumentConnection, error) {
var q struct {
Account struct {
Documents ServiceDocumentConnection `graphql:"documents(searchTerm: $searchTerm, after: $after, first: $first)"`
}
}
if variables == nil {
variables = client.InitialPageVariablesPointer()
}
if (*variables)["searchTerm"] == nil {
(*variables)["searchTerm"] = ""
}
if err := client.Query(&q, *variables, WithName("ListDocuments")); err != nil {
return nil, err
}
q.Account.Documents.TotalCount = len(q.Account.Documents.Nodes)
if q.Account.Documents.PageInfo.HasNextPage {
(*variables)["after"] = q.Account.Documents.PageInfo.End
resp, err := client.ListDocuments(variables)
if err != nil {
return &q.Account.Documents, err
}
q.Account.Documents.Nodes = append(q.Account.Documents.Nodes, resp.Nodes...)
q.Account.Documents.PageInfo = resp.PageInfo
}
q.Account.Documents.TotalCount = len(q.Account.Documents.Nodes)
return &q.Account.Documents, nil
}
func (client *Client) GetDocument(id ID) (*ServiceDocumentContent, error) {
var q struct {
Account struct {
Document ServiceDocumentContent `graphql:"document(id: $id)"`
}
}
v := PayloadVariables{
"id": id,
}
err := client.Query(&q, v, WithName("DocumentGet"))
return &q.Account.Document, err
}