Skip to content

Commit

Permalink
Enable websocket connection keepalive by default
Browse files Browse the repository at this point in the history
  • Loading branch information
sinamt committed Feb 5, 2019
1 parent c5b9b5a commit cfa012d
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions handler/graphql.go
Original file line number Diff line number Diff line change
Expand Up @@ -241,19 +241,23 @@ func CacheSize(size int) Option {
}
}

const DefaultCacheSize = 1000

// WebsocketKeepAliveDuration allows you to reconfigure the keepAlive behavior.
// By default, keep-alive is disabled.
// WebsocketKeepAliveDuration allows you to reconfigure the keepalive behavior.
// By default, keepalive is enabled with a DefaultConnectionKeepAlivePingInterval
// duration. Set handler.connectionKeepAlivePingInterval = 0 to disable keepalive
// altogether.
func WebsocketKeepAliveDuration(duration time.Duration) Option {
return func(cfg *Config) {
cfg.connectionKeepAlivePingInterval = duration
}
}

const DefaultCacheSize = 1000
const DefaultConnectionKeepAlivePingInterval = 25 * time.Second

func GraphQL(exec graphql.ExecutableSchema, options ...Option) http.HandlerFunc {
cfg := &Config{
cacheSize: DefaultCacheSize,
cacheSize: DefaultCacheSize,
connectionKeepAlivePingInterval: DefaultConnectionKeepAlivePingInterval,
upgrader: websocket.Upgrader{
ReadBufferSize: 1024,
WriteBufferSize: 1024,
Expand Down

0 comments on commit cfa012d

Please sign in to comment.