Skip to content

Commit 4f12c3f

Browse files
fix(Web): separate-batchers
1 parent 474605b commit 4f12c3f

File tree

1 file changed

+30
-5
lines changed

1 file changed

+30
-5
lines changed

web/src/context/GraphqlBatcher.tsx

+30-5
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,11 @@ interface IQuery {
2222

2323
const Context = createContext<IGraphqlBatcher | undefined>(undefined);
2424

25-
const executor: AsyncExecutor = async ({ document, variables, extensions }) => {
25+
const coreExecutor: AsyncExecutor = async ({ document, variables }) => {
2626
try {
2727
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
2828
//@ts-ignore
29-
const result = request(extensions.url, document, variables).then((res) => ({
29+
const result = request(getGraphqlUrl(false), document, variables).then((res) => ({
3030
data: res,
3131
})) as Promise<ExecutionResult>;
3232

@@ -38,12 +38,37 @@ const executor: AsyncExecutor = async ({ document, variables, extensions }) => {
3838
}
3939
};
4040

41-
const batchExec = createBatchingExecutor(executor);
41+
const dtrExecutor: AsyncExecutor = async ({ document, variables }) => {
42+
try {
43+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
44+
//@ts-ignore
45+
const result = request(getGraphqlUrl(true), document, variables).then((res) => ({
46+
data: res,
47+
})) as Promise<ExecutionResult>;
48+
49+
return result;
50+
} catch (error) {
51+
console.error("Graph error: ", { error });
52+
debounceErrorToast("Graph query error: failed to fetch data.");
53+
return { data: {} };
54+
}
55+
};
56+
57+
const coreBatchExec = createBatchingExecutor(coreExecutor);
58+
const dtrBatchExec = createBatchingExecutor(dtrExecutor);
4259

4360
const fetcher = async (queries: IQuery[]) => {
4461
const batchdata = await Promise.all(
45-
queries.map(({ document, variables, isDisputeTemplate, chainId }) =>
46-
batchExec({ document, variables, extensions: { url: getGraphqlUrl(isDisputeTemplate ?? false, chainId) } })
62+
queries.map(({ document, variables, isDisputeTemplate }) =>
63+
isDisputeTemplate
64+
? dtrBatchExec({
65+
document,
66+
variables,
67+
})
68+
: coreBatchExec({
69+
document,
70+
variables,
71+
})
4772
)
4873
);
4974

0 commit comments

Comments
 (0)