Skip to content

Commit

Permalink
add logging
Browse files Browse the repository at this point in the history
  • Loading branch information
peteror committed Oct 27, 2023
1 parent d3b9273 commit 78455ee
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 9 deletions.
14 changes: 8 additions & 6 deletions src/routes/graphql.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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
Expand All @@ -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)
Expand All @@ -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',
Expand All @@ -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)
}

/**
Expand All @@ -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)
}
Expand Down
6 changes: 3 additions & 3 deletions wrangler.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down

0 comments on commit 78455ee

Please sign in to comment.