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

add configuration for graphql server port #620

Merged
merged 1 commit into from
Jun 28, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
5 changes: 3 additions & 2 deletions gql/dummy.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,10 @@ import (
const DummyDealsDir = "/tmp/dummy"
const DummyDealsPrefix = "dummy"

var DummyDealsBase = fmt.Sprintf("http://localhost:%d/"+DummyDealsPrefix, httpPort)
var DummyDealsBase string

func serveDummyDeals(mux *http.ServeMux) error {
func serveDummyDeals(mux *http.ServeMux, port int) error {
DummyDealsBase = fmt.Sprintf("http://localhost:%d/"+DummyDealsPrefix, port)
dpath := "/" + DummyDealsPrefix + "/"
if err := os.MkdirAll(DummyDealsDir, 0755); err != nil {
return fmt.Errorf("failed to mk directory %s for dummy deals: %w", DummyDealsDir, err)
Expand Down
5 changes: 3 additions & 2 deletions gql/dummy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,10 @@ func TestDummyServer(t *testing.T) {
ctx := context.Background()

mux := http.NewServeMux()
listenAddr := fmt.Sprintf(":%d", httpPort)
port := 8080
listenAddr := fmt.Sprintf(":%d", port)
t.Logf("server listening on %s\n", listenAddr)
err := serveDummyDeals(mux)
err := serveDummyDeals(mux, port)
rq.NoError(err)

srv := &http.Server{Addr: listenAddr, Handler: mux}
Expand Down
9 changes: 4 additions & 5 deletions gql/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@ import (

var log = logging.Logger("gql")

const httpPort = 8080

type Server struct {
resolver *resolver
srv *http.Server
Expand All @@ -47,13 +45,14 @@ func (s *Server) Start(ctx context.Context) error {
}

// Serve dummy deals
err = serveDummyDeals(mux)
port := int(s.resolver.cfg.Graphql.Port)
err = serveDummyDeals(mux, port)
if err != nil {
return err
}

// GraphQL handler (GUI for making GraphQL queries)
mux.HandleFunc("/graphiql", graphiql(httpPort))
mux.HandleFunc("/graphiql", graphiql(port))

// Allow resolving directly to fields (instead of requiring resolvers to
// have a method for every GraphQL field)
Expand All @@ -73,7 +72,7 @@ func (s *Server) Start(ctx context.Context) error {
}
wsHandler := graphqlws.NewHandlerFunc(schema, queryHandler, wsOpts...)

listenAddr := fmt.Sprintf(":%d", httpPort)
listenAddr := fmt.Sprintf(":%d", port)
s.srv = &http.Server{Addr: listenAddr, Handler: mux}
fmt.Printf("Graphql server listening on %s\n", listenAddr)
mux.Handle("/graphql/subscription", &corsHandler{wsHandler})
Expand Down
4 changes: 4 additions & 0 deletions node/config/def.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,10 @@ func DefaultBoost() *Boost {
ParallelFetchLimit: 10,
},

Graphql: GraphqlConfig{
Port: 8080,
},

Dealmaking: DealmakingConfig{
ConsiderOnlineStorageDeals: true,
ConsiderOfflineStorageDeals: true,
Expand Down
14 changes: 14 additions & 0 deletions node/config/doc_gen.go

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

6 changes: 6 additions & 0 deletions node/config/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ type Boost struct {
SectorIndexApiInfo string
Dealmaking DealmakingConfig
Wallets WalletsConfig
Graphql GraphqlConfig

// Lotus configs
LotusDealmaking lotus_config.DealmakingConfig
Expand Down Expand Up @@ -69,6 +70,11 @@ type WalletsConfig struct {
PledgeCollateral string
}

type GraphqlConfig struct {
// The port that the graphql server listens on
Port uint64
}

type LotusDealmakingConfig struct {
// A list of Data CIDs to reject when making deals
PieceCidBlocklist []cid.Cid
Expand Down