@apollo-elements/core

中文文档
3.0.1发布于 2026/07/21ISCTypeScriptES Module近 30 天下载 2.7万

👩‍🚀🌛 Core Classes for Apollo Elements 🚀👨‍🚀

原始使用文档
文档目录7 节
  1. 📓 Contents
  2. 🔧 Installation
  3. 👩‍🚀 Usage
  4. ❓ FAQs
  5. Is this package only for Lit users?
  6. 📚 Other Libraries
  7. 👷‍♂️ Maintainers

@apollo-elements/core

Published on npm Published on webcomponents.org ISC License Release

🚀 Reactive GraphQL Controllers 🌜

👩‍🚀 Lander to Mission Controll, Come in, Over 👨‍🚀

🔎 Read the Full API Docs 🔎

📓 Contents

🔧 Installation

Apollo Elements is distributed through npm, the node package manager. To install a copy of the latest version in your project's node_modules directory, install npm on your system then run the following command in your project's root directory:

npm install --save @apollo-elements/core

👩‍🚀 Usage

See our docs on setting up Apollo client so your components can fetch their data.

First, let's define our GraphQL query.

query HelloQuery {
  helloWorld {
    name
    greeting
  }
}

Read our docs on working with GraphQL files during development and in production for more info, and be sure to read about generating TypeScript types from GraphQL to enhance your developer experience and reduce bugs.

Next, we'll define our UI component. Import the controller, query, and types:

Imports
import { ApolloQueryController } from '@apollo-elements/core';
import { LitElement, html } from 'lit';
import { customElement } from 'lit/decorators.js';

import { HelloQuery } from './Hello.query.graphql';

Then define your component's template. Make sure to set the query field, so your component starts fetching data automatically.

@customElement('hello-world')
export class HelloWorldElement extends LitElement {
  query = new ApolloQueryController(this, HelloQuery);

  render() {
    return html`
      <what-spin-such-loader ?active="${this.query.loading}"></what-spin-such-loader>
    ${(
      this.query.error ? html`
        <h1>😢 Such Sad, Much Error! 😰</h1>
        <pre><code>${error.message}</code></pre>`
    : html`
        <p>
          ${this.query.data?.helloWorld.greeting ?? 'Hello'},
          ${this.query.data?.helloWorld.name ?? 'Friend'}!
        </p>`
    )}
    `;
   }
}

❓ FAQs

Is this package only for Lit users?

No! You can use these controllers on any object that implements the ReactiveControllerHost interface, even vanilla HTMLElement by way of the ControllerHostMixin

import { ControllerHostMixin } from '@apollo-elements/mixins/controller-host-mixin';
import { ApolloQueryController } from '@apollo-elements/core/apollo-query-controller';

customElements.define('hello-world', class HelloWorldElement extends ControllerHostMixin(HTMLElement) {
  query = new ApolloQueryController(this, HelloQuery);

  update() {
    const greeting = this.query.data?.helloWorld.greeting ?? 'Hello';
    const name = this.query.data?.helloWorld.name ?? 'Friend';
    // Just for demo purposes, Don't actually use innerHTML!
    this.innerHTML = `<p>${greeting}, ${name}!</p>`;
    super.update();
  }
});

📚 Other Libraries

Looking for other libraries? Want to use Apollo with vanilla extends HTMLElement components? Check out our docs site

👷‍♂️ Maintainers

apollo-elements is a community project maintained by Benny Powers.

Contact me on Codementor

版本与发布记录

@apollo-elements/core 共发布 19 个版本,首次发布于 2021/06/17;过去 12 个月发布了 1 个版本。

版本发布日期距今
3.0.1latest2026/07/213 个月前
3.0.02025/10/051.1 年前
2.1.22022/03/304 年前
2.1.12022/03/284 年前
2.1.02022/03/034 年前
2.0.12022/03/014 年前

其他发布通道:next → 1.1.1-next.0。

关于 @apollo-elements/core 的常见问题

@apollo-elements/core 是什么?

👩 🚀🌛 Core Classes for Apollo Elements 🚀👨 🚀

如何安装 @apollo-elements/core?

在项目目录运行 npm install @apollo-elements/core,或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖:@apollo/client(^4.0.0)、graphql(^15.4.0 || ^16)。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖,Yarn 需要手动安装。

@apollo-elements/core 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@apollo-elements/core 支持 ESM 还是 CommonJS?

以 ES Module 形式发布,推荐使用 import 引入。在 CommonJS 项目中,Node.js 20.19+ / 22.12+ 可以直接 require() 不含顶层 await 的 ES Module,更早的版本需要改用动态 import()。

@apollo-elements/core 可以商用吗?

@apollo-elements/core 使用 ISC 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@apollo-elements/core 的下载量有多少?

根据 npm 官方下载统计,@apollo-elements/core 在 2026/10/07 – 2026/11/05 这 30 天内被下载 26,814 次,日均约 894 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@apollo-elements/core 还在维护吗?

最新版本 3.0.1 发布于 2026/07/21(3 个月前);至今共发布 19 个版本,其中过去 12 个月发布了 1 个;首次发布于 2021/06/17。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。