Improve http2 / SSL support

This commit is contained in:
2021-12-10 22:33:47 +00:00
parent ea7ec683ef
commit d1406eeac8
2 changed files with 24 additions and 5 deletions
+5 -5
View File
@@ -15,7 +15,6 @@ package gql
import (
"crypto/tls"
"fmt"
"net"
"net/http"
"os"
"strconv"
@@ -77,15 +76,15 @@ func setCacheEnabled() bool {
}
func NewConnection() *GraphQL {
return &GraphQL{
g := GraphQL{
Endpoint: pickGraphqlEndpoint(),
HttpClient: &http.Client{
Transport: &http2.Transport{
DisableCompression: false,
AllowHTTP: true,
PingTimeout: 5 * time.Second,
DialTLS: func(network, addr string, cfg *tls.Config) (net.Conn, error) {
return net.Dial(network, addr)
PingTimeout: 10 * time.Second,
TLSClientConfig: &tls.Config{
InsecureSkipVerify: true,
},
},
},
@@ -93,6 +92,7 @@ func NewConnection() *GraphQL {
Cache: setCacheEnabled(),
CacheStore: setupCache(),
}
return &g
}
func setupCache() *bigcache.BigCache {
+19
View File
@@ -132,6 +132,25 @@ func (suite *TestSuite) Test_GraphQL_Query() {
wantResult: ``,
wantErr: true,
},
{
name: "Valid query to https endpoint",
endpoint: "https://web-dev.telegram-bot.app/v1/graphql",
isLocal: false,
args: args{
queryContent: `query packages_prices {
available_packages: tbl_available_packages(where: {enabled: {_eq: true}}) {
package_name
package_discount
package_price
package_size
package_type
}
}`,
queryVariables: nil,
},
wantResult: `{"available_packages":[{"package_discount":0,"package_name":"media_1000","package_price":750,"package_size":1000,"package_type":"media"},{"package_discount":5,"package_name":"media_5000","package_price":3563,"package_size":5000,"package_type":"media"},{"package_discount":10,"package_name":"media_10000","package_price":6750,"package_size":10000,"package_type":"media"},{"package_discount":15,"package_name":"media_25000","package_price":15938,"package_size":25000,"package_type":"media"},{"package_discount":0,"package_name":"voice_500","package_price":1000,"package_size":500,"package_type":"voice"},{"package_discount":10,"package_name":"voice_1000","package_price":1800,"package_size":1000,"package_type":"voice"},{"package_discount":15,"package_name":"voice_2500","package_price":4250,"package_size":2500,"package_type":"voice"}]}`,
wantErr: false,
},
}
for _, tt := range tests {
suite.T().Run(tt.name, func(t *testing.T) {