Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(Web): separate-batchers #1867

Merged
merged 3 commits into from
Jan 30, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 22 additions & 5 deletions web/src/context/GraphqlBatcher.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@ interface IQuery {

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

const executor: AsyncExecutor = async ({ document, variables, extensions }) => {
const fetch = async (url, document, variables) => {
try {
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
//@ts-ignore
const result = request(extensions.url, document, variables).then((res) => ({
const result = request(url, document, variables).then((res) => ({
data: res,
})) as Promise<ExecutionResult>;

Expand All @@ -38,12 +38,29 @@ const executor: AsyncExecutor = async ({ document, variables, extensions }) => {
}
};

const batchExec = createBatchingExecutor(executor);
const coreExecutor: AsyncExecutor = async ({ document, variables }) => {
return fetch(getGraphqlUrl(false), document, variables);
};

const dtrExecutor: AsyncExecutor = async ({ document, variables }) => {
return fetch(getGraphqlUrl(true), document, variables);
};

const coreBatchExec = createBatchingExecutor(coreExecutor);
const dtrBatchExec = createBatchingExecutor(dtrExecutor);

const fetcher = async (queries: IQuery[]) => {
const batchdata = await Promise.all(
queries.map(({ document, variables, isDisputeTemplate, chainId }) =>
batchExec({ document, variables, extensions: { url: getGraphqlUrl(isDisputeTemplate ?? false, chainId) } })
queries.map(({ document, variables, isDisputeTemplate }) =>
isDisputeTemplate
? dtrBatchExec({
document,
variables,
})
: coreBatchExec({
document,
variables,
})
)
);

Expand Down