Skip to content

Commit

Permalink
Rename to gqlclient
Browse files Browse the repository at this point in the history
  • Loading branch information
MDrakos committed Nov 21, 2024
1 parent 5f2e02e commit 254108a
Show file tree
Hide file tree
Showing 14 changed files with 36 additions and 36 deletions.
2 changes: 1 addition & 1 deletion internal/graphql/error.go → internal/gqlclient/error.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package graphql
package gqlclient

import "fmt"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
//
// httpclient := &http.Client{}
// client := graphql.NewClient("https://machinebox.io/graphql", graphql.WithHTTPClient(httpclient))
package graphql
package gqlclient

import (
"bytes"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package graphql
package gqlclient

import (
"context"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package graphql
package gqlclient

import (
"context"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package graphql
package gqlclient

type TestRequest struct {
q string
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package graphql
package gqlclient

import (
"context"
Expand Down
6 changes: 3 additions & 3 deletions pkg/platform/api/graphql/graphql.go
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
package graphql

import (
"github.com/ActiveState/cli/internal/graphql"
"github.com/ActiveState/cli/internal/gqlclient"
"github.com/ActiveState/cli/pkg/platform/api"
"github.com/ActiveState/cli/pkg/platform/authentication"
)

func New(auth *authentication.Auth) *graphql.Client {
func New(auth *authentication.Auth) *gqlclient.Client {
url := api.GetServiceURL(api.ServiceGraphQL)
c := graphql.New(url.String(), 0)
c := gqlclient.New(url.String(), 0)
c.SetTokenProvider(auth)
return c
}
8 changes: 4 additions & 4 deletions pkg/platform/api/graphql/request/publish.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (

"github.com/ActiveState/cli/internal/errs"
"github.com/ActiveState/cli/internal/fileutils"
"github.com/ActiveState/cli/internal/graphql"
"github.com/ActiveState/cli/internal/gqlclient"
"github.com/ActiveState/cli/internal/locale"
yamlcomment "github.com/zijiren233/yaml-comment"
"gopkg.in/yaml.v3"
Expand Down Expand Up @@ -187,11 +187,11 @@ func (p *PublishInput) Close() error {
return p.file.Close()
}

func (p *PublishInput) Files() []graphql.File {
func (p *PublishInput) Files() []gqlclient.File {
if p.file == nil {
return []graphql.File{}
return []gqlclient.File{}
}
return []graphql.File{
return []gqlclient.File{
{
Field: "variables.input.file", // this needs to map to the graphql input, eg. variables.input.file
Name: p.Variables.Name,
Expand Down
6 changes: 3 additions & 3 deletions pkg/platform/api/hasura_inventory/inventory.go
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
package inventory

import (
"github.com/ActiveState/cli/internal/graphql"
"github.com/ActiveState/cli/internal/gqlclient"
"github.com/ActiveState/cli/pkg/platform/api"
"github.com/ActiveState/cli/pkg/platform/authentication"
)

func New(auth *authentication.Auth) *graphql.Client {
client := graphql.New(api.GetServiceURL(api.ServiceHasuraInventory).String(), 0)
func New(auth *authentication.Auth) *gqlclient.Client {
client := gqlclient.New(api.GetServiceURL(api.ServiceHasuraInventory).String(), 0)

if auth != nil && auth.Authenticated() {
client.SetTokenProvider(auth)
Expand Down
6 changes: 3 additions & 3 deletions pkg/platform/api/mediator/mediator.go
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
package mediator

import (
"github.com/ActiveState/cli/internal/graphql"
"github.com/ActiveState/cli/internal/gqlclient"
"github.com/ActiveState/cli/pkg/platform/api"
"github.com/ActiveState/cli/pkg/platform/authentication"
)

func New(auth *authentication.Auth) *graphql.Client {
func New(auth *authentication.Auth) *gqlclient.Client {
url := api.GetServiceURL(api.ServiceMediator)
c := graphql.New(url.String(), 0)
c := gqlclient.New(url.String(), 0)
if auth != nil {
c.SetTokenProvider(auth)
}
Expand Down
6 changes: 3 additions & 3 deletions pkg/platform/api/vulnerabilities/vulnerabilities.go
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
package vulnerabilities

import (
"github.com/ActiveState/cli/internal/graphql"
"github.com/ActiveState/cli/internal/gqlclient"
"github.com/ActiveState/cli/pkg/platform/api"
"github.com/ActiveState/cli/pkg/platform/authentication"
)

func New(auth *authentication.Auth) *graphql.Client {
client := graphql.New(api.GetServiceURL(api.ServiceVulnerabilities).String(), 0)
func New(auth *authentication.Auth) *gqlclient.Client {
client := gqlclient.New(api.GetServiceURL(api.ServiceVulnerabilities).String(), 0)

// Most requests to this service require authentication
if auth != nil && auth.Authenticated() {
Expand Down
12 changes: 6 additions & 6 deletions pkg/platform/model/buildplanner/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
"time"

"github.com/ActiveState/cli/internal/errs"
"github.com/ActiveState/cli/internal/graphql"
"github.com/ActiveState/cli/internal/gqlclient"
"github.com/ActiveState/cli/internal/locale"
"github.com/ActiveState/cli/internal/logging"
"github.com/ActiveState/cli/internal/rtutils/ptr"
Expand Down Expand Up @@ -49,7 +49,7 @@ func (c *Commit) BuildScript() *buildscript.BuildScript {
return c.buildscript
}

func (c *client) Run(req graphql.Request, resp interface{}) error {
func (c *client) Run(req gqlclient.Request, resp interface{}) error {
return c.gqlClient.Run(req, resp)
}

Expand Down Expand Up @@ -152,11 +152,11 @@ func (b *BuildPlanner) fetchCommit(commitID strfmt.UUID, owner, project string,
// "data": null
// }
func processBuildPlannerError(bpErr error, fallbackMessage string) error {
graphqlErr := &graphql.GraphErr{}
if errors.As(bpErr, graphqlErr) {
code, ok := graphqlErr.Extensions[codeExtensionKey].(string)
gqlclientErr := &gqlclient.GraphErr{}
if errors.As(bpErr, gqlclientErr) {
code, ok := gqlclientErr.Extensions[codeExtensionKey].(string)
if ok && code == clientDeprecationErrorKey {
return &response.BuildPlannerError{Err: locale.NewExternalError("err_buildplanner_deprecated", "Encountered deprecation error: {{.V0}}", graphqlErr.Message)}
return &response.BuildPlannerError{Err: locale.NewExternalError("err_buildplanner_deprecated", "Encountered deprecation error: {{.V0}}", gqlclientErr.Message)}
}
}
if locale.IsInputError(bpErr) {
Expand Down
6 changes: 3 additions & 3 deletions pkg/platform/model/buildplanner/buildplanner.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package buildplanner
import (
"time"

"github.com/ActiveState/cli/internal/graphql"
"github.com/ActiveState/cli/internal/gqlclient"
"github.com/ActiveState/cli/internal/logging"
"github.com/ActiveState/cli/pkg/platform/api"
"github.com/ActiveState/cli/pkg/platform/authentication"
Expand All @@ -12,7 +12,7 @@ import (
const clientDeprecationErrorKey = "CLIENT_DEPRECATION_ERROR"

type client struct {
gqlClient *graphql.Client
gqlClient *gqlclient.Client
}

type BuildPlanner struct {
Expand Down Expand Up @@ -40,7 +40,7 @@ func NewBuildPlannerModel(auth *authentication.Auth, cache cacher) *BuildPlanner
bpURL := api.GetServiceURL(api.ServiceBuildPlanner).String()
logging.Debug("Using build planner at: %s", bpURL)

gqlClient := graphql.NewWithOpts(bpURL, 0, graphql.WithHTTPClient(api.NewHTTPClient()))
gqlClient := gqlclient.NewWithOpts(bpURL, 0, gqlclient.WithHTTPClient(api.NewHTTPClient()))

if auth != nil && auth.Authenticated() {
gqlClient.SetTokenProvider(auth)
Expand Down
10 changes: 5 additions & 5 deletions pkg/platform/model/svc.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ import (

"github.com/ActiveState/cli/internal/condition"
"github.com/ActiveState/cli/internal/errs"
"github.com/ActiveState/cli/internal/gqlclient"
"github.com/ActiveState/cli/internal/graph"
"github.com/ActiveState/cli/internal/graphql"
"github.com/ActiveState/cli/internal/logging"
"github.com/ActiveState/cli/internal/profile"
"github.com/ActiveState/cli/internal/rtutils/ptr"
Expand All @@ -22,15 +22,15 @@ import (
var SvcTimeoutMinimal = time.Millisecond * 500

type SvcModel struct {
client *graphql.Client
client *gqlclient.Client
}

// NewSvcModel returns a model for all client connections to a State Svc. This function returns an error if the State service is not yet ready to communicate.
func NewSvcModel(port string) *SvcModel {
localURL := "http://127.0.0.1" + port + "/query"

return &SvcModel{
client: graphql.NewWithOpts(localURL, 0, graphql.WithHTTPClient(&http.Client{})),
client: gqlclient.NewWithOpts(localURL, 0, gqlclient.WithHTTPClient(&http.Client{})),
}
}

Expand All @@ -39,12 +39,12 @@ func (m *SvcModel) EnableDebugLog() {
m.client.EnableDebugLog()
}

func (m *SvcModel) request(ctx context.Context, request graphql.Request, resp interface{}) error {
func (m *SvcModel) request(ctx context.Context, request gqlclient.Request, resp interface{}) error {
defer profile.Measure("SvcModel:request", time.Now())

err := m.client.RunWithContext(ctx, request, resp)
if err != nil {
reqError := &graphql.RequestError{}
reqError := &gqlclient.RequestError{}
if errors.As(err, &reqError) && (!condition.BuiltViaCI() || condition.InTest()) {
vars, err := request.Vars()
if err != nil {
Expand Down

0 comments on commit 254108a

Please sign in to comment.