Socket
Book a DemoInstallSign in
Socket

@apollo-elements/lit-apollo

Package Overview
Dependencies
Maintainers
1
Versions
66
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@apollo-elements/lit-apollo

πŸ‘©β€πŸš€πŸŒ› Lit meets Apollo GraphQL πŸš€πŸ‘¨β€πŸš€

latest
Source
npmnpm
Version
6.0.0
Version published
Weekly downloads
0
Maintainers
1
Weekly downloads
Β 
Created
Source

@apollo-elements/lit-apollo

Published on npm Published on webcomponents.org ISC License Release

πŸš€ Lit base classes that connect to your Apollo cache 🌜

πŸ‘©β€πŸš€ It's one small step for a dev, one giant leap for the web platform! πŸ‘¨β€πŸš€

This package is for single-operation GraphQL components. Looking for Apollo Reactive Controllers? See @apollo-elements/core

View Live Demo

πŸ”Ž Read the Full API Docs πŸ”Ž

πŸ““ Contents

πŸ”§ Installation

Apollo Elements' lit-apollo 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/lit-apollo

πŸ‘©β€πŸš€ Usage

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

First, let's define our component's 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 base class and helpers, query, and types:

Imports
import { ApolloQuery, html, customElement } from '@apollo-elements/lit-apollo';

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

import type {
  HelloQueryData as Data,
  HelloQueryVariables as Variables
} from '../codegen/schema';

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

@customElement('hello-query')
export class HelloQueryElement extends ApolloQuery<Data, Variables> {
  query = HelloQuery;

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

πŸ“š 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

Keywords

Apollo

FAQs

Package last updated on 04 Oct 2025

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts