Skip to content

Commit

Permalink
Replace hasura/go-graphql-client with cli/shurcooL-graphql
Browse files Browse the repository at this point in the history
  • Loading branch information
SaaldjorMike committed Sep 11, 2023
1 parent 34e2511 commit d3fdd33
Show file tree
Hide file tree
Showing 18 changed files with 344 additions and 326 deletions.
203 changes: 106 additions & 97 deletions api/actions.go

Large diffs are not rendered by default.

76 changes: 41 additions & 35 deletions api/alerts.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package api

import (
"fmt"
graphql "github.com/cli/shurcooL-graphql"
)

type Alert struct {
Expand All @@ -13,17 +14,15 @@ type Alert struct {
TimeOfLastTrigger int `graphql:"timeOfLastTrigger" yaml:"timeOfLastTrigger" json:"timeOfLastTrigger"`
IsStarred bool `graphql:"isStarred" yaml:"isStarred" json:"isStarred"`
Description string `graphql:"description" yaml:"description,omitempty" json:"description"`
ThrottleTimeMillis Long `graphql:"throttleTimeMillis" yaml:"throttleTimeMillis" json:"throttleTimeMillis"`
ThrottleTimeMillis int `graphql:"throttleTimeMillis" yaml:"throttleTimeMillis" json:"throttleTimeMillis"`
Enabled bool `graphql:"enabled" yaml:"enabled" json:"enabled"`
Actions []string `graphql:"actions" yaml:"actions" json:"actions"`
Labels []string `graphql:"labels" yaml:"labels" json:"labels"`
Labels []string `graphql:"labels" yaml:"labels,omitempty" json:"labels,omitempty"`
LastError string `graphql:"lastError" yaml:"lastError" json:"lastError"`
}

type Long int64

func (l Long) GetGraphQLType() string { return "Long" }

type Alerts struct {
client *Client
}
Expand All @@ -38,7 +37,7 @@ func (a *Alerts) List(viewName string) ([]Alert, error) {
}

variables := map[string]interface{}{
"viewName": viewName,
"viewName": graphql.String(viewName),
}

err := a.client.Query(&query, variables)
Expand All @@ -58,25 +57,29 @@ func (a *Alerts) Update(viewName string, newAlert *Alert) (*Alert, error) {
Alert `graphql:"updateAlert(input: { id: $id, viewName: $viewName, name: $alertName, description: $description, queryString: $queryString, queryStart: $queryStart, throttleTimeMillis: $throttleTimeMillis, throttleField: $throttleField, enabled: $enabled, actions: $actions, labels: $labels })"`
}

actions := make([]string, len(newAlert.Actions))
labels := make([]string, len(newAlert.Labels))
var throttleField *string
copy(actions, newAlert.Actions)
copy(labels, newAlert.Labels)
actions := make([]graphql.String, len(newAlert.Actions))
labels := make([]graphql.String, len(newAlert.Labels))
var throttleField *graphql.String
for i, action := range newAlert.Actions {
actions[i] = graphql.String(action)
}
for i, label := range newAlert.Labels {
labels[i] = graphql.String(label)
}
if newAlert.ThrottleField != "" {
field := newAlert.ThrottleField
field := graphql.String(newAlert.ThrottleField)
throttleField = &field
}
variables := map[string]interface{}{
"id": newAlert.ID,
"viewName": viewName,
"alertName": newAlert.Name,
"description": newAlert.Description,
"queryString": newAlert.QueryString,
"queryStart": newAlert.QueryStart,
"id": graphql.String(newAlert.ID),
"viewName": graphql.String(viewName),
"alertName": graphql.String(newAlert.Name),
"description": graphql.String(newAlert.Description),
"queryString": graphql.String(newAlert.QueryString),
"queryStart": graphql.String(newAlert.QueryStart),
"throttleField": throttleField,
"throttleTimeMillis": newAlert.ThrottleTimeMillis,
"enabled": newAlert.Enabled,
"throttleTimeMillis": Long(newAlert.ThrottleTimeMillis),
"enabled": graphql.Boolean(newAlert.Enabled),
"actions": actions,
"labels": labels,
}
Expand Down Expand Up @@ -115,25 +118,28 @@ func (a *Alerts) Add(viewName string, newAlert *Alert) (*Alert, error) {
Alert `graphql:"createAlert(input: { viewName: $viewName, name: $alertName, description: $description, queryString: $queryString, queryStart: $queryStart, throttleTimeMillis: $throttleTimeMillis, throttleField: $throttleField, enabled: $enabled, actions: $actions, labels: $labels })"`
}

actions := make([]string, len(newAlert.Actions))
labels := make([]string, len(newAlert.Labels))
var throttleField *string
copy(actions, newAlert.Actions)
copy(labels, newAlert.Labels)
actions := make([]graphql.String, len(newAlert.Actions))
labels := make([]graphql.String, len(newAlert.Labels))
var throttleField *graphql.String
for i, action := range newAlert.Actions {
actions[i] = graphql.String(action)
}
for i, label := range newAlert.Labels {
labels[i] = graphql.String(label)
}
if newAlert.ThrottleField != "" {
field := newAlert.ThrottleField
field := graphql.String(newAlert.ThrottleField)
throttleField = &field
}

variables := map[string]interface{}{
"viewName": viewName,
"alertName": newAlert.Name,
"description": newAlert.Description,
"queryString": newAlert.QueryString,
"queryStart": newAlert.QueryStart,
"throttleTimeMillis": newAlert.ThrottleTimeMillis,
"viewName": graphql.String(viewName),
"alertName": graphql.String(newAlert.Name),
"description": graphql.String(newAlert.Description),
"queryString": graphql.String(newAlert.QueryString),
"queryStart": graphql.String(newAlert.QueryStart),
"throttleTimeMillis": Long(newAlert.ThrottleTimeMillis),
"throttleField": throttleField,
"enabled": newAlert.Enabled,
"enabled": graphql.Boolean(newAlert.Enabled),
"actions": actions,
"labels": labels,
}
Expand Down Expand Up @@ -197,8 +203,8 @@ func (a *Alerts) Delete(viewName, alertName string) error {
}

variables := map[string]interface{}{
"viewName": viewName,
"alertId": alertId,
"viewName": graphql.String(viewName),
"alertId": graphql.String(alertId),
}

return a.client.Mutate(&mutation, variables)
Expand Down
19 changes: 17 additions & 2 deletions api/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,12 @@ import (
"bytes"
"context"
"fmt"
graphql "github.com/cli/shurcooL-graphql"
"io"
"net"
"net/http"
"net/url"
"strings"

"github.com/hasura/go-graphql-client"
)

const defaultUserAgent = "Humio-go-client/unknown"
Expand Down Expand Up @@ -148,3 +147,19 @@ func (c *Client) HTTPRequestContext(ctx context.Context, httpMethod string, path
var client = c.newHTTPClientWithHeaders(headers)
return client.Do(req)
}

func optBoolArg(v *bool) *graphql.Boolean {
var argPtr *graphql.Boolean
if v != nil {
argPtr = graphql.NewBoolean(graphql.Boolean(*v))
}
return argPtr
}

func optStringArg(v *string) *graphql.String {
var argPtr *graphql.String
if v != nil {
argPtr = graphql.NewString(graphql.String(*v))
}
return argPtr
}
29 changes: 15 additions & 14 deletions api/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package api

import (
"fmt"
graphql "github.com/cli/shurcooL-graphql"
"math"
)

Expand Down Expand Up @@ -71,21 +72,21 @@ func (c *Clusters) Get() (Cluster, error) {
}

type StoragePartitionInput struct {
ID int32 `json:"id"`
NodeIDs []int32 `json:"nodeIds"`
ID graphql.Int `json:"id"`
NodeIDs []graphql.Int `json:"nodeIds"`
}

type IngestPartitionInput struct {
ID int32 `json:"id"`
NodeIDs []int32 `json:"nodeIds"`
ID graphql.Int `json:"id"`
NodeIDs []graphql.Int `json:"nodeIds"`
}

// Deprecated: returns dummy data as of LogScale 1.88
func (c *Clusters) UpdateStoragePartitionScheme(desired []StoragePartitionInput) error {
var mutation struct {
UpdateStoragePartitionScheme struct {
// We have to make a selection, so just take __typename
Typename string `graphql:"__typename"`
Typename graphql.String `graphql:"__typename"`
} `graphql:"updateStoragePartitionScheme(partitions: $partitions)"`
}

Expand All @@ -101,7 +102,7 @@ func (c *Clusters) UpdateIngestPartitionScheme(desired []IngestPartitionInput) e
var mutation struct {
UpdateStoragePartitionScheme struct {
// We have to make a selection, so just take __typename
Typename string `graphql:"__typename"`
Typename graphql.String `graphql:"__typename"`
} `graphql:"updateIngestPartitionScheme(partitions: $partitions)"`
}

Expand All @@ -117,7 +118,7 @@ func (c *Clusters) StartDataRedistribution() error {
var mutation struct {
StartDataRedistribution struct {
// We have to make a selection, so just take __typename
Typename string `graphql:"__typename"`
Typename graphql.String `graphql:"__typename"`
} `graphql:"startDataRedistribution"`
}

Expand All @@ -129,12 +130,12 @@ func (c *Clusters) ClusterMoveStorageRouteAwayFromNode(nodeID int) error {
var mutation struct {
ClusterMoveStorageRouteAwayFromNode struct {
// We have to make a selection, so just take __typename
Typename string `graphql:"__typename"`
Typename graphql.String `graphql:"__typename"`
} `graphql:"clusterMoveStorageRouteAwayFromNode(nodeID: $id)"`
}

variables := map[string]interface{}{
"id": int32(nodeID),
"id": graphql.Int(nodeID),
}

return c.client.Mutate(&mutation, variables)
Expand All @@ -145,12 +146,12 @@ func (c *Clusters) ClusterMoveIngestRoutesAwayFromNode(nodeID int) error {
var mutation struct {
ClusterMoveIngestRoutesAwayFromNode struct {
// We have to make a selection, so just take __typename
Typename string `graphql:"__typename"`
Typename graphql.String `graphql:"__typename"`
} `graphql:"clusterMoveIngestRoutesAwayFromNode(nodeID: $id)"`
}

variables := map[string]interface{}{
"id": int32(nodeID),
"id": graphql.Int(nodeID),
}

return c.client.Mutate(&mutation, variables)
Expand Down Expand Up @@ -201,13 +202,13 @@ func (n *ClusterNodes) Unregister(nodeID int, force bool) error {
var mutation struct {
ClusterUnregisterNode struct {
// We have to make a selection, so just take __typename
Typename string `graphql:"__typename"`
Typename graphql.String `graphql:"__typename"`
} `graphql:"clusterUnregisterNode(force: $force, nodeID: $id)"`
}

variables := map[string]interface{}{
"id": int32(nodeID),
"force": force,
"id": graphql.Int(nodeID),
"force": graphql.Boolean(force),
}

return n.client.Mutate(&mutation, variables)
Expand Down
10 changes: 6 additions & 4 deletions api/featureflag.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package api

import graphql "github.com/cli/shurcooL-graphql"

type FeatureFlag string

type FeatureFlags struct {
Expand Down Expand Up @@ -63,7 +65,7 @@ func (f *FeatureFlags) EnableForOrganization(organizationID string, flag Feature

variables := map[string]interface{}{
"feature": flag,
"orgId": organizationID,
"orgId": graphql.String(organizationID),
}

return f.c.Mutate(&mutation, variables)
Expand All @@ -76,7 +78,7 @@ func (f *FeatureFlags) DisableForOrganization(organizationID string, flag Featur

variables := map[string]interface{}{
"feature": flag,
"orgId": organizationID,
"orgId": graphql.String(organizationID),
}

return f.c.Mutate(&mutation, variables)
Expand All @@ -89,7 +91,7 @@ func (f *FeatureFlags) EnableForUser(userID string, flag FeatureFlag) error {

variables := map[string]interface{}{
"feature": flag,
"userId": userID,
"userId": graphql.String(userID),
}

return f.c.Mutate(&mutation, variables)
Expand All @@ -102,7 +104,7 @@ func (f *FeatureFlags) DisableForUser(userID string, flag FeatureFlag) error {

variables := map[string]interface{}{
"feature": flag,
"userId": userID,
"userId": graphql.String(userID),
}

return f.c.Mutate(&mutation, variables)
Expand Down
9 changes: 5 additions & 4 deletions api/files.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package api
import (
"context"
"fmt"
graphql "github.com/cli/shurcooL-graphql"
"io"
"mime/multipart"
"net/http"
Expand Down Expand Up @@ -31,7 +32,7 @@ func (f *Files) List(viewName string) ([]File, error) {
}

variables := map[string]interface{}{
"viewName": viewName,
"viewName": graphql.String(viewName),
}

err := f.client.Query(&query, variables)
Expand All @@ -42,13 +43,13 @@ func (f *Files) Delete(viewName string, fileName string) error {
var query struct {
RemoveFile struct {
// We have to make a selection, so just take __typename
Typename string `graphql:"__typename"`
Typename graphql.String `graphql:"__typename"`
} `graphql:"removeFile(name:$viewName, fileName: $fileName)"`
}

variables := map[string]interface{}{
"viewName": viewName,
"fileName": fileName,
"viewName": graphql.String(viewName),
"fileName": graphql.String(fileName),
}

return f.client.Mutate(&query, variables)
Expand Down
9 changes: 5 additions & 4 deletions api/groups.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package api

import (
"errors"
graphql "github.com/cli/shurcooL-graphql"
)

type Groups struct {
Expand Down Expand Up @@ -44,8 +45,8 @@ func (g *Groups) AddUserToGroup(groupID string, userID string) error {
}

variables := map[string]interface{}{
"userID": userID,
"groupID": groupID,
"userID": graphql.String(userID),
"groupID": graphql.String(groupID),
}

err := g.client.Mutate(&mutation, variables)
Expand Down Expand Up @@ -78,8 +79,8 @@ func (g *Groups) RemoveUserFromGroup(groupID string, userID string) error {
}

variables := map[string]interface{}{
"userID": userID,
"groupID": groupID,
"userID": graphql.String(userID),
"groupID": graphql.String(groupID),
}

return g.client.Mutate(&mutation, variables)
Expand Down
Loading

0 comments on commit d3fdd33

Please sign in to comment.