v0.6.4
Changelog
- support custom HTTP client for the subscription client (#29) @sermojohn
- add debug mode, expose GraphQL builder functions and UnmarshalGraphQL for unit tests (#30) @hgiasac
Custom HTTP Client for the subscription client
Use WithWebSocketOptions
to customize the HTTP client which is used by the subscription client.
client.WithWebSocketOptions(WebsocketOptions{
HTTPClient: &http.Client{
Transport: http.DefaultTransport,
Timeout: time.Minute,
}
})
Debugging and Unit test
Enable debug mode with the WithDebug
function. If the request is failed, the request and response information will be included in extensions[].internal
property.
{
"errors": [
{
"message":"Field 'user' is missing required arguments: login",
"extensions": {
"internal": {
"request": {
"body":"{\"query\":\"{user{name}}\"}",
"headers": {
"Content-Type": ["application/json"]
}
},
"response": {
"body":"{\"errors\": [{\"message\": \"Field 'user' is missing required arguments: login\",\"locations\": [{\"line\": 7,\"column\": 3}]}]}",
"headers": {
"Content-Type": ["application/json"]
}
}
}
},
"locations": [
{
"line":7,
"column":3
}
]
}
]
}
Because the GraphQL query string is generated in runtime using reflection, it isn't really safe. To assure the GraphQL query is expected, it's necessary to write some unit test for query construction.
// ConstructQuery build GraphQL query string from struct and variables
func ConstructQuery(v interface{}, variables map[string]interface{}, options ...Option) (string, error)
// ConstructQuery build GraphQL mutation string from struct and variables
func ConstructMutation(v interface{}, variables map[string]interface{}, options ...Option) (string, error)
// ConstructSubscription build GraphQL subscription string from struct and variables
func ConstructSubscription(v interface{}, variables map[string]interface{}, options ...Option) (string, error)
// UnmarshalGraphQL parses the JSON-encoded GraphQL response data and stores
// the result in the GraphQL query data structure pointed to by v.
func UnmarshalGraphQL(data []byte, v interface{}) error