-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
32 changed files
with
323 additions
and
281 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package client | ||
|
||
import "encoding/json" | ||
|
||
// RawJsonError is a json formatted error from a GraphQL server. | ||
type RawJsonError struct { | ||
json.RawMessage | ||
} | ||
|
||
func (r RawJsonError) Error() string { | ||
return string(r.RawMessage) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
package client | ||
|
||
import "net/http" | ||
|
||
// Var adds a variable into the outgoing request | ||
func Var(name string, value interface{}) Option { | ||
return func(bd *Request) { | ||
if bd.Variables == nil { | ||
bd.Variables = map[string]interface{}{} | ||
} | ||
|
||
bd.Variables[name] = value | ||
} | ||
} | ||
|
||
// Operation sets the operation name for the outgoing request | ||
func Operation(name string) Option { | ||
return func(bd *Request) { | ||
bd.OperationName = name | ||
} | ||
} | ||
|
||
// Path sets the url that this request will be made against, useful if you are mounting your entire router | ||
// and need to specify the url to the graphql endpoint. | ||
func Path(url string) Option { | ||
return func(bd *Request) { | ||
bd.HTTP.URL.Path = url | ||
} | ||
} | ||
|
||
// AddHeader adds a header to the outgoing request. This is useful for setting expected Authentication headers for example. | ||
func AddHeader(key string, value string) Option { | ||
return func(bd *Request) { | ||
bd.HTTP.Header.Add(key, value) | ||
} | ||
} | ||
|
||
// BasicAuth authenticates the request using http basic auth. | ||
func BasicAuth(username, password string) Option { | ||
return func(bd *Request) { | ||
bd.HTTP.SetBasicAuth(username, password) | ||
} | ||
} | ||
|
||
// AddCookie adds a cookie to the outgoing request | ||
func AddCookie(cookie *http.Cookie) Option { | ||
return func(bd *Request) { | ||
bd.HTTP.AddCookie(cookie) | ||
} | ||
} |
Oops, something went wrong.