Skip to content

Commit

Permalink
Revert 1595 (#1658)
Browse files Browse the repository at this point in the history
Signed-off-by: Steve Coffman <[email protected]>
  • Loading branch information
StevenACoffman authored Oct 13, 2021
1 parent 8359f97 commit 41c8676
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 12 deletions.
2 changes: 1 addition & 1 deletion docs/content/recipes/cors.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ func main() {

srv := handler.NewDefaultServer(starwars.NewExecutableSchema(starwars.NewResolver()))
srv.AddTransport(&transport.Websocket{
Upgrader: &websocket.Upgrader{
Upgrader: websocket.Upgrader{
CheckOrigin: func(r *http.Request) bool {
// Check against your desired domains here
return r.Host == "example.org"
Expand Down
2 changes: 1 addition & 1 deletion example/chat/server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ func main() {
srv.AddTransport(transport.POST{})
srv.AddTransport(transport.Websocket{
KeepAlivePingInterval: 10 * time.Second,
Upgrader: &websocket.Upgrader{
Upgrader: websocket.Upgrader{
CheckOrigin: func(r *http.Request) bool {
return true
},
Expand Down
10 changes: 2 additions & 8 deletions graphql/handler/transport/websocket.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ const (

type (
Websocket struct {
Upgrader WebsocketUpgrader
Upgrader websocket.Upgrader
InitFunc WebsocketInitFunc
KeepAlivePingInterval time.Duration
}
Expand All @@ -52,16 +52,10 @@ type (
ID string `json:"id,omitempty"`
Type string `json:"type"`
}
WebsocketUpgrader interface {
Upgrade(w http.ResponseWriter, r *http.Request, responseHeader http.Header) (*websocket.Conn, error)
}
WebsocketInitFunc func(ctx context.Context, initPayload InitPayload) (context.Context, error)
)

var (
_ graphql.Transport = Websocket{}
_ WebsocketUpgrader = &websocket.Upgrader{}
)
var _ graphql.Transport = Websocket{}

func (t Websocket) Supports(r *http.Request) bool {
return r.Header.Get("Upgrade") != ""
Expand Down
5 changes: 3 additions & 2 deletions handler/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"github.com/99designs/gqlgen/graphql/handler/lru"
"github.com/99designs/gqlgen/graphql/handler/transport"
"github.com/99designs/gqlgen/graphql/playground"
"github.com/gorilla/websocket"
)

// Deprecated: switch to graphql/handler.New
Expand Down Expand Up @@ -73,7 +74,7 @@ func GraphQL(exec graphql.ExecutableSchema, options ...Option) http.HandlerFunc
// Deprecated: switch to graphql/handler.New
type Config struct {
cacheSize int
upgrader transport.WebsocketUpgrader
upgrader websocket.Upgrader
websocketInitFunc transport.WebsocketInitFunc
connectionKeepAlivePingInterval time.Duration
recover graphql.RecoverFunc
Expand All @@ -92,7 +93,7 @@ type Config struct {
type Option func(cfg *Config)

// Deprecated: switch to graphql/handler.New
func WebsocketUpgrader(upgrader transport.WebsocketUpgrader) Option {
func WebsocketUpgrader(upgrader websocket.Upgrader) Option {
return func(cfg *Config) {
cfg.upgrader = upgrader
}
Expand Down

0 comments on commit 41c8676

Please sign in to comment.