package main import ( "net/http" "tercul/graph" "github.com/99designs/gqlgen/graphql/handler" "github.com/99designs/gqlgen/graphql/handler/extension" "github.com/99designs/gqlgen/graphql/handler/lru" "github.com/99designs/gqlgen/graphql/handler/transport" "github.com/99designs/gqlgen/graphql/playground" "github.com/vektah/gqlparser/v2/ast" ) const defaultPort = "8080" // SetupGraphQLServer configures and returns a GraphQL server with the provided resolver func SetupGraphQLServer(resolver *graph.Resolver) *handler.Server { srv := handler.New(graph.NewExecutableSchema(graph.Config{Resolvers: resolver})) srv.AddTransport(transport.Options{}) srv.AddTransport(transport.GET{}) srv.AddTransport(transport.POST{}) srv.SetQueryCache(lru.New[*ast.QueryDocument](1000)) srv.Use(extension.Introspection{}) srv.Use(extension.AutomaticPersistedQuery{ Cache: lru.New[string](100), }) return srv } // SetupHTTPHandlers configures HTTP routes for the GraphQL playground and API func SetupHTTPHandlers(srv *handler.Server, queryPath string) { http.Handle("/", playground.Handler("GraphQL playground", queryPath)) http.Handle(queryPath, srv) }