88 "github.com/codefresh-io/argo-platform/libs/ql/graph/model"
99)
1010
11-
1211type (
1312 IArgoRuntimeAPI interface {
1413 List () ([]model.Runtime , error )
@@ -17,20 +16,20 @@ type (
1716 codefresh * codefresh
1817 }
1918 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
2423 }
2524)
2625
2726func newArgoRuntimeAPI (codefresh * codefresh ) IArgoRuntimeAPI {
2827 return & argoRuntime {codefresh : codefresh }
2928}
30- func (r * argoRuntime ) List () ([]model.Runtime , error ) {
29+ func (r * argoRuntime ) List () ([]model.Runtime , error ) {
3130
3231 jsonData := map [string ]interface {}{
33- "query" :`
32+ "query" : `
3433 {
3534 runtimes{
3635 edges{
@@ -46,24 +45,23 @@ func (r *argoRuntime) List() ([]model.Runtime, error) {
4645 }
4746 }
4847 ` ,
49- }
50-
48+ }
5149
5250 response , err := r .codefresh .requestAPI (& requestOptions {
5351 method : "POST" ,
54- path : "/argo/api/graphql" ,
55- body : jsonData ,
52+ path : "/argo/api/graphql" ,
53+ body : jsonData ,
5654 })
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 )
6058 return nil , err
61- }
62- data , err := ioutil .ReadAll (response .Body )
59+ }
60+ data , err := ioutil .ReadAll (response .Body )
6361 if err != nil {
64- fmt .Printf ("failed to read from response body" )
62+ fmt .Printf ("failed to read from response body" )
6563 return nil , err
66- }
64+ }
6765 res := graphqlRuntimesResponse {}
6866 err = json .Unmarshal (data , & res )
6967 if err != nil {
@@ -73,8 +71,11 @@ func (r *argoRuntime) List() ([]model.Runtime, error) {
7371 for _ , v := range res .Data .Runtimes .Edges {
7472 runtimes = append (runtimes , * v .Node )
7573 }
76-
74+
75+ if len (res .Errors ) > 0 {
76+ return nil , graphqlErrorResponse {errors : res .Errors }
77+ }
78+
7779 return runtimes , nil
78-
79-
80- }
80+
81+ }
0 commit comments