mirror of
https://github.com/lukaszraczylo/graphql-monitoring-proxy.git
synced 2026-06-05 23:03:48 +00:00
Micro fixes.
This commit is contained in:
@@ -23,3 +23,7 @@ func cacheLookup(hash string) []byte {
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func cacheDelete(hash string) {
|
||||
cfg.Cache.CacheClient.Delete(hash)
|
||||
}
|
||||
|
||||
+2
-1
@@ -75,6 +75,7 @@ type parseGraphQLQueryResult struct {
|
||||
operationName string
|
||||
cacheRequest bool
|
||||
cacheTime int
|
||||
cacheRefresh bool
|
||||
shouldBlock bool
|
||||
shouldIgnore bool
|
||||
}
|
||||
@@ -144,7 +145,7 @@ func parseGraphQLQuery(c *fiber.Ctx) (res *parseGraphQLQueryResult) {
|
||||
}
|
||||
}
|
||||
if arg.Name.Value == "refresh" {
|
||||
res.cacheRequest = arg.Value.GetValue().(bool)
|
||||
res.cacheRefresh = arg.Value.GetValue().(bool)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -119,6 +119,21 @@ func (suite *Tests) Test_parseGraphQLQuery() {
|
||||
},
|
||||
},
|
||||
|
||||
{
|
||||
name: "test valid query with op name, force refreshed cache",
|
||||
suppliedQuery: queries{
|
||||
body: "{\"query\":\"query MyQuery @cached(refresh: true) { tg_users(where: {handle: {_eq: \\\"tozuo\\\"}}) { id __typename } }\", \"variables\": {\"id\": \"1\"}}",
|
||||
},
|
||||
wantResults: results{
|
||||
is_cached: true,
|
||||
cached_ttl: 0,
|
||||
shouldBlock: false,
|
||||
shouldIgnore: false,
|
||||
op_name: "MyQuery",
|
||||
op_type: "query",
|
||||
},
|
||||
},
|
||||
|
||||
{
|
||||
name: "test valid query with op name, cache and INVALID ttl",
|
||||
suppliedQuery: queries{
|
||||
|
||||
@@ -136,6 +136,11 @@ func processGraphQLRequest(c *fiber.Ctx) error {
|
||||
|
||||
wasCached := false
|
||||
|
||||
if parsedResult.cacheRefresh {
|
||||
cfg.Logger.Debug("Cache refresh requested via query", map[string]interface{}{"user_id": extractedUserID, "request_uuid": c.Locals("request_uuid")})
|
||||
cacheDelete(calculateHash(c))
|
||||
}
|
||||
|
||||
// Handling Cache Logic
|
||||
if parsedResult.cacheRequest || cfg.Cache.CacheEnable {
|
||||
cfg.Logger.Debug("Cache enabled", map[string]interface{}{"via_query": parsedResult.cacheRequest, "via_env": cfg.Cache.CacheEnable})
|
||||
|
||||
Reference in New Issue
Block a user