feat: add edge request function
This commit is contained in:
@@ -1,31 +1,23 @@
|
||||
import { DocumentNode, print } from "graphql"
|
||||
|
||||
import { Lang } from "@/constants/languages"
|
||||
import { env } from "@/env/server"
|
||||
import { edgeRequest } from "@/lib/graphql/edgeRequest"
|
||||
import { ResolveEntryByUrl } from "@/lib/graphql/Query/ResolveEntry.graphql"
|
||||
import { internalServerError } from "@/server/errors/next"
|
||||
|
||||
import { validateEntryResolveSchema } from "@/types/requests/entry"
|
||||
|
||||
export async function resolve(url: string, lang = Lang.en) {
|
||||
const result = await fetch(env.CMS_URL, {
|
||||
method: "POST",
|
||||
headers: {
|
||||
access_token: env.CMS_ACCESS_TOKEN,
|
||||
"Content-Type": "application/json",
|
||||
const response = await edgeRequest(
|
||||
ResolveEntryByUrl,
|
||||
{
|
||||
locale: lang,
|
||||
url,
|
||||
},
|
||||
body: JSON.stringify({
|
||||
query: print(ResolveEntryByUrl as DocumentNode),
|
||||
variables: {
|
||||
locale: lang,
|
||||
url,
|
||||
},
|
||||
}),
|
||||
})
|
||||
{
|
||||
revalidate: 3600,
|
||||
}
|
||||
)
|
||||
|
||||
const { data } = await result.json()
|
||||
|
||||
const validatedData = validateEntryResolveSchema.safeParse(data)
|
||||
const validatedData = validateEntryResolveSchema.safeParse(response.data)
|
||||
|
||||
if (!validatedData.success) {
|
||||
throw internalServerError(validatedData.error)
|
||||
|
||||
Reference in New Issue
Block a user