-
Notifications
You must be signed in to change notification settings - Fork 237
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Hook up client and query command to logger
- Loading branch information
Zachary Scott
committed
Jun 5, 2018
1 parent
4a7489c
commit f29be32
Showing
2 changed files
with
45 additions
and
23 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package client | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/circleci/circleci-cli/logger" | ||
"github.com/machinebox/graphql" | ||
) | ||
|
||
type Client struct { | ||
host string | ||
token string | ||
client *graphql.Client | ||
logger *logger.Logger | ||
} | ||
|
||
func NewClient(host string, token string, logger *logger.Logger) *Client { | ||
return &Client{ | ||
host, | ||
token, | ||
graphql.NewClient(host + "/graphql"), | ||
logger, | ||
} | ||
} | ||
|
||
func (c *Client) Run(query string) (map[string]interface{}, error) { | ||
req := graphql.NewRequest(query) | ||
req.Header.Set("Authorization", c.token) | ||
|
||
ctx := context.Background() | ||
var resp map[string]interface{} | ||
|
||
// TODO: fix wrapping logs with | ||
c.logger.Info("Querying ", c.host, " with:\n\n", query, "\n\n") | ||
err := c.client.Run(ctx, req, &resp) | ||
return resp, err | ||
} |
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