fix(core): add timeout params to graphql request options (#10919)
Close [BS-2813](https://linear.app/affine-design/issue/BS-2813).
This commit is contained in:
@@ -273,6 +273,7 @@ export class CopilotClient {
|
|||||||
content,
|
content,
|
||||||
options,
|
options,
|
||||||
},
|
},
|
||||||
|
timeout: 60000,
|
||||||
});
|
});
|
||||||
return res.addContextFile;
|
return res.addContextFile;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,6 +8,8 @@ import type { Mutations, Queries } from './schema';
|
|||||||
|
|
||||||
export type NotArray<T> = T extends Array<unknown> ? never : T;
|
export type NotArray<T> = T extends Array<unknown> ? never : T;
|
||||||
|
|
||||||
|
export type FetchInit = RequestInit & { timeout?: number };
|
||||||
|
|
||||||
export type _QueryVariables<Q extends GraphQLQuery> =
|
export type _QueryVariables<Q extends GraphQLQuery> =
|
||||||
Q['id'] extends Queries['name']
|
Q['id'] extends Queries['name']
|
||||||
? Extract<Queries, { name: Q['id'] }>['variables']
|
? Extract<Queries, { name: Q['id'] }>['variables']
|
||||||
@@ -75,6 +77,11 @@ export type RequestOptions<Q extends GraphQLQuery> = QueryVariablesOption<Q> & {
|
|||||||
* @default true
|
* @default true
|
||||||
*/
|
*/
|
||||||
keepNilVariables?: boolean;
|
keepNilVariables?: boolean;
|
||||||
|
/**
|
||||||
|
* Request timeout in milliseconds
|
||||||
|
* @default 15000
|
||||||
|
*/
|
||||||
|
timeout?: number;
|
||||||
};
|
};
|
||||||
|
|
||||||
export type QueryOptions<Q extends GraphQLQuery> = RequestOptions<Q> & {
|
export type QueryOptions<Q extends GraphQLQuery> = RequestOptions<Q> & {
|
||||||
@@ -169,7 +176,7 @@ function formatRequestBody<Q extends GraphQLQuery>({
|
|||||||
|
|
||||||
export const gqlFetcherFactory = (
|
export const gqlFetcherFactory = (
|
||||||
endpoint: string,
|
endpoint: string,
|
||||||
fetcher: (input: string, init?: RequestInit) => Promise<Response> = fetch
|
fetcher: (input: string, init?: FetchInit) => Promise<Response> = fetch
|
||||||
) => {
|
) => {
|
||||||
const logger = new DebugLogger('GraphQL');
|
const logger = new DebugLogger('GraphQL');
|
||||||
const gqlFetch = async <Query extends GraphQLQuery>(
|
const gqlFetch = async <Query extends GraphQLQuery>(
|
||||||
@@ -199,6 +206,7 @@ export const gqlFetcherFactory = (
|
|||||||
method: 'POST',
|
method: 'POST',
|
||||||
headers,
|
headers,
|
||||||
body: isFormData ? body : JSON.stringify(body),
|
body: isFormData ? body : JSON.stringify(body),
|
||||||
|
timeout: options.timeout,
|
||||||
})
|
})
|
||||||
).then(async res => {
|
).then(async res => {
|
||||||
if (res.headers.get('content-type')?.startsWith('application/json')) {
|
if (res.headers.get('content-type')?.startsWith('application/json')) {
|
||||||
|
|||||||
Reference in New Issue
Block a user