• 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.

    Type Parameters

    • T

    Parameters

    • query: string

      The GraphQL query or mutation string.

    • Optionalvariables: Record<string, unknown>

      Optional variables for the query.

    • Optionaltoken: string

      Optional authentication token.

    • OptionalabortSignal: AbortSignal

      Optional abort signal to cancel the request.

    • OptionalbypassCache: boolean

      Optional flag to bypass cache.

    Returns Promise<AniListResponse<T>>

    A promise resolving to an AniListResponse object.

    export async function request<T>(
    query: string,
    variables?: Record<string, unknown>,
    token?: string,
    abortSignal?: AbortSignal,
    bypassCache?: 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 = typeof window !== "undefined" && window.electronAPI;

    // Route request to appropriate handler
    if (isElectron) {
    return handleElectronRequest<T>(
    requestId,
    query,
    variables,
    token,
    bypassCache,
    abortSignal,
    );
    } else {
    const options = buildRequestOptions(query, variables, token, abortSignal);
    return handleBrowserRequest<T>(requestId, options);
    }
    }