Add mapstring output and update the README.

This commit is contained in:
2023-04-08 01:36:56 +01:00
parent 689b1efc43
commit d764980390
3 changed files with 10 additions and 2 deletions
+1 -1
View File
@@ -34,7 +34,7 @@ Therefore, I present you the simple client to which you can copy & paste your gr
* `GRAPHQL_ENDPOINT` - Your GraphQL endpoint. Default: `http://127.0.0.1:9090/v1/graphql`
* `GRAPHQL_CACHE_ENABLED` - Should the query cache be enabled? Default: `false`
* `GRAPHQL_CACHE_TTL` - Cache TTL in seconds for SELECT type of queries. Default: `5`
* `GRAPHQL_OUTPUT` - Output format. Default: `byte`, available: `byte`, `string`
* `GRAPHQL_OUTPUT` - Output format. Default: `mapstring`, available: `byte`, `string`, `mapstring`
* `LOG_LEVEL` - Logging level. Default: `info` available: `debug`, `info`, `warn`, `error`
* `GRAPHQL_RETRIES_ENABLE` - Should retries be enabled? Default: `true`
* `GRAPHQL_RETRIES_NUMBER` - Number of retries: Default: `1`
+1 -1
View File
@@ -33,7 +33,7 @@ func NewConnection() *BaseClient {
}
b.endpoint = envutil.Getenv("GRAPHQL_ENDPOINT", "https://api.github.com/graphql")
b.responseType = envutil.Getenv("GRAPHQL_OUTPUT", "string")
b.responseType = envutil.Getenv("GRAPHQL_OUTPUT", "mapstring")
b.validate = envutil.GetBool("GRAPHQL_VALIDATE", false)
b.cache.enabled = envutil.GetBool("GRAPHQL_CACHE_ENABLED", true)
b.cache.ttl = envutil.GetInt("GRAPHQL_CACHE_TTL", 60)
+8
View File
@@ -120,6 +120,14 @@ func (c *BaseClient) Query(queryContent string, queryVariables interface{}, quer
func (c *BaseClient) decodeResponse(jsonData []byte) any {
switch c.responseType {
case "mapstring":
var response map[string]interface{}
err := json.Unmarshal(jsonData, &response)
if err != nil {
c.Logger.Error(c, "Error while converting to map[string]interface{};", "error", err.Error())
return nil
}
return response
case "string":
return helpers.BytesToString(jsonData)
case "byte":