aboutsummaryrefslogtreecommitdiffstats
path: root/vendor/github.com/99designs/gqlgen/handler/context.go
diff options
context:
space:
mode:
authorMichael Muré <batolettre@gmail.com>2018-12-23 17:11:37 +0100
committerMichael Muré <batolettre@gmail.com>2018-12-23 17:11:37 +0100
commit1410a1af75b1ab9ea3f980a7e372728f9a123abf (patch)
treee24db8f84c48b20158b1f1fd6d281d700421279c /vendor/github.com/99designs/gqlgen/handler/context.go
parent8fc15a032f021c855abf66ed303c003d57c340ea (diff)
downloadgit-bug-1410a1af75b1ab9ea3f980a7e372728f9a123abf.tar.gz
upgrade gqlgen to v0.7.1
Diffstat (limited to 'vendor/github.com/99designs/gqlgen/handler/context.go')
-rw-r--r--vendor/github.com/99designs/gqlgen/handler/context.go57
1 files changed, 57 insertions, 0 deletions
diff --git a/vendor/github.com/99designs/gqlgen/handler/context.go b/vendor/github.com/99designs/gqlgen/handler/context.go
new file mode 100644
index 00000000..2992aa3d
--- /dev/null
+++ b/vendor/github.com/99designs/gqlgen/handler/context.go
@@ -0,0 +1,57 @@
+package handler
+
+import "context"
+
+type key string
+
+const (
+ initpayload key = "ws_initpayload_context"
+)
+
+// InitPayload is a structure that is parsed from the websocket init message payload. TO use
+// request headers for non-websocket, instead wrap the graphql handler in a middleware.
+type InitPayload map[string]interface{}
+
+// GetString safely gets a string value from the payload. It returns an empty string if the
+// payload is nil or the value isn't set.
+func (payload InitPayload) GetString(key string) string {
+ if payload == nil {
+ return ""
+ }
+
+ if value, ok := payload[key]; ok {
+ res, _ := value.(string)
+ return res
+ }
+
+ return ""
+}
+
+// Authorization is a short hand for getting the Authorization header from the
+// payload.
+func (payload InitPayload) Authorization() string {
+ if value := payload.GetString("Authorization"); value != "" {
+ return value
+ }
+
+ if value := payload.GetString("authorization"); value != "" {
+ return value
+ }
+
+ return ""
+}
+
+func withInitPayload(ctx context.Context, payload InitPayload) context.Context {
+ return context.WithValue(ctx, initpayload, payload)
+}
+
+// GetInitPayload gets a map of the data sent with the connection_init message, which is used by
+// graphql clients as a stand-in for HTTP headers.
+func GetInitPayload(ctx context.Context) InitPayload {
+ payload, ok := ctx.Value(initpayload).(InitPayload)
+ if !ok {
+ return nil
+ }
+
+ return payload
+}