-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Closes https://hasurahq.atlassian.net/browse/PLAT-351 PR-URL: hasura/graphql-engine-mono#7256 Co-authored-by: Sooraj <8408875+soorajshankar@users.noreply.github.com> Co-authored-by: Manas Agarwal <5352361+manasag@users.noreply.github.com> GitOrigin-RevId: 5096e76f11ab2860fae9fa7cd71c9afaead20cc0
- Loading branch information
1 parent
f7d4051
commit a0c5e16
Showing
11 changed files
with
217 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
package v1version | ||
|
||
import ( | ||
"bytes" | ||
"context" | ||
"encoding/json" | ||
"fmt" | ||
"io" | ||
"net/http" | ||
|
||
"github.com/hasura/graphql-engine/cli/v2/internal/errors" | ||
"github.com/hasura/graphql-engine/cli/v2/internal/hasura" | ||
"github.com/hasura/graphql-engine/cli/v2/internal/httpc" | ||
) | ||
|
||
type Client struct { | ||
*httpc.Client | ||
path string | ||
} | ||
|
||
func New(client *httpc.Client, path string) *Client { | ||
return &Client{client, path} | ||
} | ||
|
||
func (c *Client) GetVersion() (*hasura.V1VersionResponse, error) { | ||
var op errors.Op = "v1version.Client.GetVersion" | ||
b := new(bytes.Buffer) | ||
resp, err := c.send(nil, b) | ||
if err != nil { | ||
return nil, errors.E(op, err) | ||
} | ||
|
||
if resp.StatusCode != http.StatusOK { | ||
if b.Len() > 0 { | ||
return nil, errors.E(op, errors.KindHasuraAPI, b.String()) | ||
} else { | ||
return nil, errors.E(op, errors.KindHasuraAPI, fmt.Errorf("API request to %v failed, code: %v", c.path, resp.StatusCode)) | ||
} | ||
} | ||
o := new(hasura.V1VersionResponse) | ||
if err := json.NewDecoder(b).Decode(o); err != nil { | ||
return nil, errors.E(op, fmt.Errorf("decoding API response failed for: %v", c.path)) | ||
} | ||
return o, nil | ||
} | ||
|
||
func (c *Client) send(body interface{}, responseBodyWriter io.Writer) (*httpc.Response, error) { | ||
var op errors.Op = "v1version.Client.send" | ||
req, err := c.NewRequest(http.MethodGet, c.path, body) | ||
if err != nil { | ||
return nil, errors.E(op, err) | ||
} | ||
resp, err := c.LockAndDo(context.Background(), req, responseBodyWriter) | ||
if err != nil { | ||
return nil, errors.E(op, err) | ||
} | ||
return resp, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters