Skip to content

Commit

Permalink
Export GetGraphqlServer and accept initialized backend
Browse files Browse the repository at this point in the history
Signed-off-by: robert-cronin <[email protected]>
  • Loading branch information
robert-cronin committed Oct 31, 2024
1 parent 094a31a commit 76a6143
Showing 1 changed file with 7 additions and 13 deletions.
20 changes: 7 additions & 13 deletions cmd/guacgql/cmd/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,12 +79,14 @@ func startServer(cmd *cobra.Command) {
os.Exit(1)
}

srv, err := getGraphqlServer(ctx)
backend, err := backends.Get(flags.backend, ctx, getOpts[flags.backend](ctx))
if err != nil {
logger.Errorf("unable to initialize graphql server: %v", err)
logger.Errorf("error creating %v backend: %w", flags.backend, err)
os.Exit(1)
}

srv := GetGraphqlServer(ctx, backend)

metric, err := setupPrometheus(ctx, "guacgql")
if err != nil {
logger.Fatalf("Error setting up Prometheus: %v", err)
Expand Down Expand Up @@ -172,20 +174,12 @@ func validateFlags() error {
return nil
}

func getGraphqlServer(ctx context.Context) (*handler.Server, error) {
var topResolver resolvers.Resolver

backend, err := backends.Get(flags.backend, ctx, getOpts[flags.backend](ctx))
if err != nil {
return nil, fmt.Errorf("Error creating %v backend: %w", flags.backend, err)
}
topResolver = resolvers.Resolver{Backend: backend}

func GetGraphqlServer(ctx context.Context, backend backends.Backend) *handler.Server {
topResolver := resolvers.Resolver{Backend: backend}
config := generated.Config{Resolvers: &topResolver}
config.Directives.Filter = resolvers.Filter
srv := handler.NewDefaultServer(generated.NewExecutableSchema(config))

return srv, nil
return srv
}

func healthHandler(w http.ResponseWriter, r *http.Request) {
Expand Down

0 comments on commit 76a6143

Please sign in to comment.