8
8
"github.com/codefresh-io/argo-platform/libs/ql/graph/model"
9
9
)
10
10
11
-
12
11
type (
13
12
IArgoRuntimeAPI interface {
14
13
List () ([]model.Runtime , error )
@@ -17,20 +16,20 @@ type (
17
16
codefresh * codefresh
18
17
}
19
18
graphqlRuntimesResponse struct {
20
- Data struct {
21
- Runtimes model.RuntimePage `json:"runtimes"`
22
- } `json:"data"`
23
- Errors []byte
19
+ Data struct {
20
+ Runtimes model.RuntimePage
21
+ }
22
+ Errors []graphqlError
24
23
}
25
24
)
26
25
27
26
func newArgoRuntimeAPI (codefresh * codefresh ) IArgoRuntimeAPI {
28
27
return & argoRuntime {codefresh : codefresh }
29
28
}
30
- func (r * argoRuntime ) List () ([]model.Runtime , error ) {
29
+ func (r * argoRuntime ) List () ([]model.Runtime , error ) {
31
30
32
31
jsonData := map [string ]interface {}{
33
- "query" :`
32
+ "query" : `
34
33
{
35
34
runtimes{
36
35
edges{
@@ -46,24 +45,23 @@ func (r *argoRuntime) List() ([]model.Runtime, error) {
46
45
}
47
46
}
48
47
` ,
49
- }
50
-
48
+ }
51
49
52
50
response , err := r .codefresh .requestAPI (& requestOptions {
53
51
method : "POST" ,
54
- path : "/argo/api/graphql" ,
55
- body : jsonData ,
52
+ path : "/argo/api/graphql" ,
53
+ body : jsonData ,
56
54
})
57
- defer response .Body .Close ()
58
- if err != nil {
59
- fmt .Printf ("The HTTP request failed with error %s\n " , err )
55
+ defer response .Body .Close ()
56
+ if err != nil {
57
+ fmt .Printf ("The HTTP request failed with error %s\n " , err )
60
58
return nil , err
61
- }
62
- data , err := ioutil .ReadAll (response .Body )
59
+ }
60
+ data , err := ioutil .ReadAll (response .Body )
63
61
if err != nil {
64
- fmt .Printf ("failed to read from response body" )
62
+ fmt .Printf ("failed to read from response body" )
65
63
return nil , err
66
- }
64
+ }
67
65
res := graphqlRuntimesResponse {}
68
66
err = json .Unmarshal (data , & res )
69
67
if err != nil {
@@ -73,8 +71,11 @@ func (r *argoRuntime) List() ([]model.Runtime, error) {
73
71
for _ , v := range res .Data .Runtimes .Edges {
74
72
runtimes = append (runtimes , * v .Node )
75
73
}
76
-
74
+
75
+ if len (res .Errors ) > 0 {
76
+ return nil , graphqlErrorResponse {errors : res .Errors }
77
+ }
78
+
77
79
return runtimes , nil
78
-
79
-
80
- }
80
+
81
+ }
0 commit comments