Skip to content

Commit 9616df8

Browse files
refactor(web): abstract-fetch-logic
1 parent 4f12c3f commit 9616df8

File tree

1 file changed

+7
-15
lines changed

1 file changed

+7
-15
lines changed

web/src/context/GraphqlBatcher.tsx

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

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

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>;
41+
const coreExecutor: AsyncExecutor = async ({ document, variables }) => {
42+
return fetch(getGraphqlUrl(false), document, variables);
43+
};
4844

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-
}
45+
const dtrExecutor: AsyncExecutor = async ({ document, variables }) => {
46+
return fetch(getGraphqlUrl(true), document, variables);
5547
};
5648

5749
const coreBatchExec = createBatchingExecutor(coreExecutor);

0 commit comments

Comments
 (0)