feat(WEB-104): add on-demand revalidation for cache
This commit is contained in:
@@ -6,18 +6,22 @@ import { cache } from "react"
|
||||
import type { Data } from "@/types/request"
|
||||
import type { DocumentNode } from "graphql"
|
||||
|
||||
const client = new GraphQLClient(env.CMS_URL, {
|
||||
fetch: cache(async function (url: URL | RequestInfo, params: RequestInit | undefined) {
|
||||
return fetch(url, params)
|
||||
}),
|
||||
})
|
||||
|
||||
export async function request<T>(
|
||||
query: string | DocumentNode,
|
||||
variables?: {},
|
||||
next?: NextFetchRequestConfig
|
||||
): Promise<Data<T>> {
|
||||
try {
|
||||
const client = new GraphQLClient(env.CMS_URL, {
|
||||
fetch: cache(async function (url: URL | RequestInfo, params: RequestInit | undefined) {
|
||||
return fetch(url, params)
|
||||
}),
|
||||
next,
|
||||
})
|
||||
|
||||
if (next) {
|
||||
client.requestConfig.next = next
|
||||
}
|
||||
|
||||
if (env.PRINT_QUERY) {
|
||||
const print = (await import("graphql/language/printer")).print
|
||||
|
||||
Reference in New Issue
Block a user