github.com/99designs/gqlgen@v0.17.45/client/options.go (about) 1 package client 2 3 import "net/http" 4 5 // Var adds a variable into the outgoing request 6 func Var(name string, value interface{}) Option { 7 return func(bd *Request) { 8 if bd.Variables == nil { 9 bd.Variables = map[string]interface{}{} 10 } 11 12 bd.Variables[name] = value 13 } 14 } 15 16 // Operation sets the operation name for the outgoing request 17 func Operation(name string) Option { 18 return func(bd *Request) { 19 bd.OperationName = name 20 } 21 } 22 23 // Extensions sets the extensions to be sent with the outgoing request 24 func Extensions(extensions map[string]interface{}) Option { 25 return func(bd *Request) { 26 bd.Extensions = extensions 27 } 28 } 29 30 // Path sets the url that this request will be made against, useful if you are mounting your entire router 31 // and need to specify the url to the graphql endpoint. 32 func Path(url string) Option { 33 return func(bd *Request) { 34 bd.HTTP.URL.Path = url 35 } 36 } 37 38 // AddHeader adds a header to the outgoing request. This is useful for setting expected Authentication headers for example. 39 func AddHeader(key string, value string) Option { 40 return func(bd *Request) { 41 bd.HTTP.Header.Add(key, value) 42 } 43 } 44 45 // BasicAuth authenticates the request using http basic auth. 46 func BasicAuth(username, password string) Option { 47 return func(bd *Request) { 48 bd.HTTP.SetBasicAuth(username, password) 49 } 50 } 51 52 // AddCookie adds a cookie to the outgoing request 53 func AddCookie(cookie *http.Cookie) Option { 54 return func(bd *Request) { 55 bd.HTTP.AddCookie(cookie) 56 } 57 }