Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@apollo-elements/core

Package Overview
Dependencies
Maintainers
1
Versions
17
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@apollo-elements/core

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

  • 0.1.0-next.7
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

@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

Keywords

FAQs

Package last updated on 30 Jul 2021

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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc