99 "net/http"
1010 "strings"
1111
12+ "github.com/codefresh-io/go-sdk/pkg/codefresh/model"
1213 "github.com/google/go-querystring/query"
1314)
1415
@@ -30,9 +31,19 @@ type (
3031 Gitops () GitopsAPI
3132 ArgoRuntime () IArgoRuntimeAPI
3233 GitSource () IGitSourceAPI
34+ Component () IComponentAPI
35+ }
36+
37+ graphqlResponse struct {
38+ Data struct {
39+ Runtimes model.RuntimePage
40+ }
41+ Errors []graphqlError
3342 }
3443)
3544
45+ var qlEndPoint = "/2.0/api/graphql"
46+
3647func New (opt * ClientOptions ) Codefresh {
3748 httpClient := & http.Client {}
3849 if opt .Client != nil {
@@ -94,6 +105,10 @@ func (c *codefresh) GitSource() IGitSourceAPI {
94105 return newGitSourceAPI (c )
95106}
96107
108+ func (c * codefresh ) Component () IComponentAPI {
109+ return newComponentAPI (c )
110+ }
111+
97112func (c * codefresh ) requestAPI (opt * requestOptions ) (* http.Response , error ) {
98113 return c .requestAPIWithContext (context .Background (), opt )
99114}
@@ -122,6 +137,25 @@ func (c *codefresh) requestAPIWithContext(ctx context.Context, opt *requestOptio
122137 return response , nil
123138}
124139
140+ func (c * codefresh ) graphqlAPI (ctx context.Context , body map [string ]interface {}, res interface {}) error {
141+ response , err := c .requestAPIWithContext (ctx , & requestOptions {
142+ method : "POST" ,
143+ path : qlEndPoint ,
144+ body : body ,
145+ })
146+ if err != nil {
147+ return fmt .Errorf ("The HTTP request failed: %w" , err )
148+ }
149+ defer response .Body .Close ()
150+
151+ data , err := ioutil .ReadAll (response .Body )
152+ if err != nil {
153+ return fmt .Errorf ("failed to read from response body: %w" , err )
154+ }
155+
156+ return json .Unmarshal (data , res )
157+ }
158+
125159func buildQSFromMap (qs map [string ]string ) string {
126160 var arr = []string {}
127161 for k , v := range qs {
0 commit comments