mirror of
https://github.com/lukaszraczylo/go-simple-graphql.git
synced 2026-10-13 00:48:37 +00:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
5a222aa316
|
||
|
|
d843238d46
|
@@ -80,10 +80,13 @@ func (c *BaseClient) Query(queryContent string, queryVariables interface{}, quer
|
||||
if len(queryHeaders) > 0 {
|
||||
cacheBaseClient = reflect.ValueOf(*c).Interface().(BaseClient)
|
||||
queryHeaders = c.parseQueryHeaders(queryHeaders)
|
||||
defer func() {
|
||||
*c = cacheBaseClient
|
||||
}()
|
||||
}
|
||||
|
||||
if c.cache.enabled {
|
||||
queryHash = strutil.Md5(query.compiledQuery)
|
||||
queryHash = strutil.Md5(fmt.Sprintf("%s-%+v", query.compiledQuery, queryHeaders))
|
||||
c.Logger.Debug(c, "Hash calculated;", "hash:", queryHash)
|
||||
|
||||
cachedResponse = c.cacheLookup(queryHash)
|
||||
@@ -111,10 +114,6 @@ func (c *BaseClient) Query(queryContent string, queryVariables interface{}, quer
|
||||
c.cache.client.Set(queryHash, jsonData)
|
||||
}
|
||||
|
||||
if len(queryHeaders) > 0 {
|
||||
*c = cacheBaseClient
|
||||
}
|
||||
|
||||
return c.decodeResponse(jsonData), err
|
||||
}
|
||||
|
||||
|
||||
@@ -5,6 +5,7 @@ import (
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"net/http"
|
||||
"time"
|
||||
|
||||
"github.com/avast/retry-go/v4"
|
||||
)
|
||||
@@ -50,6 +51,13 @@ func (c *BaseClient) executeQuery(query []byte, headers any) (result any, err er
|
||||
|
||||
return nil
|
||||
},
|
||||
retry.OnRetry(func(n uint, err error) {
|
||||
c.Logger.Error(c, "Retrying query", "error", err.Error())
|
||||
}),
|
||||
retry.Attempts(uint(c.retries.max)),
|
||||
retry.DelayType(retry.BackOffDelay),
|
||||
retry.Delay(time.Duration(c.retries.delay)*time.Second),
|
||||
retry.LastErrorOnly(true),
|
||||
)
|
||||
|
||||
if len(queryResult.Errors) > 0 {
|
||||
|
||||
Reference in New Issue
Block a user