The GraphQL query or mutation string.
Optionalvariables: Record<string, unknown>Optional variables for the query.
Optionaltoken: stringOptional authentication token.
OptionalabortSignal: AbortSignalOptional abort signal to cancel the request.
OptionalbypassCache: booleanOptional flag to bypass cache.
OptionalnoRetry: booleanIf true, disable internal retry logic (external retry layer will handle retries).
A promise resolving to an AniListResponse object. See api-listeners.ts for retry implementation
Retry logic is handled automatically by the IPC layer for Electron environments. Transient errors (network failures, 5xx responses, rate limits) are automatically retried with exponential backoff. Maximum 5 retry attempts with jitter to prevent thundering herd. Rate limits are respected via retry-after headers.
export async function request<T>(
query: string,
variables?: Record<string, unknown>,
token?: string,
abortSignal?: AbortSignal,
bypassCache?: boolean,
noRetry?: boolean,
): Promise<AniListResponse<T>> {
// Generate a unique request ID for tracking this request in logs
const requestId = Math.random().toString(36).substring(2, 8);
// Check if we're running in a browser or Electron environment
const isElectron = globalThis.window !== undefined && globalThis.electronAPI;
// Route request to appropriate handler
if (isElectron) {
return handleElectronRequest<T>(
requestId,
query,
variables,
token,
bypassCache,
abortSignal,
noRetry,
);
} else {
const options = buildRequestOptions(query, variables, token, abortSignal);
return handleBrowserRequest<T>(requestId, options);
}
}
Make a request to the AniList API.
Supports dynamic mutations where variable declarations may change based on the variables object passed. Handles both browser and Electron environments.