-
Notifications
You must be signed in to change notification settings - Fork 0
/
sanity.client.ts
34 lines (31 loc) · 796 Bytes
/
sanity.client.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
import "server-only";
import {
createClient,
type ClientConfig,
type QueryParams,
} from "@sanity/client";
import { projectId, dataset, apiVersion, token } from "@/lib/sanity.api";
const config: ClientConfig = {
projectId,
dataset,
apiVersion,
// set CDN to live API in development mode
useCdn: process.env.NODE_ENV === "development" ? true : false,
token,
};
const client = createClient(config);
export async function sanityFetch<QueryResponse>({
query,
qParams,
tags,
}: {
query: string;
qParams?: QueryParams;
tags: string[];
}): Promise<QueryResponse> {
return client.fetch<QueryResponse>(query, qParams, {
// disable cache in development mode.
cache: process.env.NODE_ENV === "development" ? "no-store" : "force-cache",
next: { tags },
});
}