fix: rename retried-wrapped fetch to make caching work again

This commit is contained in:
Simon Emanuelsson
2024-08-28 10:47:57 +02:00
parent 08529e6398
commit 93526ce693
41 changed files with 728 additions and 575 deletions

View File

@@ -1,20 +0,0 @@
#import "../Image.graphql"
fragment LoyaltyPageMetaData on LoyaltyPage {
web {
seo_metadata {
title
description
imageConnection {
edges {
node {
...Image
}
}
}
}
breadcrumbs {
title
}
}
}

View File

@@ -1,20 +0,0 @@
#import "../Image.graphql"
fragment MyPagesMetaData on AccountPage {
web {
seo_metadata {
title
description
imageConnection {
edges {
node {
...Image
}
}
}
}
breadcrumbs {
title
}
}
}

View File

@@ -1,11 +1,24 @@
#import "../Fragments/LoyaltyPage/MetaData.graphql"
#import "../Fragments/Image.graphql"
query GetLoyaltyPageMetaData($locale: String!, $url: String!) {
all_loyalty_page(locale: $locale, where: { url: $url }) {
items {
...LoyaltyPageMetaData
system {
uid
query GetLoyaltyPageMetaData($locale: String!, $uid: String!) {
loyalty_page(locale: $locale, uid: $uid) {
system {
uid
}
web {
seo_metadata {
description
title
imageConnection {
edges {
node {
...Image
}
}
}
}
breadcrumbs {
title
}
}
}

View File

@@ -1,11 +1,24 @@
#import "../Fragments/MyPages/MetaData.graphql"
#import "../Fragments/Image.graphql"
query GetMyPagesMetaData($locale: String!, $url: String!) {
all_account_page(locale: $locale, where: { url: $url }) {
items {
...MyPagesMetaData
system {
uid
query GetMyPagesMetaData($locale: String!, $uid: String!) {
account_page(locale: $locale, uid: $uid) {
system {
uid
}
web {
breadcrumbs {
title
}
seo_metadata {
description
title
imageConnection {
edges {
node {
...Image
}
}
}
}
}
}

View File

@@ -12,11 +12,17 @@ export async function request<T>(
client: GraphQLClient,
query: string | DocumentNode,
variables?: {},
next?: NextFetchRequestConfig
params?: RequestInit
): Promise<Data<T>> {
try {
if (next) {
client.requestConfig.next = next
if (params?.cache) {
client.requestConfig.cache = params.cache
}
if (params?.headers) {
client.requestConfig.headers = params.headers
}
if (params?.next) {
client.requestConfig.next = params.next
}
if (env.PRINT_QUERY) {

View File

@@ -7,12 +7,12 @@ import type { BatchRequestDocument } from "graphql-request"
import type { Data } from "@/types/request"
export async function batchRequest<T>(
queries: (BatchRequestDocument & NextFetchRequestConfig)[]
queries: (BatchRequestDocument & { options?: RequestInit })[]
): Promise<Data<T>> {
try {
const response = await Promise.allSettled(
queries.map((query) =>
request<T>(query.document, query.variables, { tags: query.tags })
request<T>(query.document, query.variables, query.options)
)
)

View File

@@ -14,7 +14,7 @@ const client = new GraphQLClient(env.CMS_URL, {
export async function edgeRequest<T>(
query: string | DocumentNode,
variables?: {},
next?: NextFetchRequestConfig
params?: RequestInit
): Promise<Data<T>> {
return _request(client, query, variables, next)
return _request(client, query, variables, params)
}

View File

@@ -14,20 +14,20 @@ const client = new GraphQLClient(env.CMS_URL, {
url: URL | RequestInfo,
params: RequestInit | undefined
) {
const fetch = fetchRetry(global.fetch, {
const wrappedFetch = fetchRetry(global.fetch, {
retries: 3,
retryDelay: function (attempt, error, response) {
return Math.pow(2, attempt) * 150 // 150, 300, 600
},
})
return fetch(url, params)
return wrappedFetch(url, params)
}),
})
export async function request<T>(
query: string | DocumentNode,
variables?: {},
next?: NextFetchRequestConfig
params?: RequestInit
): Promise<Data<T>> {
return _request(client, query, variables, next)
return _request(client, query, variables, params)
}