Skip to content

Commit

Permalink
Move off old GraphQL API (#666)
Browse files Browse the repository at this point in the history
Let's not remove it entirely because we might want to reuse some of the
underpinnings for the product's GQL API.
  • Loading branch information
sourishkrout committed Sep 12, 2024
1 parent 05dbf31 commit 57248b0
Show file tree
Hide file tree
Showing 16 changed files with 1,650 additions and 5,991 deletions.
5 changes: 3 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -159,8 +159,9 @@ release/publish: install/goreleaser

.PHONY: update-gql-schema
update-gql-schema:
@go run ./cmd/gqltool/main.go > ./client/graphql/schema/introspection_query_result.json
@cd ./client/graphql/schema && npm run convert
@go run ./cmd/gqltool/main.go > ./internal/client/graphql/schema/introspection_query_result.json
@npm install --prefix internal/client/graphql/schema
@cd ./internal/client/graphql/schema && npm run convert

.PHONY: generate
generate:
Expand Down
16 changes: 7 additions & 9 deletions cmd/gqltool/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,27 +7,25 @@ import (
"log" // revive:disable-line
"os"

"github.com/stateful/runme/v3/internal/auth"
"github.com/stateful/runme/v3/internal/client"
"github.com/stateful/runme/v3/internal/client/graphql"
"github.com/stateful/runme/v3/internal/cmd"
"golang.org/x/oauth2"
)

var (
apiURL = flag.String("api-url", "https://api.stateful.com", "The API base address")
tokenDir = flag.String("token-dir", cmd.GetUserConfigHome(), "The directory with tokens")
apiURL = flag.String("api-url", "http://localhost:4000", "The API base address")
// tokenDir = flag.String("token-dir", cmd.GetUserConfigHome(), "The directory with tokens")
)

func init() {
flag.Parse()
}

func main() {
httpClient := client.NewHTTPClient(nil, client.WithTokenGetter(func() (string, error) {
a := auth.New(oauth2.Config{}, *apiURL, &auth.DiskStorage{Location: *tokenDir})
return a.GetToken(context.Background())
}))
// httpClient := client.NewHTTPClient(nil, client.WithTokenGetter(func() (string, error) {
// a := auth.New(oauth2.Config{}, *apiURL, &auth.DiskStorage{Location: *tokenDir})
// return a.GetToken(context.Background())
// }))
httpClient := client.NewHTTPClient(nil)
client, err := graphql.New(*apiURL+"/graphql", httpClient)
if err != nil {
log.Fatal(err)
Expand Down
2 changes: 1 addition & 1 deletion internal/auth/auth_mock_gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

39 changes: 0 additions & 39 deletions internal/client/graphql/client.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
package graphql

import (
"context"
"net/http"

"github.com/Khan/genqlient/graphql"
"github.com/stateful/runme/v3/internal/client/graphql/query"
)

//go:generate genqlient
Expand All @@ -19,40 +17,3 @@ func New(endpoint string, httpClient *http.Client) (*Client, error) {
Client: graphql.NewClient(endpoint, httpClient),
}, nil
}

func (c *Client) GetUser(ctx context.Context, withAnnotation bool) (result query.GetUserUser, _ error) {
trackInput := trackInputFromContext(ctx)
resp, err := query.GetUser(ctx, c.Client, withAnnotation, trackInput)
if err := NewAPIError(err, resp.Track.Errors); err != nil {
return result, err
}
return resp.User, nil
}

func (c *Client) GetSuggestedBranch(ctx context.Context, q query.SuggestedBranchInput) (result []string, _ error) {
trackInput := trackInputFromContext(ctx)
resp, err := query.GetSuggestedBranch(ctx, c.Client, q, trackInput)
if err != nil {
return nil, NewAPIError(err)
}

var names []string
for _, item := range resp.SuggestedBranchnames.Data {
names = append(names, item.Name)
}

return names, err
}

type ctxKey struct{}

var trackInputKey = &ctxKey{}

func ContextWithTrackInput(ctx context.Context, input query.TrackInput) context.Context {
return context.WithValue(ctx, trackInputKey, input)
}

func trackInputFromContext(ctx context.Context) query.TrackInput {
inpt, _ := ctx.Value(trackInputKey).(query.TrackInput)
return inpt
}
101 changes: 0 additions & 101 deletions internal/client/graphql/errors.go

This file was deleted.

91 changes: 0 additions & 91 deletions internal/client/graphql/errors_test.go

This file was deleted.

6 changes: 5 additions & 1 deletion internal/client/graphql/genqlient.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,12 @@ generated: ./query/generated.go
package: query
bindings:
DateTime:
type: github.com/stateful/runme/internal/client/graphql/schema/model.DateTime
type: github.com/stateful/runme/v3/internal/client/graphql/schema/model.DateTime
Date:
type: string
UUID:
type: string
Bytes:
type: string
JSON:
type: string
Loading

0 comments on commit 57248b0

Please sign in to comment.