anilist-anime-js — AniList Anime (GraphQL)
A plain HTML/CSS/JS demo (like the other *-js samples; not Vite/Vue — that's
wikipedia-pages-vue) that renders AniList anime in
vanilla-grid via the built-in GraphQLDataManager.
It is the reference showcase for the GraphQL data manager: server-side sort,
free-text search, structured column filters, offset pagination, and a total
row count read inline from the same response (a count strategy OData can't do —
it needs a separate $count call), through a totalPath function because
AniList's total is only real on the last page.
Endpoint
https://graphql.anilist.co— public, no auth, permissive CORS,POST application/json.- Rate limit: 30 requests/minute — what the live endpoint reports in
x-ratelimit-limit(the docs still say 90; the API has been running degraded). Exceeding it returns HTTP429and locks the IP out for a minute. The built-in toolbar search item debounces input (600 ms) and the app surfaces HTTP429as a "rate limited" toolbar status. - Caps: a server-side
perPagecap of 50 (→pageSize: 50). pageInfo.totalis a placeholder until the last page: whilehasNextPageis true the API answerstotal: 5000/lastPage: 100whatever the query matches (Format = TV, Year = 1998 reports 5,000 on page 1 and 59 on page 2, its last). The real count arrives only with the last page, so the manager reads it only there (see Manager configuration).
The query (rows + inline total in one request)
query ($page: Int, $perPage: Int, $search: String, $sort: [MediaSort],
$id_in: [Int], $genre_in: [String], $format_in: [MediaFormat], $status: MediaStatus,
$seasonYear: Int, $startDate_greater: FuzzyDateInt, $startDate_lesser: FuzzyDateInt,
$averageScore: Int, $averageScore_greater: Int, $averageScore_lesser: Int) {
Page(page: $page, perPage: $perPage) {
pageInfo { total currentPage lastPage hasNextPage perPage }
media(type: ANIME, search: $search, sort: $sort, id_in: $id_in, genre_in: $genre_in,
format_in: $format_in, status: $status, seasonYear: $seasonYear,
startDate_greater: $startDate_greater, startDate_lesser: $startDate_lesser,
averageScore: $averageScore, averageScore_greater: $averageScore_greater,
averageScore_lesser: $averageScore_lesser) {
id
title { romaji english }
format status seasonYear startDate { year } episodes duration averageScore popularity genres
siteUrl description(asHtml: false) coverImage { medium large }
}
}
}
The siteUrl / description / coverImage fields are pure app chrome (title-cell
thumbnail + detail panel); the manager neither needs nor knows about them — it
only unwraps Page.media and reads Page.pageInfo through totalPath.
Manager configuration
new window.GraphQLDataManager({
endpoint: 'https://graphql.anilist.co',
query: ANILIST_QUERY,
paginationStyle: 'offset',
pageSize: 50,
infiniteScroll: true,
dataPath: 'Page.media', // where the rows array lives in `data`
// Inline total — NO separate count request. A function, not a path:
// `pageInfo.total` is a placeholder (5000) until the last page.
totalPath: (data) => {
const info = data && data.Page && data.Page.pageInfo;
return info && !info.hasNextPage ? info.total : null;
},
buildVariables, // page/perPage/search/sort + filter args
buildSort, // grid column → [MediaSort] enum
buildFilter, // filter model → AniList flat args
buildSearch: (term) => term || null,
onBeforeFetch, onFetchError, // error status text only — the grid element
// sets its own loading skeleton around every load
});
The three builders live in their own module,
modules/anilist-query.js: pure functions that
touch neither window nor the DOM, so tests/node/anilist-build-filter.test.js
tests them directly. modules/anime-tab.js imports them
and owns the grid, toolbar and detail panel.
The manager always thinks in grid-native skip/top; buildVariables maps that
to AniList's page-based API (page = Math.floor(skip / top) + 1, perPage = top)
via the convenience fields on the builder state object.
Pagination
Offset/page-based with an inline total. <vn-grid> auto-wires infinite scroll to
dm.fetchMoreRows(skip, pageSize); the manager derives page/perPage from
skip/top. While more pages remain the total is pushed as unknown (null), so
the status line reads "Loaded 50 rows (scroll to load more)" and a select-all
reads "50+ selected"; the last page pushes the real Page.pageInfo.total, and
both become exact ("Loaded 59 of 59 rows"). The status line is the toolbar's
autonomous <vn-grid-toolbar-status>, which derives all of this from grid state;
the app only gives it its wording and number formatter
(configureToolbarRowCountStatus() in modules/i18n.js).
Sort (server-side [MediaSort])
buildSort maps the grid column + direction to an AniList sort enum:
| Column | Enum (asc / desc) |
|---|---|
title |
TITLE_ROMAJI / TITLE_ROMAJI_DESC |
seasonYear |
START_DATE / START_DATE_DESC |
episodes |
EPISODES / EPISODES_DESC |
averageScore |
SCORE / SCORE_DESC |
popularity |
POPULARITY / POPULARITY_DESC |
Columns AniList can't sort server-side (format, status, duration, genres)
are declared sortable="false" in the markup.
Filters (structured column filters → AniList flat args)
buildFilter maps the grid's column-filter model to AniList's flat arguments.
AniList's genre/format/status fields are exact-match enums/tokens (there
is no substring filter server-side), so each filterable column declares a
filter-operators allow-list in the markup (with default-filter-operator
preselecting in on the token columns) — the filter panel then only ever offers
operators AniList can honor, and buildFilter receives nothing it can't map:
| Column | filter-operators |
AniList arg |
|---|---|---|
id |
equals / in |
id_in |
genres |
in (default) / equals |
genre_in |
format |
in (default) / equals |
format_in |
status |
equals |
status |
seasonYear |
equals |
seasonYear |
seasonYear |
greaterThan / greaterThanOrEqual / lessThan / lessThanOrEqual / between |
startDate_greater / startDate_lesser |
averageScore |
equals |
averageScore |
averageScore |
greaterThan / greaterThanOrEqual / lessThan |
averageScore_greater / averageScore_lesser |
AniList has no seasonYear_greater/_lesser, so year ranges map to
startDate_greater/_lesser, which take a FuzzyDateInt (YYYYMMDD with unknown
month/day → 0, e.g. 2005 → 20050000); buildFilter converts each year to
this boundary. startDate is the air date — equal to seasonYear for nearly all
titles but able to differ at a year boundary — so exact-year matches still use the
precise seasonYear arg. A title with an all-null (unknown) startDate passes
startDate_lesser but fails startDate_greater, so "less than" queries also pin a
minimal lower floor (startDate_greater: 1) to keep date-less titles out.
Year display fallback. Because the year filter and sort act on startDate,
but the Year column shows seasonYear, the two would disagree for upcoming
titles — AniList frequently gives a NOT_YET_RELEASED entry a known
startDate.year but a null seasonYear, so it passes a "year > N" filter yet
renders a blank year. To keep what you see aligned with what you filtered, the app
selects startDate { year } and the Year column's displayYear() shows
seasonYear ?? startDate.year (via renderCell — a valueGetter can't be used,
as the grid compiles value accessors at setColumns() time). The same fallback
feeds the detail panel and the Excel export.
Unknown-date titles sort first in both directions. Some titles
(cancelled or announced-but-undated projects) have a null seasonYear and an
all-null startDate — there is no year to show, and the Year column renders a
- placeholder for them. The AniList API emits these unknown-date titles at
the top of the results under both START_DATE and START_DATE_DESC (SQL
NULL ordering on their backend — nulls don't participate in the comparison;
only the tie-break flips, so ascending leads with old cancelled titles and
descending with freshly announced ones). A Year sort therefore legitimately
starts with a block of - rows in either direction; this is upstream API
behavior, not a display bug.
So the panel's zero-config default (e.g. Format is any of TV) filters to
format_in: ["TV"]. Operators AniList genuinely can't express (startsWith,
notContains, isEmpty, …) are never offered thanks to the allow-lists;
buildFilter keeps a console.warn fallthrough as a safety net for filters on
columns with no mapping at all.
Two conditions on one column. The filter panel allows a second condition,
joined by and or or. AniList's arguments are all AND-ed, so:
and— the two conditions are intersected, never overwritten: lower bounds keep the larger value, upper bounds the smaller, lists the common values. "Year ≥ 2000 and < 2010" becomesstartDate_greater: 20000000, startDate_lesser: 20100000(2000-2009). A pair that can match nothing (two differentequalsvalues, disjoint lists) sends an emptystartDatewindow, so the result is empty rather than wider.or— AniList's flat argument list cannot express it, so that column's filter is dropped with aconsole.warn(the other columns still apply), rather than being sent as anand.
Sorting and filtering are both server-side reloads driven by the same
auto-reload path: a header-sort runs handleSort() (updating sort:) and a
column filter runs setColumnFilters(), and each fires onConfigChanged. The
grid (setAutoReloadOnConfigChange(true)) coalesces those into a single re-issue
of the query from page 1 with the new args — no per-sort reload callback. The
manager's onSortChanged is a notification hook only.
Search
buildSearch is a passthrough (term || null); the term becomes AniList's
search: argument. Search is the built-in <vn-grid-toolbar-search delay="600">
toolbar item — it wires its own debounced input straight to <vn-grid>.search()
(→ setSearchTerm → AniList search:), so no host code is involved. The 600 ms
debounce keeps AniList's 30 req/min rate limit comfortable.
The search presentation follows the active theme (mirrors northwind-orders-js):
modules/theme.js#switchTheme() toggles the search item's expandable attribute
— the Carbon-style collapsing lens is used only for the IBM Carbon light/dark
themes; every other theme renders the standard inline search box.
AniList search is whole-word, not substring/prefix. Its search: engine
matches complete title tokens (with some fuzzy tolerance for typos within a
word); it does not match arbitrary prefixes shorter than a full word. So
Hokuto finds Hokuto no Ken but Hoku/Hokut return zero results, and
Ken matches because it's a whole word in the title. This is server-side AniList
behavior, not a grid limitation — there's no host-side substring fallback because
the dataset is server-paginated (infinite scroll), so the unloaded rows aren't
available to match against locally.
The grid carries highlight-search-matches, and the Title renderer writes the
name with <vn-grid>.setSearchHighlightedText(), so the active term is marked
(<mark class="vn-grid-search-match">) in the displayed title when it appears
there verbatim (a fuzzy or English-title match leaves the romaji name
unmarked). AniList searches titles only, so the plain numeric columns (ID,
Episodes, Duration, Score, Popularity) set highlightSearchMatches: false and
a search like 86 marks no score or ID.
Row shaping
title— a value getter flattenstitle { romaji english }to a scalar (romaji, falling back toenglish); a custom cell renderer adds the cover thumbnail.genres— a cell renderer joins the array with·for display (the Excel export resolves it the same way). The genre filter's value list is user-entered, so the joined display text never leaks into the server-sidegenre_inargument.- The plain-text cell renderers (Genres, Format, Status, Year) add the grid's
vn-grid-truncate-ellipsisclass, so a narrow column shows an ellipsis instead of wrapping (a wrapped cell would grow every row; the grid adds the class only to cells it renders itself). averageScoreis 0–100 (not 0–10) — noted in the column's secondary label.episodes,seasonYear,durationare frequentlynullfor ongoing/unreleased titles; the grid's empty-cell rendering handles it. For the Year column,seasonYearfalls back tostartDate.year(see Filters above) so upcoming titles that pass the startDate-based year filter still show a year.
UI parity with wikipedia-pages-js
- Theme selector — 14 of the 15 built-in grid themes (all but Ledger), app-shell chrome
theme-parameterized via the shared
../_common/themes/app-*.css(seesamples/_common/README.md). - EN/IT i18n — column headers, status labels, the column filter panel
(the app passes its own
getGridFilterMessages()table: operators, Apply/Clear, a11y labels) and the detail panel switch language. The AniListMediaStatusandMediaFormatenums (RELEASING,TV_SHORT, …) are shown with localized labels (localizeStatus()/localizeFormat()) in the grid cells, the Excel export and the detail panel. Filter values stay the enum tokens AniList matches on (Format is any ofMOVIE, notFilm). - Detail panel — row double-click (or the toolbar
Viewcommand on a single selection) opens a side panel with the cover, description, metadata, and the AniList page link (linked only when it is anhttp:/https:URL). - Toolbar — built-in debounced search, auto-fit, clear filters & sorting, reset, reload, theme-styled Excel export.
- No select-all drain — the app subclasses
GraphQLDataManagerwithsupportsFullFetch()returningfalse, asgithub-repos-jsdoes. Fetching every page for a select-all export would run into AniList's 30 requests a minute (a429), so exporting a select-all while rows are still unloaded is refused with the grid'sexportUnsupporteddialog, before any request. A manual selection, or a select-all once every row is loaded (e.g. the 59 TV titles of 1998 after scrolling to the end), exports directly. - Status line — the toolbar's
<vn-grid-toolbar-status>appends the selection count, so a select-all counts the rows not loaded yet (… · 200+ selectedwhile the count is a lower bound). Fetch errors and the429rate-limit message go to the<vn-grid-toolbar-status-message>next to it, reported once by the manager'sonFetchErrorhook (loadAnime()only logs).GraphQLDataManagercarries the HTTP status only in the error message (HTTP error! status: 429), so that is what the app matches.
How the components are loaded
index.html loads the components as plain custom-element scripts (same tail as
wikipedia-pages-js):
<script src="../../src/vanilla-resize-box/vanilla-resize-box.js"></script>
<script src="../../src/vanilla-grid/vanilla-grid.js"></script>
<script src="../../src/vanilla-grid-toolbar/vanilla-grid-toolbar.js"></script>
<script type="module" src="app.js"></script>
vanilla-grid.js auto-loads its feature scripts (including
window.GraphQLDataManager) asynchronously; app.js awaits
window.VanillaGridReady before constructing the manager and grid.
Resizing the grid
The toolbar and the grid sit together in a src/vanilla-resize-box/ (aria-label="Resizable AniList anime grid and toolbar"). The box takes a single content child, so the two are stacked in a .resize-content wrapper, and it has a minimum size of 920 x 300 px (min-width="920", min-height="300"). Drag the corner handle to resize them together — resizing is pointer-driven, with no keyboard path. Double-click the handle to fill the available space, and again to restore the previous size.
The grid uses stretch-to-fit, so narrowing the box narrows its non-frozen columns. Each of them declares min-width="80", which stops the squeeze there: at the narrowest box sizes the grid scrolls horizontally instead of cutting the headers down to a letter or two.
The handle carries role="separator" and takes its accessible name from the host's aria-label — here "Resizable AniList anime grid and toolbar — resize handle" — but is not focusable, so it adds no tab stop to the page. This app's markup needs nothing beyond the aria-label it already carries.
AniList-specific caveats
- No
edges/cursor — AniList is page-based, so this app usespaginationStyle: 'offset', not cursor. (The cursor path is still shipped inGraphQLDataManagerand covered by the mocked Playwright spec.) - Inline total — demonstrates the "total in the same response" strategy
(
totalPath), which OData can't do, in its function form: the schema's total is only trustworthy on the last page, so the function returnsnullbefore it. - Errors envelope — a GraphQL error is an HTTP 200 with a populated
errorsarray; the manager throwsGraphQLDataManager.GraphQLErrorby default.