diff --git a/go.mod b/go.mod index cac0c04d2a1..94c160d7fd8 100644 --- a/go.mod +++ b/go.mod @@ -21,7 +21,7 @@ require ( github.com/dgraph-io/dgo/v210 v210.0.0-20210407152819-261d1c2a6987 github.com/dgraph-io/gqlgen v0.13.2 github.com/dgraph-io/gqlparser/v2 v2.2.0 - github.com/dgraph-io/graphql-transport-ws v0.0.0-20210223074046-e5b8b80bb4ed + github.com/dgraph-io/graphql-transport-ws v0.0.0-20210511143556-2cef522f1f15 github.com/dgraph-io/ristretto v0.0.4-0.20210504190834-0bf2acd73aa3 github.com/dgraph-io/roaring v0.5.6-0.20210227175938-766b897233a5 github.com/dgraph-io/simdjson-go v0.3.0 @@ -43,7 +43,6 @@ require ( github.com/google/uuid v1.0.0 github.com/gorilla/websocket v1.4.2 github.com/graph-gophers/graphql-go v0.0.0-20200309224638-dae41bde9ef9 - github.com/graph-gophers/graphql-transport-ws v0.0.0-20190611222414-40c048432299 // indirect github.com/hashicorp/vault/api v1.0.4 github.com/minio/minio-go/v6 v6.0.55 github.com/mitchellh/panicwrap v1.0.0 diff --git a/go.sum b/go.sum index 155eefee4d2..008ca062ef9 100644 --- a/go.sum +++ b/go.sum @@ -129,8 +129,8 @@ github.com/dgraph-io/gqlgen v0.13.2/go.mod h1:iCOrOv9lngN7KAo+jMgvUPVDlYHdf7qDws github.com/dgraph-io/gqlparser/v2 v2.1.1/go.mod h1:MYS4jppjyx8b9tuUtjV7jU1UFZK6P9fvO8TsIsQtRKU= github.com/dgraph-io/gqlparser/v2 v2.2.0 h1:fKSCW8OxoMogjDwUhO9OrFvrgIA0UZspTDbcm0QGk9M= github.com/dgraph-io/gqlparser/v2 v2.2.0/go.mod h1:MYS4jppjyx8b9tuUtjV7jU1UFZK6P9fvO8TsIsQtRKU= -github.com/dgraph-io/graphql-transport-ws v0.0.0-20210223074046-e5b8b80bb4ed h1:pgGMBoTtFhR+xkyzINaToLYRurHn+6pxMYffIGmmEPc= -github.com/dgraph-io/graphql-transport-ws v0.0.0-20210223074046-e5b8b80bb4ed/go.mod h1:7z3c/5w0sMYYZF5bHsrh8IH4fKwG5O5Y70cPH1ZLLRQ= +github.com/dgraph-io/graphql-transport-ws v0.0.0-20210511143556-2cef522f1f15 h1:X2NRsgAtVUAp2nmTPCq+x+wTcRRrj74CEpy7E0Unsl4= +github.com/dgraph-io/graphql-transport-ws v0.0.0-20210511143556-2cef522f1f15/go.mod h1:7z3c/5w0sMYYZF5bHsrh8IH4fKwG5O5Y70cPH1ZLLRQ= github.com/dgraph-io/ristretto v0.0.4-0.20210504190834-0bf2acd73aa3 h1:jU/wpYsEL+8JPLf/QcjkQKI5g0dOjSuwcMjkThxt5x0= github.com/dgraph-io/ristretto v0.0.4-0.20210504190834-0bf2acd73aa3/go.mod h1:fux0lOrBhrVCJd3lcTHsIJhq1T2rokOu6v9Vcb3Q9ug= github.com/dgraph-io/roaring v0.5.6-0.20210227175938-766b897233a5 h1:9t3OKcvsQlxU9Cu0U55tgvNtaRYVGDr6rUb95P8cSbg= @@ -279,8 +279,6 @@ github.com/gorilla/websocket v1.4.2 h1:+/TMaTYc4QFitKJxsQ7Yye35DkWvkdLcvGKqM+x0U github.com/gorilla/websocket v1.4.2/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE= github.com/graph-gophers/graphql-go v0.0.0-20200309224638-dae41bde9ef9 h1:kLnsdud6Fl1/7ZX/5oD23cqYAzBfuZBhNkGr2NvuEsU= github.com/graph-gophers/graphql-go v0.0.0-20200309224638-dae41bde9ef9/go.mod h1:9CQHMSxwO4MprSdzoIEobiHpoLtHm77vfxsvsIN5Vuc= -github.com/graph-gophers/graphql-transport-ws v0.0.0-20190611222414-40c048432299 h1:BdXUpuP9yOGKcwD/mhhZ+6EeAmrPrAQA3yeq4YEOHL4= -github.com/graph-gophers/graphql-transport-ws v0.0.0-20190611222414-40c048432299/go.mod h1:mA6VjyefgI7zd37tC3zopb51mW39gSfnEoWvtnxsqKQ= github.com/grpc-ecosystem/go-grpc-middleware v1.0.0/go.mod h1:FiyG127CGDf3tlThmgyCl78X/SZQqEOJBCDaAfeWzPs= github.com/grpc-ecosystem/go-grpc-middleware v1.0.1-0.20190118093823-f849b5445de4/go.mod h1:FiyG127CGDf3tlThmgyCl78X/SZQqEOJBCDaAfeWzPs= github.com/grpc-ecosystem/go-grpc-prometheus v1.2.0/go.mod h1:8NvIoxWQoOIhqOTXgfV/d3M/q6VIi02HzZEHgUlZvzk= diff --git a/graphql/admin/http.go b/graphql/admin/http.go index c53c46d8328..031767b6b72 100644 --- a/graphql/admin/http.go +++ b/graphql/admin/http.go @@ -158,10 +158,10 @@ func (gs *graphqlSubscription) Subscribe( variableValues map[string]interface{}) (payloads <-chan interface{}, err error) { + reqHeader := http.Header{} // library (graphql-transport-ws) passes the headers which are part of the INIT payload to us // in the context. We are extracting those headers and passing them along. headerPayload, _ := ctx.Value("Header").(json.RawMessage) - reqHeader := http.Header{} if len(headerPayload) > 0 { headers := make(map[string]interface{}) if err = json.Unmarshal(headerPayload, &headers); err != nil { @@ -175,6 +175,19 @@ func (gs *graphqlSubscription) Subscribe( } } + // Earlier the graphql-transport-ws library was ignoring the http headers in the request. + // The library was relying upon the information present in the request payload. This was + // blocker for the cloud team because the only control cloud has is over the HTTP headers. + // This fix ensures that we are setting the request headers if not provided in the payload. + httpHeaders, _ := ctx.Value("RequestHeader").(http.Header) + if len(httpHeaders) > 0 { + for k := range httpHeaders { + if len(strings.TrimSpace(reqHeader.Get(k))) == 0 { + reqHeader.Set(k, httpHeaders.Get(k)) + } + } + } + req := &schema.Request{ OperationName: operationName, Query: document, @@ -182,7 +195,11 @@ func (gs *graphqlSubscription) Subscribe( Header: reqHeader, } namespace := x.ExtractNamespaceHTTP(&http.Request{Header: reqHeader}) - LazyLoadSchema(namespace) // first load the schema, then do anything else + glog.Infof("namespace: %d. Got GraphQL request over websocket.", namespace) + // first load the schema, then do anything else + if err = LazyLoadSchema(namespace); err != nil { + return nil, err + } if err = gs.isValid(namespace); err != nil { glog.Errorf("namespace: %d. graphqlSubscription not initialized: %s", namespace, err) return nil, errors.New(resolve.ErrInternal) @@ -220,6 +237,7 @@ func (gh *graphqlHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) { defer span.End() ns, _ := strconv.ParseUint(r.Header.Get("resolver"), 10, 64) + glog.Infof("namespace: %d. Got GraphQL request over HTTP.", ns) if err := gh.isValid(ns); err != nil { glog.Errorf("namespace: %d. graphqlHandler not initialised: %s", ns, err) WriteErrorResponse(w, r, errors.New(resolve.ErrInternal))