diff options
author | Michael Muré <batolettre@gmail.com> | 2019-04-10 01:48:53 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-04-10 01:48:53 +0200 |
commit | 9722d7c9eca28b1710e50ac9075fd11d0db0606a (patch) | |
tree | e46d372dcd1e68fb067101778eb0a5f13f745ad0 /vendor/github.com/99designs/gqlgen/handler/websocket.go | |
parent | 30efc99f4493f3a09e94bf322cbf8ef844beea13 (diff) | |
parent | 4d14cadde45ac807afcbfd37200e86c4de6bf8db (diff) | |
download | git-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.go | 30 |
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) |