feat(WEB-102): language-switcher per page basis

This commit is contained in:
Simon Emanuelsson
2024-02-20 15:58:53 +01:00
parent 9e56ff158d
commit 7417abc814
28 changed files with 355 additions and 1377 deletions

28
lib/batchRequest.ts Normal file
View File

@@ -0,0 +1,28 @@
import "server-only"
import { request } from "./request"
import type { Data } from "@/types/request"
import type { BatchRequestDocument } from "graphql-request"
export async function batchRequest<T>(queries: BatchRequestDocument[]): Promise<Data<T>> {
try {
const response = await Promise.allSettled(
queries.map(query => request<T>(query.document, query.variables))
)
let data = {} as T
const reasons = []
response.forEach(res => {
if (res.status === "fulfilled") {
data = Object.assign({}, data, res.value.data)
} else {
reasons.push(res.reason)
}
})
return { data }
} catch (error) {
console.error(error)
throw new Error("Something went wrong")
}
}