From 78455ee128002dce3bcefb3b0c948a9bb5a7c5ec Mon Sep 17 00:00:00 2001 From: Peter Orlovacz Date: Fri, 27 Oct 2023 10:25:40 +0400 Subject: [PATCH] add logging --- src/routes/graphql.ts | 14 ++++++++------ wrangler.toml | 6 +++--- 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/src/routes/graphql.ts b/src/routes/graphql.ts index b67cdea..5558583 100644 --- a/src/routes/graphql.ts +++ b/src/routes/graphql.ts @@ -95,7 +95,6 @@ export const graphql: Handler = async function (req, res) { if (!isMutationRequest) { content = normalizeDocument(originalBody.query) - if (inspectSchema) { const schema = await findSchema() if (schema && !graphQLSchema) { @@ -135,7 +134,7 @@ export const graphql: Handler = async function (req, res) { isMutationRequest === false && (hasPrivateTypes || scope === Scope.AUTHENTICATED || authRequired) - + /** * In case of the query will return user specific data the response * is cached user specific based on the Authorization header @@ -156,9 +155,9 @@ export const graphql: Handler = async function (req, res) { defaultResponseHeaders[HTTPHeaders.fgScope] = Scope.AUTHENTICATED } else { querySignature = await SHA256(content + variables) - } + } */ - if (operationName == 'home') { + if (operationName == 'Home') { querySignature = await SHA256(authorizationHeader + content + variables) } else { querySignature = await SHA256(content + variables) @@ -173,6 +172,7 @@ export const graphql: Handler = async function (req, res) { cacheKey += querySignature cacheUrl.pathname = cacheUrl.pathname + cacheKey + cacheRequest = new Request(cacheUrl.toString(), { headers: req.headers, method: 'GET', @@ -181,8 +181,10 @@ export const graphql: Handler = async function (req, res) { let response = await cache.match(cacheRequest) if (response) { - return response + console.log("cache hit: "+originalBody.operationName+"|"+cacheRequest.url) + return response } + console.log("cache miss: "+originalBody.operationName+"|"+cacheRequest.url) } /** @@ -194,7 +196,7 @@ export const graphql: Handler = async function (req, res) { try { const forwardedHeaders = new Headers() forwardedHeaders.append(HTTPHeaders.contentType, 'application/json') - + if (authorizationHeader) { forwardedHeaders.append(HTTPHeaders.authorization, authorizationHeader) } diff --git a/wrangler.toml b/wrangler.toml index 39f51c9..2eb81cd 100644 --- a/wrangler.toml +++ b/wrangler.toml @@ -15,10 +15,10 @@ kv_namespaces = [ ORIGIN_URL = "https://api-test-original.lemune.com/graphql/" SCOPE = "AUTHENTICATED" IGNORE_ORIGIN_CACHE_HEADERS = "1" -DEFAULT_TTL = "900" +DEFAULT_TTL = "600" SWR = "30" -PRIVATE_TYPES = "" -GENERIC_TYPES = "productsList,Home,categories,promotedProductsList,productDetails,getProductsForSubcategoriesWithPromoted,getHomeCategories,getPromotionalBanner,getProductCountForChannel,getMainProductCategories" +PRIVATE_TYPES = "userOrders,accountAddresses" +GENERIC_TYPES = "ShippingMethodsFetchAll,productsList,Home,categories,collections,promotedProductsList,productDetails,getProductsForSubcategoriesWithPromoted,getHomeCategories,getPromotionalBanner,getProductCountForChannel,getMainProductCategories,productsCountByChannel" AUTH_DIRECTIVE = "" APQ_TTL = "30"