-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgraphql.go
44 lines (36 loc) · 1.03 KB
/
graphql.go
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
package cloudcms
import (
"encoding/json"
"fmt"
"io"
"net/url"
)
func (session *CloudCmsSession) GraphQLQuery(repositoryId string, branchId string, query string, operationName string, variables JsonObject) (JsonObject, error) {
uri := fmt.Sprintf("/repositories/%s/branches/%s/graphql", repositoryId, branchId)
params := url.Values{"query": []string{query}}
if operationName != "" {
params.Add("operationName", operationName)
}
if variables != nil {
variablesStr, _ := json.Marshal(variables)
params.Add("variables", string(variablesStr))
}
res, err := session.Get(uri, params)
if err != nil {
return nil, err
}
return res, nil
}
func (session *CloudCmsSession) GraphQLSchema(repositoryId string, branchId string) (string, error) {
uri := fmt.Sprintf("/repositories/%s/branches/%s/graphql/schema", repositoryId, branchId)
reader, err := session.Download(uri, nil)
if err != nil {
return "", err
}
defer reader.Close()
bytes, err := io.ReadAll(reader)
if err != nil {
return "", err
}
return string(bytes), nil
}