aboutsummaryrefslogtreecommitdiffstats
path: root/vendor/github.com/99designs/gqlgen/handler/websocket.go
diff options
context:
space:
mode:
authorMichael Muré <batolettre@gmail.com>2019-04-10 01:48:53 +0200
committerGitHub <noreply@github.com>2019-04-10 01:48:53 +0200
commit9722d7c9eca28b1710e50ac9075fd11d0db0606a (patch)
treee46d372dcd1e68fb067101778eb0a5f13f745ad0 /vendor/github.com/99designs/gqlgen/handler/websocket.go
parent30efc99f4493f3a09e94bf322cbf8ef844beea13 (diff)
parent4d14cadde45ac807afcbfd37200e86c4de6bf8db (diff)
downloadgit-bug-9722d7c9eca28b1710e50ac9075fd11d0db0606a.tar.gz
Merge pull request #123 from A-Hilaly/graphql
Upgrade gqlgen version to 0.8.3
Diffstat (limited to 'vendor/github.com/99designs/gqlgen/handler/websocket.go')
-rw-r--r--vendor/github.com/99designs/gqlgen/handler/websocket.go30
1 files changed, 25 insertions, 5 deletions
diff --git a/vendor/github.com/99designs/gqlgen/handler/websocket.go b/vendor/github.com/99designs/gqlgen/handler/websocket.go
index 09800c17..58f38e5d 100644
--- a/vendor/github.com/99designs/gqlgen/handler/websocket.go
+++ b/vendor/github.com/99designs/gqlgen/handler/websocket.go
@@ -12,6 +12,7 @@ import (
"github.com/99designs/gqlgen/graphql"
"github.com/gorilla/websocket"
+ "github.com/hashicorp/golang-lru"
"github.com/vektah/gqlparser"
"github.com/vektah/gqlparser/ast"
"github.com/vektah/gqlparser/gqlerror"
@@ -44,12 +45,13 @@ type wsConnection struct {
active map[string]context.CancelFunc
mu sync.Mutex
cfg *Config
+ cache *lru.Cache
keepAliveTicker *time.Ticker
initPayload InitPayload
}
-func connectWs(exec graphql.ExecutableSchema, w http.ResponseWriter, r *http.Request, cfg *Config) {
+func connectWs(exec graphql.ExecutableSchema, w http.ResponseWriter, r *http.Request, cfg *Config, cache *lru.Cache) {
ws, err := cfg.upgrader.Upgrade(w, r, http.Header{
"Sec-Websocket-Protocol": []string{"graphql-ws"},
})
@@ -65,6 +67,7 @@ func connectWs(exec graphql.ExecutableSchema, w http.ResponseWriter, r *http.Req
conn: ws,
ctx: r.Context(),
cfg: cfg,
+ cache: cache,
}
if !conn.init() {
@@ -176,10 +179,27 @@ func (c *wsConnection) subscribe(message *operationMessage) bool {
return false
}
- doc, qErr := gqlparser.LoadQuery(c.exec.Schema(), reqParams.Query)
- if qErr != nil {
- c.sendError(message.ID, qErr...)
- return true
+ var (
+ doc *ast.QueryDocument
+ cacheHit bool
+ )
+ if c.cache != nil {
+ val, ok := c.cache.Get(reqParams.Query)
+ if ok {
+ doc = val.(*ast.QueryDocument)
+ cacheHit = true
+ }
+ }
+ if !cacheHit {
+ var qErr gqlerror.List
+ doc, qErr = gqlparser.LoadQuery(c.exec.Schema(), reqParams.Query)
+ if qErr != nil {
+ c.sendError(message.ID, qErr...)
+ return true
+ }
+ if c.cache != nil {
+ c.cache.Add(reqParams.Query, doc)
+ }
}
op := doc.Operations.ForName(reqParams.OperationName)