Skip to content

There can be more than Notion and Miro. AFFiNE(pronounced [ə‘fain]) is a next-gen knowledge base that brings planning, sorting and creating all together. Privacy first, open-source, customizable and ready to use.

fix(core): add timeout params to graphql request options (#10919)

akumatus05329e96c774
diff --git a/packages/frontend/core/src/blocksuite/ai/provider/copilot-client.ts b/packages/frontend/core/src/blocksuite/ai/provider/copilot-client.ts
index 8268ee5063..0bba0a0181 100644
--- a/packages/frontend/core/src/blocksuite/ai/provider/copilot-client.ts
+++ b/packages/frontend/core/src/blocksuite/ai/provider/copilot-client.ts
@@ -273,6 +273,7 @@ export class CopilotClient {
content,
options,
},
+ timeout: 60000,
});
return res.addContextFile;
}
diff --git a/packages/frontend/graphql/src/fetcher.ts b/packages/frontend/graphql/src/fetcher.ts
index d90cfd01d7..520f6363ed 100644
--- a/packages/frontend/graphql/src/fetcher.ts
+++ b/packages/frontend/graphql/src/fetcher.ts
@@ -8,6 +8,8 @@ import type { Mutations, Queries } from './schema';
export type NotArray<T> = T extends Array<unknown> ? never : T;
+export type FetchInit = RequestInit & { timeout?: number };
+
export type _QueryVariables<Q extends GraphQLQuery> =
Q['id'] extends Queries['name']
? Extract<Queries, { name: Q['id'] }>['variables']
@@ -75,6 +77,11 @@ export type RequestOptions<Q extends GraphQLQuery> = QueryVariablesOption<Q> & {
* @default true
*/
keepNilVariables?: boolean;
+ /**
+ * Request timeout in milliseconds
+ * @default 15000
+ */
+ timeout?: number;
};
export type QueryOptions<Q extends GraphQLQuery> = RequestOptions<Q> & {
@@ -169,7 +176,7 @@ function formatRequestBody<Q extends GraphQLQuery>({
export const gqlFetcherFactory = (
endpoint: string,
- fetcher: (input: string, init?: RequestInit) => Promise<Response> = fetch
+ fetcher: (input: string, init?: FetchInit) => Promise<Response> = fetch
) => {
const logger = new DebugLogger('GraphQL');
const gqlFetch = async <Query extends GraphQLQuery>(
@@ -199,6 +206,7 @@ export const gqlFetcherFactory = (
method: 'POST',
headers,
body: isFormData ? body : JSON.stringify(body),
+ timeout: options.timeout,
})
).then(async res => {
if (res.headers.get('content-type')?.startsWith('application/json')) {