Skip to content

Commit

Permalink
adding timestamp in kv metadata
Browse files Browse the repository at this point in the history
  • Loading branch information
dbrrt committed Jan 3, 2024
1 parent 08109b6 commit fa03219
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 3 deletions.
5 changes: 5 additions & 0 deletions .changeset/few-swans-juggle.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@authdog/hydra-core": patch
---

adding timestamp to metadata to know when data has been cached
5 changes: 2 additions & 3 deletions packages/core/src/handlers/hydra.ts
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,6 @@ export const HydraHandler = async (req, env, ctx): Promise<Response> => {
);
}
}
// }

let payload: any = null;

Expand Down Expand Up @@ -329,7 +328,6 @@ export const HydraHandler = async (req, env, ctx): Promise<Response> => {
if (!isIntrospection && !isMutation && cacheKey && payload) {
const rawJsonPayload = await payload.clone().json();

// console.log("rawJsonPayload", rawJsonPayload)

if (rawJsonPayload?.errors) {
throw new Error(JSON.stringify(rawJsonPayload?.errors));
Expand All @@ -349,6 +347,7 @@ export const HydraHandler = async (req, env, ctx): Promise<Response> => {
};
}),
],
ts: new Date().toISOString(),
},
});

Expand All @@ -373,6 +372,7 @@ export const HydraHandler = async (req, env, ctx): Promise<Response> => {
};
}),
],
ts: new Date().toISOString(),
},
});
});
Expand All @@ -388,7 +388,6 @@ export const HydraHandler = async (req, env, ctx): Promise<Response> => {
"content-type": "application/json;charset=UTF-8",
"x-hydra-rate-budget": String(remainingRateBudget),
"x-hydra-rate-threshold": String(defaultRateLimitingBudget),
// "x-hydra-cache-key": cacheKey,
},
});

Expand Down
13 changes: 13 additions & 0 deletions services/itty-hydra/handlers/cache-keys.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { headersDefault } from "../utils/headers";

export const CacheKeysHandler = async (request, bindings: any, ctx: any) => {
const keys = await ctx?.kv.list();

return new Response(
JSON.stringify({
message: "OK",
...keys,
}),
{ status: 200, headers: headersDefault },
);
};
2 changes: 2 additions & 0 deletions services/itty-hydra/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { Router } from "itty-router";
import { createCors } from "itty-cors";
import { NotFound } from "./handlers/notFound";
import { Health } from "./handlers/health";
import {CacheKeysHandler} from "./handlers/cache-keys"
import { GraphQLHandler, HydraHandler } from "@authdog/hydra-core";
import { HydraConfigAcme } from "./hydra.config";

Expand All @@ -21,6 +22,7 @@ router
.options("*", preflight)
.get("/", Health)
.get("/health", Health)
.get("/keys", CacheKeysHandler)
.get("/graphql", GraphQLHandler)
.post("/graphql", HydraHandler)
.all("*", NotFound);
Expand Down

0 comments on commit fa03219

Please sign in to comment.