Skip to content

Commit

Permalink
feat: allow all origins
Browse files Browse the repository at this point in the history
  • Loading branch information
amimart committed Aug 12, 2022
1 parent 8af5a40 commit d9ef2e8
Showing 1 changed file with 35 additions and 2 deletions.
37 changes: 35 additions & 2 deletions internal/server/router.go
Original file line number Diff line number Diff line change
@@ -1,13 +1,20 @@
package server

import (
"net/http"
"okp4/cosmos-faucet/graph"
"okp4/cosmos-faucet/graph/generated"
"okp4/cosmos-faucet/internal/server/handlers"
"okp4/cosmos-faucet/pkg/captcha"
"time"

graphql "github.com/99designs/gqlgen/graphql/handler"
"github.com/99designs/gqlgen/graphql"
graphqlserver "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/gorilla/websocket"
)

func (s *httpServer) createRoutes(config Config) {
Expand All @@ -16,7 +23,7 @@ func (s *httpServer) createRoutes(config Config) {
Methods("GET")
s.router.Path("/graphql").
Handler(
graphql.NewDefaultServer(
newGraphQLServer(
generated.NewExecutableSchema(generated.Config{
Resolvers: &graph.Resolver{
Faucet: config.Faucet,
Expand All @@ -37,3 +44,29 @@ func (s *httpServer) createRoutes(config Config) {
Methods("GET")
}
}

func newGraphQLServer(schema graphql.ExecutableSchema) http.Handler {
srv := graphqlserver.New(schema)

srv.AddTransport(transport.Websocket{
KeepAlivePingInterval: 10 * time.Second,
Upgrader: websocket.Upgrader{
CheckOrigin: func(r *http.Request) bool {
return true
},
},
})
srv.AddTransport(transport.Options{})
srv.AddTransport(transport.GET{})
srv.AddTransport(transport.POST{})
srv.AddTransport(transport.MultipartForm{})

srv.SetQueryCache(lru.New(1000))

srv.Use(extension.Introspection{})
srv.Use(extension.AutomaticPersistedQuery{
Cache: lru.New(100),
})

return srv
}

0 comments on commit d9ef2e8

Please sign in to comment.