Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added GraphQL server #534

Draft
wants to merge 35 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
58e553d
Added GraphQL server
oxisto Dec 27, 2024
72e3ba0
Migrating first clients to graphQL
oxisto Dec 27, 2024
b2f8e81
Ignore gqlgen generated files for introspection for coverage
oxisto Dec 27, 2024
e854bb0
Compiles, but tests fail
oxisto Dec 27, 2024
43fcb2a
Fixed some tests
oxisto Dec 27, 2024
bf36e8d
Fixed tests
oxisto Dec 27, 2024
e23afdd
Added tools dependencies
oxisto Dec 27, 2024
fc24b4a
++
oxisto Dec 27, 2024
95a1589
More testing, more graphql
oxisto Dec 27, 2024
04d251e
Adding portfolio, breaking everything
oxisto Dec 28, 2024
b741b3e
++
oxisto Dec 28, 2024
8e0d223
Converting++
oxisto Dec 29, 2024
fd87d22
First test in persistence works
oxisto Jan 1, 2025
3f4ce6d
Package securities/quote also tests
oxisto Jan 1, 2025
309aaa7
CSV package works
oxisto Jan 1, 2025
b10069c
package finance test works
oxisto Jan 1, 2025
14af0db
More graphql conversion
oxisto Jan 1, 2025
93f9bff
Triggering quotes
oxisto Jan 2, 2025
5d7b77a
More test are ok
oxisto Jan 4, 2025
62a2174
more tests ok
oxisto Jan 5, 2025
fd849da
All tests work
oxisto Jan 5, 2025
6e426d4
Create accounts
oxisto Jan 5, 2025
916c1f8
Removed connect
oxisto Jan 5, 2025
b1fff5c
Creating account works
oxisto Jan 6, 2025
4e31bea
Using stringer
oxisto Jan 6, 2025
e81a55c
new internal enum package
oxisto Jan 6, 2025
5c4a389
Create and list accounts
oxisto Jan 6, 2025
59233df
Delete account works
oxisto Jan 6, 2025
448b2fa
Fixed test
oxisto Jan 6, 2025
94e7bfa
Added transactions
oxisto Jan 7, 2025
0efdc9b
Implemented more portfolio
oxisto Jan 12, 2025
a09bfa2
More unit tests
oxisto Jan 12, 2025
2627c27
Fixed tests
oxisto Jan 12, 2025
e232cc2
Create transaction works but some other test fails
oxisto Jan 13, 2025
e68319e
Fixed unit tests
oxisto Jan 13, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .codecov.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
ignore:
- "**/*.pb.go" # ignore protoc generated files
- "**/*.connect.go" # ignore connect-go generated files
- "graph/generated.go" # ignore gqlgen generated files for introspection
coverage:
range: "70...85"
status:
Expand Down
14 changes: 8 additions & 6 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,22 +16,24 @@ jobs:
uses: actions/setup-go@v5
with:
go-version-file: go.mod
cache-dependency-path: "**/*.sum"
- name: Set up node.js
uses: actions/setup-node@v4
with:
node-version: 23
- name: Set up buf
uses: bufbuild/[email protected]
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
- name: Set up tools
run: |
go install github.com/mfridman/tparse
go install github.com/sqlc-dev/sqlc/cmd/sqlc
go install github.com/99designs/gqlgen
go install golang.org/x/tools/cmd/stringer
working-directory: ./tools
- name: Build Backend
run: |
go install github.com/sqlc-dev/sqlc/cmd/sqlc@latest
go generate ./...
go build -v ./...
- name: Test Backend
run: |
go install github.com/mfridman/tparse@latest
go test -v -coverprofile=coverage.cov -coverpkg ./... -covermode=atomic ./... -json | tee output.json | tparse -follow || true
tparse -format markdown -file output.json > $GITHUB_STEP_SUMMARY
- name: Upload coverage reports to Codecov
Expand Down
10 changes: 0 additions & 10 deletions buf.gen.yaml

This file was deleted.

8 changes: 0 additions & 8 deletions buf.lock

This file was deleted.

6 changes: 0 additions & 6 deletions buf.openapi.gen.yaml

This file was deleted.

10 changes: 0 additions & 10 deletions buf.yaml

This file was deleted.

45 changes: 12 additions & 33 deletions cli/cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,12 @@ import (
"context"
"encoding/json"
"fmt"
"log/slog"
"io"
"net/http"
"os"

"github.com/oxisto/money-gopher/gen/portfoliov1connect"
"github.com/shurcooL/graphql"

"connectrpc.com/connect"
"github.com/lmittmann/tint"
oauth2 "github.com/oxisto/oauth2go"
"github.com/urfave/cli/v3"
)
Expand All @@ -40,8 +38,7 @@ var SessionKey sessionKeyType

// Session holds all necessary information about the current CLI session.
type Session struct {
PortfolioClient portfoliov1connect.PortfolioServiceClient `json:"-"`
SecuritiesClient portfoliov1connect.SecuritiesServiceClient `json:"-"`
GraphQL *graphql.Client

opts *SessionOptions
}
Expand Down Expand Up @@ -78,6 +75,9 @@ func (opts *SessionOptions) MergeWith(other *SessionOptions) *SessionOptions {
// DefaultBaseURL is the default base URL for all services.
const DefaultBaseURL = "http://localhost:8080"

// DefaultGraphURL is the default URL for the GraphQL service.
const DefaultGraphURL = "http://localhost:9090/graphql"

// NewSession creates a new session.
func NewSession(opts *SessionOptions) (s *Session) {
def := &SessionOptions{
Expand Down Expand Up @@ -138,38 +138,17 @@ func (s *Session) Save() (err error) {

// initClients initializes the clients for the session.
func (s *Session) initClients() {
interceptor := func(next connect.UnaryFunc) connect.UnaryFunc {
return connect.UnaryFunc(func(
ctx context.Context,
req connect.AnyRequest,
) (connect.AnyResponse, error) {
if req.Spec().IsClient {
var t, err = s.opts.OAuth2Config.TokenSource(context.Background(), s.opts.Token).Token()
if err != nil {
slog.Error("Could not retrieve token", tint.Err(err))
} else {
req.Header().Set("Authorization", "Bearer "+t.AccessToken)
}
}
return next(ctx, req)
})
}

if s.opts.HttpClient == nil {
s.opts.HttpClient = http.DefaultClient
}

s.PortfolioClient = portfoliov1connect.NewPortfolioServiceClient(
s.opts.HttpClient, s.opts.BaseURL,
connect.WithHTTPGet(),
connect.WithInterceptors(connect.UnaryInterceptorFunc(interceptor)),
)
s.GraphQL = graphql.NewClient(s.opts.BaseURL+"/graphql/query", s.opts.HttpClient)
}

s.SecuritiesClient = portfoliov1connect.NewSecuritiesServiceClient(
s.opts.HttpClient, s.opts.BaseURL,
connect.WithHTTPGet(),
connect.WithInterceptors(connect.UnaryInterceptorFunc(interceptor)),
)
func (s *Session) WriteJSON(w io.Writer, v any) {
enc := json.NewEncoder(w)
enc.SetIndent("", " ")
enc.Encode(v)
}

// FromContext extracts the session from the context.
Expand Down
Loading
Loading