Constructs a new BaseOperation instance.
OptionalauthToken: RequestAuthInput
The authentication material used for API requests. A string is treated as a bearer token for backwards compatibility.
Optionaloptions: RequestOptions
Transport settings scoped to this instance (timeout, cancellation, retry policy, lifecycle hooks).
OptionalstateOwner: object
Stable object keying cross-request transport state (circuit breaker, retry budget, pacing deadlines). Provider wirings pass one shared owner to every operation they construct so that state spans the whole client; when omitted, a fresh per-instance object is used and the state stays scoped to this operation.
custom sends a caller-authored GraphQL query or mutation document.
The response follows the same unwrapping rule as every other operation:
a document with a single root field resolves to the bare field value,
while a document with multiple root fields resolves to the full
{ data } envelope. Annotate T with the shape you expect: the bare
value for single-root-field documents, or the envelope type itself when
the document selects several root fields:
const viewer = await aniLink.anilist.custom<{ id: number }>("query { Viewer { id } }");
// Multi-root-field document: T is the full envelope.
const both = await aniLink.anilist.custom<{ data: { Media: { id: number }; User: { id: number } } }>(
"query { Media (id: 1) { id } User (id: 1) { id } }"
);
The GraphQL document to execute. It must declare an executable operation: an anonymous shorthand selection ({ Viewer { id } }) or a query/mutation document. AniList's HTTP endpoint does not serve subscriptions, so subscription documents are rejected here rather than failing remotely.
The variables for the document. This parameter is optional.
Optionaloptions: RequestOptions
Optional per-request transport settings merged over the instance-level ones for this call only.
A promise that resolves to the unwrapped response data for single-root-field documents, or the full { data } envelope otherwise.
An AniLinkValidationError when the query is empty or is not an executable document (for example a fragment-only definition).
An AniLinkError when the request fails. When AniList returns partial success (some fields resolve while others fail inside an HTTP 200 envelope), the thrown AniLinkGraphQLError exposes the resolved portion via its partialData field, so the fields that did resolve remain recoverable from the error.
customPage paginates a caller-authored Page document through the
shared engine. Use it for collections whose field combination the
generated page operations do not expose.
The document must declare the standard AniList Page wrapper with
$page/$perPage Int variables and select pageInfo { hasNextPage }
(the engine's terminal flag) plus an items array under a key of your
choosing. Because Page is the document's single root field, the
response unwraps to the bare Page object, so TPage is the Page
selection's shape, not an envelope:
const result = await aniLink.anilist.customPage(
`query ($page: Int, $perPage: Int) {
Page(page: $page, perPage: $perPage) {
pageInfo { total currentPage lastPage hasNextPage }
media(type: ANIME, sort: POPULARITY_DESC) { id title { romaji } }
}
}`,
"media",
{},
{ perPage: 50, maxPages: 5 }
);
The traversal reuses every engine guard: perPage clamping (AniList caps
it at 50), the maxPages bound (default 100), look-ahead concurrency
(default 3), AbortSignal forwarding, and the pageInfo.lastPage
terminal bound. variables are forwarded verbatim on every page
request with page/perPage merged over them.
The Page selection's response shape; must include pageInfo (the engine reads pageInfo.hasNextPage).
The key of the items array on TPage (e.g. "media").
The GraphQL document to traverse. It must be a query document whose single root field is Page, selected with $page/$perPage variables; mutation documents, non-Page documents, and documents with additional root fields are rejected locally.
The key of the items array on the Page response (e.g. "media", "characters").
The variables for the document, forwarded on every page request with page/perPage merged over them. This parameter is optional.
Optionaloptions: CustomPageOptions
Optional CustomPageOptions: the PaginateOptions controls (perPage, startPage, maxPages, concurrency, signal, onPage, onHookError, diagnostics) plus per-request transport settings under transportOptions, merged over the instance-level ones for this call only.
The collected items, per-page snapshots, page count, and whether the maxPages guard or the server-reported lastPage bound truncated the run; a PaginateResult.
An AniLinkValidationError when the document is not a query selecting the Page root field with $page/$perPage variable references, or when a fetched page response has no itemsKey key at all.
const result = await aniLink.anilist.customPage(
`query ($page: Int, $perPage: Int) {
Page(page: $page, perPage: $perPage) {
pageInfo { hasNextPage }
characters(search: "spike") { id name { full } }
}
}`,
"characters",
{},
{ perPage: 50, maxPages: 3 }
);
console.log(result.items.length, result.truncated);
CustomRequestsends caller-authored GraphQL documents to AniList for queries and mutations without a typed operation.See