feat(WEB-104): add on-demand revalidation for cache

This commit is contained in:
Simon Emanuelsson
2024-02-21 08:04:03 +01:00
parent d1d20ce555
commit f6f4e6edb4
11 changed files with 104 additions and 23 deletions

View File

@@ -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