import { TypedDocumentNode } from "@graphql-typed-document-node/core"; import { Variables } from "graphql-request"; import { ExecutionResult, Sink } from "graphql-ws"; import { Mutation } from "./Mutation"; import { Query } from "./Query"; import { Subscribe } from "./Subscribe"; export type CleanupFunction = () => void; export type ApiConfig = { apiUrl: string; apiRealtimeUrl: string; ws?: boolean; headers?: Record; wsHeaders?: Record; applyHeaders?: () => Promise>; fetch?: (input: RequestInfo | URL, init?: RequestInit) => Promise; }; export declare class Codex { private apiKey; private apiConfig?; private client; private wsClient; queries: Query; mutations: Mutation; subscriptions: Subscribe; /** * @param apiKey - The api key to use for the requests. * @param apiConfig - The configuration to use for the requests. */ constructor(apiKey: string, apiConfig?: Partial | undefined); private parseConfig; private createGraphQLClient; private createWebsocketClient; private getRequestHeaders; /** * Need to update the headers on the websocket connection. * This is useful if the api key changes, or you need to modify the connection init params at all. * NOTE: it will dispose of the old connection, so all existing subscriptions will be closed. */ updateConfig(incomingConfig: Partial): void; /** * Call this to dispose of the websocket connection, and make this class ready for garbage collection. * This will also close any open subscriptions. * * It's useful for when you need to modify some of the configuration, or when you're done with the class. */ dispose(): Promise; /** * This is the preferred way to execute queries. * @param doc - The graphql document node to execute. * @param args - The variables to pass to the document. * @returns The result of the query. */ query(doc: TypedDocumentNode, args?: TVars): Promise; /** * This is functionally the same thing as the `query` method, but it's more expressive. * @param doc - The graphql document node to execute. * @param args - The variables to pass to the document. * @returns The result of the mutation. */ mutation(doc: TypedDocumentNode, args?: TVars): Promise; /** * This should be used when you don't want to use graphql libaries to create a document node, * and would rather just pass in a string. * @param gqlString - The graphql document string to execute. * @param args - The variables to pass to the document. * @returns The result of the mutation. */ send(gqlString: string, args?: V): Promise; /** * @param doc - The graphql document string to execute. * @param args - The variables to pass to the document. * @param sink - The sink to receive the results. * @returns A cleanup function to unsubscribe from the subscription. */ subscribe = Record>(doc: string, args: TVars, sink: Sink>): CleanupFunction; }