feat(WEB-102): language-switcher per page basis
This commit is contained in:
28
lib/batchRequest.ts
Normal file
28
lib/batchRequest.ts
Normal 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")
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user