From cfa012de44b74987653560296ac9571a385c31dd Mon Sep 17 00:00:00 2001 From: Paul Leitmanis Date: Mon, 4 Feb 2019 16:52:55 +1100 Subject: [PATCH] Enable websocket connection keepalive by default --- handler/graphql.go | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/handler/graphql.go b/handler/graphql.go index 8c83dc08e91..e5e1bccd9c4 100644 --- a/handler/graphql.go +++ b/handler/graphql.go @@ -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,