File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 11package database
22
33import (
4- "context"
54 "encoding/json"
65 "fmt"
76 "github.com/hasura/go-graphql-client"
87 "go.uber.org/zap"
9- "golang.org/x/oauth2 "
8+ "net/http "
109 "time"
1110)
1211
@@ -27,13 +26,15 @@ type GraphqlSubscriptionClient struct {
2726}
2827
2928func NewGraphqlQueryClient (host string , token string ) GraphqlClient {
30- src := oauth2 .StaticTokenSource (
31- & oauth2.Token {AccessToken : token },
32- )
33- httpClient := oauth2 .NewClient (context .Background (), src )
29+ transport := http .DefaultTransport
30+ if token != "" {
31+ transport = AuthHeaderTransport {Transport : http .DefaultTransport , Token : token }
32+ }
33+
34+ customHttpClient := http.Client {Transport : transport }
3435 return GraphqlClient {
3536 Host : host ,
36- Client : graphql .NewClient (host , httpClient ),
37+ Client : graphql .NewClient (host , & customHttpClient ),
3738 }
3839}
3940
Original file line number Diff line number Diff line change @@ -3,8 +3,19 @@ package database
33import (
44 "fmt"
55 "gorm.io/gorm"
6+ "net/http"
67)
78
9+ type AuthHeaderTransport struct {
10+ Transport http.RoundTripper
11+ Token string
12+ }
13+
14+ func (adt AuthHeaderTransport ) RoundTrip (req * http.Request ) (* http.Response , error ) {
15+ req .Header .Add ("x-hasura-admin-secret" , adt .Token )
16+ return adt .Transport .RoundTrip (req )
17+ }
18+
819type DBConnection interface {
920 GetDB () * gorm.DB
1021}
Original file line number Diff line number Diff line change @@ -13,7 +13,6 @@ require (
1313 github.com/spf13/cobra v1.1.1
1414 github.com/spf13/viper v1.7.1
1515 go.uber.org/zap v1.16.0
16- golang.org/x/oauth2 v0.0.0-20190604053449-0f29369cfe45
1716 gorm.io/driver/postgres v1.0.6
1817 gorm.io/gorm v1.21.12
1918)
Original file line number Diff line number Diff line change @@ -635,7 +635,6 @@ golang.org/x/net v0.0.0-20201110031124-69a78807bb2b h1:uwuIcX0g4Yl1NC5XAz37xsr2l
635635golang.org/x/net v0.0.0-20201110031124-69a78807bb2b /go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU =
636636golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be /go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U =
637637golang.org/x/oauth2 v0.0.0-20190226205417-e64efc72b421 /go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw =
638- golang.org/x/oauth2 v0.0.0-20190604053449-0f29369cfe45 h1:SVwTIAaPC2U/AvvLNZ2a7OVsmBpC8L5BlwK1whH3hm0 =
639638golang.org/x/oauth2 v0.0.0-20190604053449-0f29369cfe45 /go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw =
640639golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f /go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM =
641640golang.org/x/sync v0.0.0-20181108010431-42b317875d0f /go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM =
@@ -733,7 +732,6 @@ google.golang.org/api v0.13.0/go.mod h1:iLdEw5Ide6rF15KTC1Kkl0iskquN2gFfn9o9XIsb
733732google.golang.org/appengine v1.1.0 /go.mod h1:EbEs0AVv82hx2wNQdGPgUI5lhzA/G0D9YwlJXL52JkM =
734733google.golang.org/appengine v1.4.0 /go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7/EB5XEv4 =
735734google.golang.org/appengine v1.5.0 /go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7/EB5XEv4 =
736- google.golang.org/appengine v1.6.1 h1:QzqyMA1tlu6CgqCDUtU9V+ZKhLFT2dkJuANu5QaxI3I =
737735google.golang.org/appengine v1.6.1 /go.mod h1:i06prIuMbXzDqacNJfV5OdTW448YApPu5ww/cMBSeb0 =
738736google.golang.org/genproto v0.0.0-20180817151627-c66870c02cf8 /go.mod h1:JiN7NxoALGmiZfu7CAH4rXhgtRTLTxftemlI0sWmxmc =
739737google.golang.org/genproto v0.0.0-20190307195333-5fe7a883aa19 /go.mod h1:VzzqZJRnGkLBvHegQrXjBqPurQTc5/KpmUdxsrq26oE =
You can’t perform that action at this time.
0 commit comments